diff --git a/README.md b/README.md index cad93e4..b461d53 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ ### 🎉 What's this? 这是一款`在线工具箱`程序,您可以通过安装扩展增强她的功能 +通过插件模板的功能,您也可以把她当做网页导航来使用~ 觉得该项目不错的可以给个`Star`~ ### 😺 演示地址 @@ -17,7 +18,9 @@ > 严禁用于非法用途 ### 😺 文档 -[插件编写](docs/Plugin.md) +[插件编写](docs/Plugin.md) +[Github Oauth 配置](docs/Github_Oauth.md) +[Plugin Template 使用](docs/Plugin_Template.md) ### 🎊 环境要求 diff --git a/app/controller/master/Plugin.php b/app/controller/master/Plugin.php index b8ab789..634a2db 100644 --- a/app/controller/master/Plugin.php +++ b/app/controller/master/Plugin.php @@ -80,6 +80,7 @@ class Plugin extends BaseController 'title', 'enable', 'weight', + 'template', ])->data($params)->save(); return msg('ok', 'success', $plugin); } @@ -117,6 +118,7 @@ class Plugin extends BaseController 'title', 'enable', 'weight', + 'template', ])->data($params)->save(); return msg('ok', 'success', $plugin); } diff --git a/app/controller/master/System.php b/app/controller/master/System.php index 08994fa..4bea505 100644 --- a/app/controller/master/System.php +++ b/app/controller/master/System.php @@ -72,8 +72,18 @@ class System extends BaseController array_push($arr, basename($v)); } } + return msg('ok', 'success', $arr); - + } + public function plugin_templates() + { + $glob = glob(template_path_get() . '/template/*'); + $arr = []; + foreach ($glob as $v) { + if (is_file($v)) { + array_push($arr, basename($v,'.html')); + } + } return msg('ok', 'success', $arr); } diff --git a/app/lib/Plugin.php b/app/lib/Plugin.php index ec71fdb..e31a236 100644 --- a/app/lib/Plugin.php +++ b/app/lib/Plugin.php @@ -119,6 +119,7 @@ class Plugin $model->config = []; $model->category_id = 0; $model->request_count = 0; + $model->template = 'default'; } if (is_file($this->pluginPath . '/logo.png')) { $logoFilename = plugin_logo_path_get($this->pluginClass); diff --git a/app/model/Category.php b/app/model/Category.php index 98288cd..8ed7697 100644 --- a/app/model/Category.php +++ b/app/model/Category.php @@ -6,6 +6,7 @@ namespace app\model; /** * @property int $id + * @property int $weight 权重 * @property string $create_time 安装时间 * @property string $title 标题 * @property string $update_time 更新时间 diff --git a/app/model/Plugin.php b/app/model/Plugin.php index d52347a..d04cabd 100644 --- a/app/model/Plugin.php +++ b/app/model/Plugin.php @@ -10,14 +10,17 @@ use think\Model; * Class app\model\Plugin * * @property int $category_id 分类 + * @property int $enable 是否启用 * @property int $id * @property int $request_count 接口请求次数 + * @property int $weight 权重 * @property string $alias 插件名 * @property string $class 插件类 * @property string $config 配置信息 * @property string $create_time 安装时间 * @property string $desc 插件描述 * @property string $logo 插件logo + * @property string $template * @property string $title 插件标题 * @property string $update_time 更新时间 * @property string $version 版本 diff --git a/app/model/Request.php b/app/model/Request.php index 6caa0d7..2779b9b 100644 --- a/app/model/Request.php +++ b/app/model/Request.php @@ -12,6 +12,7 @@ namespace app\model; * @property int $request_count 接口请求次数 * @property string $create_time 安装时间 * @property string $update_time 更新时间 + * @property-read \app\model\Plugin $plugin */ class Request extends Base { diff --git a/config/version.php b/config/version.php index 5be8940..a3af413 100644 --- a/config/version.php +++ b/config/version.php @@ -3,4 +3,4 @@ // | 版本号 // +---------------------------------------------------------------------- -define('VERSION', 'v1.2'); \ No newline at end of file +define('VERSION', 'v1.3'); \ No newline at end of file diff --git a/docs/Github_Oauth.md b/docs/Github_Oauth.md new file mode 100644 index 0000000..31f8efe --- /dev/null +++ b/docs/Github_Oauth.md @@ -0,0 +1,12 @@ +## Github Oauth 配置 +* 打开Github,并且登录你的github账号 +* 打开:https://github.com/settings/developers + +### 创建一个Oauth APP + +![](images/github_oauth_1.png) +#### 填写APP信息 +![](images/github_oauth_2.png) +#### 获取`Client ID`和`Client secrets` +![](images/github_oauth_3.png) +#### 最后在安装界面填入刚刚得到的的`Client ID`和`Client secrets`即可完成`Oauth`配置 \ No newline at end of file diff --git a/docs/Plugin_Template.md b/docs/Plugin_Template.md new file mode 100644 index 0000000..2540723 --- /dev/null +++ b/docs/Plugin_Template.md @@ -0,0 +1,20 @@ +## Plugin Template 使用 +### 添加插件 +![](images/plugin_template_1.png) + +### 插件配置信息填入下方`JSON`数据 +```json +{ + "url":"https://www.aoaostar.com" +} +``` +### 成功演示 +![](images/plugin_template_2.png) +#### `redirect`亦是如此 + +## 添加新模板 +### 在`view/index/default/template`添加`pluto.html` +![](images/plugin_template_3.png) + +### 添加成功之后,即可在后台看到新增的模板 +![](images/plugin_template_4.png) diff --git a/docs/images/github_oauth_1.png b/docs/images/github_oauth_1.png new file mode 100644 index 0000000..92bce8d Binary files /dev/null and b/docs/images/github_oauth_1.png differ diff --git a/docs/images/github_oauth_2.png b/docs/images/github_oauth_2.png new file mode 100644 index 0000000..6403a16 Binary files /dev/null and b/docs/images/github_oauth_2.png differ diff --git a/docs/images/github_oauth_3.png b/docs/images/github_oauth_3.png new file mode 100644 index 0000000..ed90626 Binary files /dev/null and b/docs/images/github_oauth_3.png differ diff --git a/docs/images/plugin_template_1.png b/docs/images/plugin_template_1.png new file mode 100644 index 0000000..0e9244b Binary files /dev/null and b/docs/images/plugin_template_1.png differ diff --git a/docs/images/plugin_template_2.png b/docs/images/plugin_template_2.png new file mode 100644 index 0000000..3b1084f Binary files /dev/null and b/docs/images/plugin_template_2.png differ diff --git a/docs/images/plugin_template_3.png b/docs/images/plugin_template_3.png new file mode 100644 index 0000000..5f369d4 Binary files /dev/null and b/docs/images/plugin_template_3.png differ diff --git a/docs/images/plugin_template_4.png b/docs/images/plugin_template_4.png new file mode 100644 index 0000000..0f2efb6 Binary files /dev/null and b/docs/images/plugin_template_4.png differ diff --git a/docs/images/view_1.png b/docs/images/view_1.png index ea8331b..29663a3 100644 Binary files a/docs/images/view_1.png and b/docs/images/view_1.png differ diff --git a/install.sql b/install.sql index 2cd0a23..6f7f5c1 100644 --- a/install.sql +++ b/install.sql @@ -80,6 +80,7 @@ CREATE TABLE `toolbox_plugin` ( `enable` int(11) NOT NULL DEFAULT 1 COMMENT '是否启用', `request_count` int(11) NOT NULL DEFAULT 0 COMMENT '接口请求次数', `category_id` int(11) NOT NULL DEFAULT 0 COMMENT '分类', + `template` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'default', `create_time` datetime NOT NULL COMMENT '安装时间', `update_time` datetime NOT NULL COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE, @@ -90,7 +91,7 @@ CREATE TABLE `toolbox_plugin` ( -- ---------------------------- -- Records of toolbox_plugin -- ---------------------------- -INSERT INTO `toolbox_plugin` VALUES (1, 'Hello,Pluto', '/static/icons/aoaostar_com_example.png', 'If you see this message, it means that your program is running properly', 'example', 'aoaostar_com\\example', '{}', 'v1.0', 0, 1, 0, 1, '2021-12-22 18:38:35', '2021-12-25 13:50:14'); +INSERT INTO `toolbox_plugin` VALUES (1, 'Hello,Pluto', '/static/icons/aoaostar_com_example.png', 'If you see this message, it means that your program is running properly', 'example', 'aoaostar_com\\example', '{}', 'v1.0', 0, 1, 0, 1, 'default', '2021-12-22 18:38:35', '2021-12-25 13:50:14'); -- ---------------------------- -- Table structure for toolbox_request diff --git a/public/admin/index.html b/public/admin/index.html index 25c99ab..29c7a0c 100644 --- a/public/admin/index.html +++ b/public/admin/index.html @@ -2,7 +2,7 @@ - 傲星工具箱 - 后台管理中心 + 后台管理中心 - 傲星工具箱 diff --git a/public/admin/js/api.js b/public/admin/js/api.js index 064eb85..ce3805a 100644 --- a/public/admin/js/api.js +++ b/public/admin/js/api.js @@ -149,6 +149,11 @@ const system_get = () => { const templates_get = () => { return httpGet('/master/system/templates') } + +const plugin_templates_get = () => { + return httpGet('/master/system/plugin_templates') +} + const ota_check = () => { return httpGet('/master/ota/check') } diff --git a/public/admin/page/ota.html b/public/admin/page/ota.html index 8275017..dd95197 100644 --- a/public/admin/page/ota.html +++ b/public/admin/page/ota.html @@ -21,6 +21,11 @@ padding: .5rem; } + .ota-console { + max-width: 600px; + max-height: 400px; + } + @@ -112,7 +117,8 @@ layer.open({ type: 1, title: '在线更新', - area: ['600px', '400px'], + area: ['85vw', '400px'], + skin: 'ota-console', shade: 0.8, id: 'ota_update', content: `
`, diff --git a/public/admin/page/plugin.html b/public/admin/page/plugin.html index a4334cf..04149b9 100644 --- a/public/admin/page/plugin.html +++ b/public/admin/page/plugin.html @@ -2,7 +2,7 @@ - layui + 插件管理 @@ -118,6 +118,7 @@ return '默认分组' } }, + {field: 'template', width: 100, title: '模板', sort: true, align: 'center'}, { field: 'config', width: 150, title: '配置信息', align: 'center', templet: function (res) { return JSON.stringify(res.config, null, 4) diff --git a/public/admin/page/plugin/add.html b/public/admin/page/plugin/add.html index 37d30dd..5a22720 100644 --- a/public/admin/page/plugin/add.html +++ b/public/admin/page/plugin/add.html @@ -2,7 +2,7 @@ - layui + 添加插件 @@ -29,7 +29,7 @@
- 插件Logo,无需多言 @@ -56,7 +56,7 @@
- 插件的版本号,例如:v1.0。 @@ -65,7 +65,7 @@
- 填数字,数字越大排名越前。 @@ -74,7 +74,7 @@
- + 禁用则不会在前台显示。
@@ -101,6 +101,15 @@ 插件描述信息,介绍一下这个插件是干什么的吧!
+
+ +
+ + 默认运行本地插件,可通过设置模板实现iframe或redirect功能 + 模板位于view/index/default/template目录 +
+
@@ -115,6 +124,14 @@ {{# }); }} + @@ -125,15 +142,26 @@ layer = layui.layer, laytpl = layui.laytpl, $ = layui.$; + layer.load(1) - categories_get().then(res => { - const getTpl = document.getElementById('categoies_tpl').innerHTML, + let tasks = [] + tasks.push(categories_get().then(res => { + var getTpl = document.getElementById('categoies_tpl').innerHTML, view = document.getElementById('categories'); laytpl(getTpl).render(res.data.items, function (html) { view.innerHTML = html; form.render(); }); - }).finally(() => { + })) + tasks.push(plugin_templates_get().then(res => { + var getTpl = document.getElementById('templates_tpl').innerHTML, + view = document.getElementById('templates'); + laytpl(getTpl).render(res.data, function (html) { + view.innerHTML = html; + form.render(); + }); + })) + Promise.all(tasks).finally(() => { layer.closeAll('loading') }) //监听提交 diff --git a/public/admin/page/plugin/edit.html b/public/admin/page/plugin/edit.html index 7978014..1a1d96b 100644 --- a/public/admin/page/plugin/edit.html +++ b/public/admin/page/plugin/edit.html @@ -2,7 +2,7 @@ - layui + 编辑插件 @@ -35,7 +35,7 @@
- 插件Logo,无需多言 @@ -71,7 +71,7 @@
- 填数字,数字越大排名越前。 @@ -108,6 +108,15 @@ 插件描述信息,介绍一下这个插件是干什么的吧!
+
+ +
+ + 默认运行本地插件,可通过设置模板实现iframe或redirect功能 + 模板位于view/index/default/template目录 +
+
@@ -122,6 +131,14 @@ {{# }); }} + @@ -142,6 +159,14 @@ form.render(); }); })) + tasks.push(plugin_templates_get().then(res => { + var getTpl = document.getElementById('templates_tpl').innerHTML, + view = document.getElementById('templates'); + laytpl(getTpl).render(res.data, function (html) { + view.innerHTML = html; + form.render(); + }); + })) tasks.push( plugin_get(getQueryString('id')).then(res => { if (res.status === 'ok') { diff --git a/route/admin.php b/route/admin.php index 4f0cf92..f419129 100644 --- a/route/admin.php +++ b/route/admin.php @@ -20,6 +20,7 @@ Route::group('master', function () { Route::delete('/category', 'Category/delete'); Route::get('/system/templates', 'System/templates'); + Route::get('/system/plugin_templates', 'System/plugin_templates'); Route::get('/system/info', 'System/info'); Route::get('/system', 'System/all'); Route::post('/system', 'System/update'); diff --git a/route/plugin.php b/route/plugin.php index ed491a9..857532b 100644 --- a/route/plugin.php +++ b/route/plugin.php @@ -25,9 +25,13 @@ Route::get(':alias', function () { abort(404, '页面异常'); } $template = plugin_template_path_get($path); + $model = plugin_info_get($alias); View::assign([ - "plugin" => plugin_info_get($alias) + "plugin" => $model ]); + if ($model->template !== 'default') { + $template = template_path_get() . 'template/' . $model->template . '.html'; + } return view($template); })->pattern(['alias' => '[\w|\-/]+']) ->middleware(\app\middleware\View::class); \ No newline at end of file diff --git a/runtime/.gitignore b/runtime/.gitignore index c96a04f..7129810 100644 --- a/runtime/.gitignore +++ b/runtime/.gitignore @@ -1,2 +1,4 @@ * -!.gitignore \ No newline at end of file +!.gitignore +!update +!update/** \ No newline at end of file diff --git a/runtime/update/sql/202232115106.sql b/runtime/update/sql/202232115106.sql new file mode 100644 index 0000000..385ac34 --- /dev/null +++ b/runtime/update/sql/202232115106.sql @@ -0,0 +1,5 @@ +SET FOREIGN_KEY_CHECKS=0; + +ALTER TABLE `toolbox_plugin` ADD COLUMN `template` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'default' AFTER `category_id`; + +SET FOREIGN_KEY_CHECKS=1; \ No newline at end of file diff --git a/view/index/default/layout/layout.html b/view/index/default/layout/layout.html index bec1802..25ea30a 100644 --- a/view/index/default/layout/layout.html +++ b/view/index/default/layout/layout.html @@ -15,7 +15,7 @@ - + {block name="head"}{/block} diff --git a/view/index/default/template/iframe.html b/view/index/default/template/iframe.html new file mode 100644 index 0000000..120994a --- /dev/null +++ b/view/index/default/template/iframe.html @@ -0,0 +1,20 @@ + + + + + {$plugin.title} - {$app.title} + + + + + + + + + + + \ No newline at end of file diff --git a/view/index/default/template/redirect.html b/view/index/default/template/redirect.html new file mode 100644 index 0000000..ca53cee --- /dev/null +++ b/view/index/default/template/redirect.html @@ -0,0 +1,34 @@ + + + + + + + 页面加载中,请稍候... + + + + + + + + +
+
+
+
+
+
+
+ + \ No newline at end of file