From bb5b0567e1dd2ad4c1b04250548c41d4bc4775d7 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Fri, 9 Apr 2021 20:12:41 +0800 Subject: [PATCH] 0409 --- class/Api.php | 22 ++++++++++++++ controller/admin.php | 11 +++++++ controller/api.php | 13 ++++++++ data/update.txt | 3 ++ templates/admin/ext_js.php | 27 +++++++++++++++++ templates/admin/imp_link.php | 49 +++++++++++++++++++++++++++++++ templates/admin/left.php | 12 +++++++- templates/admin/static/embed.js | 14 +++++++++ templates/default/index.php | 4 +-- templates/default/static/embed.js | 24 +++++++++++++++ test.php | 2 +- 11 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 data/update.txt create mode 100644 templates/admin/ext_js.php create mode 100644 templates/admin/imp_link.php diff --git a/class/Api.php b/class/Api.php index f6824f3..858c780 100644 --- a/class/Api.php +++ b/class/Api.php @@ -391,6 +391,28 @@ class Api { ]; exit(json_encode($data)); } + /** + * 自定义js + */ + public function add_js($token,$content){ + $this->auth($token); + //如果内容为空 + // if( $content == '' ){ + // $this->err_msg(-1013,'The content cannot be empty!'); + // } + //写入文件 + try{ + file_put_contents("data/extend.js",$content); + $data = [ + 'code' => 0, + 'data' => 'success' + ]; + exit(json_encode($data)); + } + catch(Exception $e){ + $this->err_msg(-2000,$e->getMessage()); + } + } /** * 获取IP */ diff --git a/controller/admin.php b/controller/admin.php index 30fd3ba..424e0e5 100644 --- a/controller/admin.php +++ b/controller/admin.php @@ -68,6 +68,17 @@ if ($page == 'logout') { exit; } +//如果是自定义js页面 +if ($page == 'ext_js') { + //判断文件是否存在 + if (is_file('data/extend.js')) { + $content = file_get_contents('data/extend.js'); + } + else{ + $content = ''; + } +} + $page = $page.'.php'; //获取访客IP diff --git a/controller/api.php b/controller/api.php index 96582eb..fdf02de 100644 --- a/controller/api.php +++ b/controller/api.php @@ -43,6 +43,9 @@ switch ($method) { case 'get_link_info': get_link_info($api); break; + case 'add_js': + add_js($api); + break; default: # code... break; @@ -174,4 +177,14 @@ function get_link_info($api) { //获取URL $url = @$_POST['url']; $api->get_link_info($token,$url); +} + +/** + * 添加自定义js + */ +function add_js($api) { + //获取token + $token = $_POST['token']; + $content = @$_POST['content']; + $api->add_js($token,$content); } \ No newline at end of file diff --git a/data/update.txt b/data/update.txt new file mode 100644 index 0000000..d24a6cc --- /dev/null +++ b/data/update.txt @@ -0,0 +1,3 @@ +20200409 +1. 新增快捷键支持 +2. 后台增加自定义js功能 \ No newline at end of file diff --git a/templates/admin/ext_js.php b/templates/admin/ext_js.php new file mode 100644 index 0000000..256c854 --- /dev/null +++ b/templates/admin/ext_js.php @@ -0,0 +1,27 @@ + + + +
+ +
+
+
+

自定义JavaScript,仅对默认主题有效:

+
+ + +
+
+
+ + +
+
+
+
+ +
+ +
+ + \ No newline at end of file diff --git a/templates/admin/imp_link.php b/templates/admin/imp_link.php new file mode 100644 index 0000000..18b837c --- /dev/null +++ b/templates/admin/imp_link.php @@ -0,0 +1,49 @@ + + + +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ + +
+
+
+
+ +
+ +
+ + \ No newline at end of file diff --git a/templates/admin/left.php b/templates/admin/left.php index 5f17d95..5705cd0 100644 --- a/templates/admin/left.php +++ b/templates/admin/left.php @@ -17,9 +17,19 @@
我的链接
添加链接
+
书签导入
+
+ + + + + \ No newline at end of file diff --git a/templates/admin/static/embed.js b/templates/admin/static/embed.js index c7b4efc..d1ecf3a 100644 --- a/templates/admin/static/embed.js +++ b/templates/admin/static/embed.js @@ -205,6 +205,20 @@ layui.use(['element','table','layer','form'], function(){ console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value} return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 }); + //添加自定义js + form.on('submit(add_js)', function(data){ + $.post('/index.php?c=api&method=add_js',data.field,function(data,status){ + //如果添加成功 + if(data.code == 0) { + layer.msg('已添加!', {icon: 1}); + } + else{ + layer.msg(data.err_msg, {icon: 5}); + } + }); + //console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value} + return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 + }); //修改分类目录 form.on('submit(edit_category)', function(data){ $.post('/index.php?c=api&method=edit_category',data.field,function(data,status){ diff --git a/templates/default/index.php b/templates/default/index.php index e93cfe3..a578edc 100644 --- a/templates/default/index.php +++ b/templates/default/index.php @@ -13,8 +13,7 @@ - - + @@ -193,4 +192,5 @@ + diff --git a/templates/default/static/embed.js b/templates/default/static/embed.js index c1b1f7c..109dc37 100644 --- a/templates/default/static/embed.js +++ b/templates/default/static/embed.js @@ -211,6 +211,10 @@ $.contextMenu({ // 添加链接按钮 $("#add").click(function(){ + open_add_link(); +}); + +function open_add_link(){ layer.open({ type: 2, title: '添加链接', @@ -219,4 +223,24 @@ $("#add").click(function(){ area : ['800px' , '520px'], content: '/index.php?c=admin&page=add_link_tpl' }); +} +//搜索框失去焦点 +function clean_search(){ + $(".search").val(''); + $(".search").blur(); +} +//搜索框得到焦点 +function on_search(){ + $(".search").focus(); + $(".search").val(''); +} +hotkeys('a,esc', function (event, handler){ + switch (handler.key) { + case 'a': open_add_link(); + break; + case 'esc': clean_search(); + break; + + default: alert(event); + } }); \ No newline at end of file diff --git a/test.php b/test.php index 5ac5163..e0a6929 100644 --- a/test.php +++ b/test.php @@ -1,5 +1,5 @@ /i";