From bc0d349093a919eb9f52091dc0b7a52dda59f3f9 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Mon, 29 Nov 2021 18:30:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=AE=A1=E7=90=86=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/manager/Area.php | 39 +++++++++++ app/model/Area.php | 11 +++- public/static/manager/js/area.js | 110 +++++++++++++++++++++++++++++++ view/manager/area/index.html | 24 +++++++ 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 app/controller/manager/Area.php create mode 100644 public/static/manager/js/area.js create mode 100644 view/manager/area/index.html diff --git a/app/controller/manager/Area.php b/app/controller/manager/Area.php new file mode 100644 index 0000000..ab6ca8c --- /dev/null +++ b/app/controller/manager/Area.php @@ -0,0 +1,39 @@ +request->isPost()) { + $menus = AreaModel::getAllList(); + $res = [ + 'code' => 0, + 'msg' => 'success', + 'count' => $menus->count(), + 'data' => $menus->toArray(), + ]; + return json($res); + } + return $this->view(); + } +} \ No newline at end of file diff --git a/app/model/Area.php b/app/model/Area.php index 6c78557..5fa5f66 100644 --- a/app/model/Area.php +++ b/app/model/Area.php @@ -3,6 +3,8 @@ namespace app\model; +use think\Collection; + class Area extends Base { @@ -17,9 +19,16 @@ class Area extends Base */ public static function getByPCode($PCode,bool $filter = false) { - return self::where("pcode",$PCode ) ->when($filter,function ($q){ + return self::where("pcode",$PCode) ->when($filter,function ($q){ $q->where("status",self::COMMON_ON); })->order("id asc")->select(); } + + // 获取列表 + public static function getAllList(): Collection + { + return self::order('id', 'asc') + ->select(); + } } diff --git a/public/static/manager/js/area.js b/public/static/manager/js/area.js new file mode 100644 index 0000000..baa0c99 --- /dev/null +++ b/public/static/manager/js/area.js @@ -0,0 +1,110 @@ +layui.use(['laytpl', 'treeTable', 'jquery', 'iconPickerFa', 'form', 'miniTab', 'xmSelect'], function () { + let $ = layui.jquery, + form = layui.form, + treeTable = layui.treeTable, + iconPickerFa = layui.iconPickerFa, + layer = layui.layer, + miniTab = layui.miniTab, + xmSelect = layui.xmSelect; + + + + /**** index begin ***/ + //index页面 + if ($('.location-index-page').length > 0) { + miniTab.listen(); + + // 渲染表格 + let listUrl = $('#menu-table').data('url'); + let insTb = treeTable.render({ + elem: '#menu-table', + toolbar: '#toolbar-tpl', + defaultToolbar: [], + method: 'POST', + url: listUrl, + page: false, + tree: { + iconIndex: 1, // 折叠图标显示在第几列 + isPidData: true, // 是否是id、pid形式数据 + idName: 'code', // id字段名称 + pidName: 'pcode', // pid字段名称 + Spid: '86' // pid字段名称 + }, + cols: [[ + {type: 'checkbox'}, + {field: 'title', title: '菜单名称', minWidth: 150, singleLine: true}, + {title: '图标', width: 50, templet: '
',align: 'center'}, + {field: 'name', title: '路由标识'}, + + {templet: '#menu-operate', minWidth: 250, fixed: 'right', align: 'center', title: '操作'} + ]], + done: function () { + } + }); + + + + //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 + treeTable.on('toolbar(menu-table)', function (obj) { + let layEvent = obj.event; + + //全部展开 + if (layEvent === 'expand') { + insTb.expandAll(); + return false; + } + + //全部折叠 + if (layEvent === 'fold') { + insTb.foldAll(); + return false; + } + + //删除 + if (layEvent === 'del') { + let selected = insTb.checkStatus(false); + let ids = []; + let url = $(obj.elem.context).data('href') + $.each(selected, function (index, val) { + ids.push(val.id); + }) + + del(url, ids); + return false; + } + + + }); + + //刷新 + $('body').on('click', '[data-table-refresh]', function () { + insTb.refresh(); + }); + + + } + /*** index end ***/ + + + + iconPickerFa.render({ + // 选择器,推荐使用input + elem: '.iconPicker', + // fa 图标接口 + url: "/static/layuimini/lib/font-awesome-4.7.0/less/variables.less", + // 是否开启搜索:true/false,默认true + search: true, + // 是否开启分页:true/false,默认true + page: true, + // 每页显示数量,默认12 + limit: 12, + // 点击回调 + click: function (data) { + // console.log(data); + }, + // 渲染成功后的回调 + success: function (d) { + // console.log(d); + } + }); +}); \ No newline at end of file diff --git a/view/manager/area/index.html b/view/manager/area/index.html new file mode 100644 index 0000000..0dd4563 --- /dev/null +++ b/view/manager/area/index.html @@ -0,0 +1,24 @@ +{layout name="manager/layout" /} + +
+
+
+ +
+
+
+ + + + + + + \ No newline at end of file