地址管理初始化

master
wangxinglong 2021-11-29 18:30:30 +08:00
parent 737ec32bea
commit bc0d349093
4 changed files with 183 additions and 1 deletions

View File

@ -0,0 +1,39 @@
<?php
namespace app\controller\manager;
use app\repository\CmsRepository;
use app\model\Area as AreaModel;
use think\response\Json;
use think\response\View;
/**
* 地域管理
*
* Class Menu
* @package app\controller\manager
*/
class Area extends Base
{
/**
* 列表
*
* @return View|Json
*/
public function index()
{
if ($this->request->isPost()) {
$menus = AreaModel::getAllList();
$res = [
'code' => 0,
'msg' => 'success',
'count' => $menus->count(),
'data' => $menus->toArray(),
];
return json($res);
}
return $this->view();
}
}

View File

@ -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();
}
}

View File

@ -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: '<div><i class="fa {{ d.icon }}"></i></div>',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);
}
});
});

View File

@ -0,0 +1,24 @@
{layout name="manager/layout" /}
<div class="layuimini-container location-index-page">
<div class="layuimini-main">
<div>
<table id="menu-table" class="layui-table" data-url="/manager/area" lay-filter="menu-table"></table>
</div>
</div>
</div>
<!-- 操作列 -->
<script type="text/html" id="menu-operate">
<a class="layui-btn layui-btn-danger layui-btn-xs" data-href="/manager/menu/status.html" lay-event="status">关闭</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" data-href="/manager/menu/status.html" lay-event="status">开启</a>
</script>
<!-- toolbar -->
<script type="text/html" id="toolbar-tpl">
<a class="layui-btn layui-btn-primary layui-btn-sm" data-table-refresh><i class="fa fa-refresh"></i></a>
<a class="layui-btn layui-btn-warm layui-btn-sm" lay-event="expand">全部展开</a>
<a class="layui-btn layui-btn-info layui-btn-sm" lay-event="fold">全部折叠</a>
</script>
<script src="__MANAGER__/js/area.js?v={:mt_rand()}"></script>