diff --git a/app/admin/controller/decoration/MenuDecorate.php b/app/admin/controller/decoration/MenuDecorate.php index 7eec93c3..63cf4f36 100644 --- a/app/admin/controller/decoration/MenuDecorate.php +++ b/app/admin/controller/decoration/MenuDecorate.php @@ -242,4 +242,73 @@ class MenuDecorate extends AdminBase{ 'shop_street_hide' => ConfigServer::get('decoration', 'shop_street_hide', 0) ]); } + + // 工具条列表 + public function toolsList() + { + if($this->request->isAjax()){ + $get = $this->request->get(); + $list = MenuDecorateLogic::toolLists($get); + return JsonServer::success('',$list); + } + } + + // 新增工具 + public function addTools(){ + if($this->request->isAjax()){ + $post = $this->request->post(); + $post['del'] = 0; + $post['decorate_type'] = $post['type']; + (new MenuDecorateValidate())->goCheck('Add',$post); + $result = MenuDecorateLogic::add_tools($post); + if($result){ + return JsonServer::success('添加成功'); + } + return JsonServer::error('添加失败'); + } + $type = $this->request->get('type'); + $menu_type = MenuEnum::INDEX; + if(2 == $type){ + $menu_type = MenuEnum::CENTRE; + } + return view('',['menu_list'=>$menu_type]); + } + + // 编辑工具 + public function editTools(){ + if($this->request->isAjax()){ + $post = $this->request->post(); + $post['del'] = 0; + (new MenuDecorateValidate())->goCheck('edit', $post); + $result = MenuDecorateLogic::edit_tools($post); + if($result){ + return JsonServer::success('修改成功'); + } + return JsonServer::error('修改失败'); + } + $id = $this->request->get('id'); + $detail = MenuDecorateLogic::getTools($id); + $type = $this->request->get('type'); + $menu_type = MenuEnum::INDEX; + if(2 == $type){ + $menu_type = MenuEnum::CENTRE; + } + return view('',['menu_list' => $menu_type, 'detail' => $detail]); + } + + // 切换工具状态 + public function swtichToolsStatus(){ + (new MenuDecorateValidate())->goCheck('swtich'); + $post = $this->request->post(); + MenuDecorateLogic::swtichToolsStatus($post); + return JsonServer::success('操作成功'); + } + + // 删除工具 + public function delTools(){ + $id = $this->request->post('id'); + (new MenuDecorateValidate())->goCheck('del'); + MenuDecorateLogic::delTools($id); + return JsonServer::success('删除成功'); + } } \ No newline at end of file diff --git a/app/admin/logic/decoration/MenuDecorateLogic.php b/app/admin/logic/decoration/MenuDecorateLogic.php index a66e8dc4..e24ab371 100644 --- a/app/admin/logic/decoration/MenuDecorateLogic.php +++ b/app/admin/logic/decoration/MenuDecorateLogic.php @@ -324,4 +324,73 @@ class MenuDecorateLogic extends Logic { return true; } + public static function toolLists($get){ + + $where[] = ['del','=',0]; + + $lists = Db::name('menu_tools') + ->where($where) + ->paginate(['list_rows'=>$get['limit'],'page'=>$get['page']]); + + $list = $lists->items(); + $count = $lists->total(); + foreach ($list as $key => $menu){ + $list[$key]['image'] = empty($list[$key]['image']) ? '' : UrlServer::getFileUrl($list[$key]['image']); + } + + return ['count'=>$count,'lists'=>$list]; + } + + // 添加工具 + public static function add_tools($post){ + $data = [ + 'name' => $post['name'], + 'image' => clearDomain($post['image']), + 'url' => $post['url'], + 'sort' => $post['sort'], + 'is_show' => $post['is_show'], + 'create_time' => time(), + ]; + return Db::name('menu_tools')->insert($data); + } + + // 获取工具数据 + public static function getTools($id) + { + $info = Db::name('menu_tools') + ->where(['del'=>0,'id'=>$id]) + ->find(); + $info['image'] = empty($info['image']) ? '' : UrlServer::getFileUrl($info['image']); + + return $info; + } + + // 编辑工具 + public static function edit_tools($post) + { + $data = [ + 'name' => $post['name'], + 'image' => clearDomain($post['image']), + 'url' => $post['url'], + 'sort' => $post['sort'], + 'is_show' => $post['is_show'], + 'create_time' => time(), + ]; + + return Db::name('menu_tools')->where(['id'=>$post['id']])->update($data); + } + + // 切换工具状态 + public static function swtichToolsStatus($post){ + return Db::name('menu_tools') + ->where(['id' => $post['id']]) + ->update(['is_show' => $post['is_show'], 'update_time' => time()]); + } + + public static function delTools($id) + { + return Db::name('menu_tools') + ->where(['id' => $id,'del' => 0]) + ->update(['update_time' =>time() ,'del' => 1]); + } } diff --git a/app/admin/view/decoration/menu_decorate/add_tools.html b/app/admin/view/decoration/menu_decorate/add_tools.html new file mode 100644 index 00000000..edc2d988 --- /dev/null +++ b/app/admin/view/decoration/menu_decorate/add_tools.html @@ -0,0 +1,76 @@ +{layout name="layout2" /} + +
+
+
+ +
+ +
+
+
+ + +
+
+ 建议尺寸:宽200像素*高200像素的png图片 +
+ +
+ +
+ +
+
+
+ 如:/pages/user/user +
+ +
+ +
+ +
+
+
+ 只能填写大于0整数,数字越大排序越前 +
+ +
+ +
+ + +
+
+ +
+ +
+
+
+ diff --git a/app/admin/view/decoration/menu_decorate/edit_tools.html b/app/admin/view/decoration/menu_decorate/edit_tools.html new file mode 100644 index 00000000..418cc86f --- /dev/null +++ b/app/admin/view/decoration/menu_decorate/edit_tools.html @@ -0,0 +1,86 @@ +{layout name="layout2" /} + +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ 建议尺寸:宽200像素*高200像素的png图片 +
+ +
+ +
+ +
+
+
+ 如:/pages/user/user +
+ +
+ +
+ +
+
+
+ 只能填写大于0整数,数字越大排序越前 +
+ +
+ +
+ + +
+
+ +
+ +
+
+
+ diff --git a/app/admin/view/decoration/menu_decorate/lists.html b/app/admin/view/decoration/menu_decorate/lists.html index 22d04f1d..607861ea 100644 --- a/app/admin/view/decoration/menu_decorate/lists.html +++ b/app/admin/view/decoration/menu_decorate/lists.html @@ -20,7 +20,8 @@
@@ -41,6 +42,24 @@
+
+
+ +
+
+ + +
{if (1 == $type) } @@ -189,7 +208,7 @@
- {/if} + {/if}
@@ -221,6 +240,21 @@ ,{title: '操作', width: 240, align: 'center', fixed: 'right', toolbar: '#table-operation'} ],{type:type},true); + like.tableLists('#like-tools-lists','{:url("decoration.MenuDecorate/toolsList")}',[ + {field: 'id', width: 60, title: 'ID'} + ,{field: 'name', width: 260, align: 'center', title: '工具名称'} + ,{field: 'image', width: 120,title: '图标', templet: '#image'} + ,{field: 'url', width: 180,title: '链接地址'} + ,{field: 'is_show_desc', width: 120,title: '状态',templet: function(d){ + if(1 == d.is_show){ + return '显示'; + } + return '隐藏'; + }} + ,{field: 'sort', width: 120,title: '排序'} + ,{title: '操作', width: 240, align: 'center', fixed: 'right', toolbar: '#tools-table-operation'} + ],{type:type},true); + var active = { add:function(){ layer.open({ @@ -329,7 +363,113 @@ layer.close(index); }) }, - + addTools: function() { + layer.open({ + type: 2 + ,title: '新增工具' + ,content: '{:url("decoration.MenuDecorate/addTools")}?type='+type + ,area: ['90%', '90%'] + ,btn: ['确定', '取消'] + ,yes: function(index, layero){ + var iframeWindow = window['layui-layer-iframe'+ index] + ,submitID = 'addToolsSubmit' + ,submit = layero.find('iframe').contents().find('#'+ submitID); + //监听提交 + iframeWindow.layui.form.on('submit('+ submitID +')', function(data){ + var field = data.field; + field.type = type; + like.ajax({ + url:'{:url("decoration.MenuDecorate/addTools")}', + data:field, + type:"post", + success:function(res) + { + if(res.code == 1) { + layui.layer.msg(res.msg); + layer.close(index); + table.reload('like-table-lists'); + } + } + }); + }); + submit.trigger('click'); + } + }); + }, + editTools: function(obj) { + var id = obj.data.id; + layer.open({ + type: 2 + ,title: '编辑工具' + ,content: '{:url("decoration.MenuDecorate/editTools")}?id=' + id + ,area: ['90%', '90%'] + ,btn: ['确定', '取消'] + ,yes: function(index, layero){ + var iframeWindow = window['layui-layer-iframe'+ index] + ,submitID = 'editToolSubmit' + ,submit = layero.find('iframe').contents().find('#'+ submitID); + //监听提交 + iframeWindow.layui.form.on('submit('+ submitID +')', function(data){ + var field = data.field; + field.type = type; + like.ajax({ + url:'{:url("decoration.MenuDecorate/editTools")}', + data:field, + type:"post", + success:function(res) + { + if(res.code == 1) { + layui.layer.msg(res.msg); + layer.close(index); + table.reload('like-table-lists'); + } + } + }); + }); + submit.trigger('click'); + } + }); + }, + statusTools: function(obj) { + var is_show = 1 == obj.data.is_show ? 0 : 1; + if(is_show){ + var tips = "确定显示菜单:"+ obj.data.name +""; + }else{ + var tips = "确定隐藏菜单:"+ obj.data.name +""; + } + layer.confirm(tips, function(index) { + like.ajax({ + url: "{:url('decoration.MenuDecorate/swtichToolsStatus')}", + data: {id: obj.data.id, is_show: is_show}, + type: "POST", + success: function (res) { + if (res.code === 1) { + layui.layer.msg(res.msg); + layer.close(index); + table.reload('like-tools-lists'); + } + } + }); + layer.close(index); + }) + }, + delTools: function(obj) { + layer.confirm("确定删除菜单:"+ obj.data.name +"", function(index) { + like.ajax({ + url: "{:url('decoration.MenuDecorate/delTools')}", + data: {id: obj.data.id}, + type: "POST", + success: function (res) { + if (res.code === 1) { + layui.layer.msg(res.msg); + layer.close(index); + obj.del(); + } + } + }); + layer.close(index); + }) + } }; like.eventClick(active);