修改系统菜单管理

This commit is contained in:
邹景立 2022-03-03 00:21:22 +08:00
parent e88ecd84b0
commit d92c83bcf9
5 changed files with 114 additions and 83 deletions

View File

@ -42,7 +42,7 @@ class Menu extends Controller
{
$this->title = '系统菜单管理';
$this->type = input('get.type', 'index');
SystemMenu::mQuery()->order('sort desc,id asc')->page(false, true);
SystemMenu::mQuery()->order('sort desc,id asc')->layTable();//->page(false, true);
}
/**
@ -131,7 +131,6 @@ class Menu extends Controller
*/
public function state()
{
$this->_applyFormToken();
SystemMenu::mSave($this->_vali([
'status.in:0,1' => '状态值范围异常!',
'status.require' => '状态值不能为空!',
@ -144,7 +143,6 @@ class Menu extends Controller
*/
public function remove()
{
$this->_applyFormToken();
SystemMenu::mDelete();
}
}

View File

@ -2,7 +2,7 @@
{block name="button"}
<!--{if $type eq 'index' and auth("add")}-->
<button data-modal='{:url("add")}' data-title="添加菜单" class='layui-btn layui-btn-sm layui-btn-primary'>添加菜单</button>
<button data-modal='{:url("add")}' class='layui-btn layui-btn-sm layui-btn-primary'>添加菜单</button>
<!--{/if}-->
<!--{if $type eq 'index' and auth("state")}-->
@ -25,78 +25,102 @@
{/if}{/foreach}
</ul>
<div class="layui-tab-content">
{empty name='list'}
<div class="notdata">没有记录哦</div>
{else}
<table class="layui-table" lay-skin="line">
<thead>
<tr>
<th class='list-table-check-td think-checkbox'>
<label><input data-auto-none data-check-target='.list-check-box' type='checkbox'></label>
</th>
<th class='list-table-sort-td'>
<button type="button" data-reload class="layui-btn layui-btn-xs"> </button>
</th>
<th class='text-center' style="width:30px"></th>
<th style="width:230px"></th>
<th class='layui-hide-xs' style="width:180px"></th>
<th colspan="2"></th>
</tr>
</thead>
<tbody>
{foreach $list as $key=>$vo}
<tr data-dbclick class="{if ($type eq 'index' and $vo.status eq 0)}layui-hide{/if}">
<td class='list-table-check-td think-checkbox'>
<label><input class="list-check-box" value='{$vo.ids}' type='checkbox'></label>
</td>
<td class='list-table-sort-td'>
<input data-action-blur="{:sysuri()}" data-value="id#{$vo.id};action#sort;sort#{value}" data-loading="false" value="{$vo.sort}" class="list-sort-input">
</td>
<td class='text-center'><i class="{$vo.icon} font-s18"></i></td>
<td class="nowrap"><span class="color-desc">{$vo.spl|raw}</span>{$vo.title}</td>
<td class='layui-hide-xs layui-elip'>{$vo.url}</td>
<td class='text-center nowrap'>{eq name='vo.status' value='0'}<span class="color-red">已禁用</span>{else}<span class="color-green">已激活</span>{/eq}</td>
<td class='text-center nowrap notselect'>
{if isset($type) and $type eq 'index'}
{if auth("add")}
<!--{if $vo.spt < 2}-->
<a class="layui-btn layui-btn-sm layui-btn-primary" data-title="添加子菜单" data-modal='{:url("add")}?pid={$vo.id}'> </a>
<!--{else}-->
<a class="layui-btn layui-btn-sm layui-btn-disabled"> </a>
<!--{/if}-->
{/if}
<!--{if auth("edit")}-->
<a data-dbclick class="layui-btn layui-btn-sm" data-title="编辑菜单" data-modal='{:url("edit")}?id={$vo.id}'> </a>
<!--{/if}-->
<!--{if $vo.status eq 1 and auth("state")}-->
<a class="layui-btn layui-btn-warm layui-btn-sm" data-confirm="确定要禁用菜单吗?" data-action="{:url('state')}" data-value="id#{$vo.ids};status#0" data-csrf="{:systoken('state')}"> </a>
<!--{/if}-->
{else}
<!--{if auth("state")}-->
<a class="layui-btn layui-btn-warm layui-btn-sm" data-confirm="确定要激活菜单吗?" data-action="{:url('state')}" data-value="id#{$vo.ids};status#1" data-csrf="{:systoken('state')}"> </a>
<!--{/if}-->
<!--{if auth("remove") and ($vo.spc<1 or $vo.status<1)}-->
<a class="layui-btn layui-btn-danger layui-btn-sm" data-confirm="确定要删除菜单吗?" data-action="{:url('remove')}" data-value="id#{$vo.ids}" data-csrf="{:systoken('remove')}"> </a>
<!--{/if}-->
<!--{if auth("remove") and $vo.spc>0 and $vo.status>0}-->
<a class="layui-btn layui-btn-disabled layui-btn-sm"> </a>
<!--{/if}-->
{/if}
</td>
</tr>
{/foreach}
</tbody>
</table>
{/empty}
<table id="MenuData" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
</div>
</div>
{/block}
<script>
$(function () {
$('#MenuData').layTable({
even: true, height: 'full', page: false,
sort: {field: 'sort desc,id', type: 'asc'},
where: {type: '{$type|default="index"}'},
filter: function (items) {
var type = this.where.type;
return items.filter(function (item) {
return !(type === 'index' && item.status === 0);
});
},
cols: [[
{checkbox: true, field: 'ids'},
{field: 'sort', title: '排序权重', width: 100, align: 'center', sort: true, templet: '#SortInputTpl'},
{
field: 'icon', title: '图标', width: 100, align: 'center', templet: function (d) {
return layui.laytpl('<i class="{{d.icon}} font-s18"></i>').render(d);
}
},
{
field: 'title', title: '菜单名称', minWidth: 220, templet: function (d) {
return layui.laytpl('<span class="color-desc">{{d.spl}}</span>{{d.title}}').render(d);
}
},
{field: 'status', title: '菜单状态', minWidth: 120, align: 'center', templet: '#StatusSwitchTpl'},
//{field: 'create_at', title: '创建时间', minWidth: 170, align: 'center'},
{toolbar: '#toolbar', title: '操作面板', minWidth: 170, align: 'center', fixed: 'right'},
]]
});
// 数据状态切换操作
layui.form.on('switch(StatusSwitch)', function (obj) {
var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
if (data.status > 0) data.id += obj.elem.dataset.path.replace(/-/g, ',');
$.form.load("{:url('state')}", data, 'post', function (ret) {
if (obj.value.indexOf(',') > -1) {
$('#MenuData').trigger('reload');
} else if (ret.code < 1) $.msg.error(ret.info, 3, function () {
$('#MenuData').trigger('reload');
});
return false;
}, false);
});
});
</script>
<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
<!--{if auth("state")}-->
{{# if( "{$type|default='index'}"==='index' || (d.spc<1 || d.status<1)){ }}
<input type="checkbox" value="{{d.ids}}" data-path="{{d.path}}" lay-skin="switch" lay-text="已激活|已禁用" lay-filter="StatusSwitch" {{d.status>0?'checked':''}}>
{{# }else{ }}
{{d.status ? '<b class="color-green">已激活</b>' : '<b class="color-red">已禁用</b>'}}
{{# } }}
<!--{else}-->
{{d.status ? '<b class="color-green">已激活</b>' : '<b class="color-red">已禁用</b>'}}
<!--{/if}-->
</script>
<!-- 列表排序权重模板 -->
<script type="text/html" id="SortInputTpl">
<input type="number" min="0" data-blur-number="0" data-action-blur="{:sysuri()}" data-value="id#{{d.id}};action#sort;sort#{value}" data-loading="false" value="{{d.sort}}" class="layui-input text-center">
</script>
<!-- 操控面板的模板 -->
<script type="text/html" id="toolbar">
<!-- {if isset($type) and $type eq 'index'} -->
<!-- {if auth('add')} -->
{{# if(d.spt<2){ }}
<a class="layui-btn layui-btn-sm layui-btn-primary" data-title="添加系统菜单" data-modal='{:url("add")}?pid={{d.id}}'> </a>
{{# }else{ }}
<a class="layui-btn layui-btn-sm layui-btn-disabled"> </a>
{{# } }}
<!-- {/if} -->
{if auth('edit')}
<a class="layui-btn layui-btn-sm" data-title="编辑系统菜单" data-modal='{:url("edit")}?id={{d.id}}'> </a>
{/if}
<!-- {else} -->
{if auth('remove')}
{{# if( (d.spc<1 || d.status<1)){ }}
<a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="确定要删除菜单吗?" data-action="{:url('remove')}" data-value="id#{{d.ids}}"> </a>
{{# }else{ }}
<a class="layui-btn layui-btn-disabled layui-btn-sm"> </a>
{{# } }}
{/if}
<!-- {/if} -->
</script>
{/block}

View File

@ -41,6 +41,12 @@
cols: [[
{checkbox: true, fixed: true},
{field: 'sort', title: '排序权重', width: 100, align: 'center', sort: true, templet: '#SortInputTpl'},
{
field: 'headimg', title: '头像', width: 60, align: 'center', templet: function (d) {
if (!d.headimg) return '';
return layui.laytpl('<div data-tips-image data-tips-hover class="headimg headimg-xs margin-0" data-lazy-src="{{d.headimg}}" style="background-image:url({{d.headimg}})"></div>').render(d);
}
},
{field: 'username', title: '登录账号', minWidth: 110, templet: '<div>{{d.username||"-"}}</div>'},
{field: 'nickname', title: '用户名称', minWidth: 110, templet: '<div>{{d.nickname||"-"}}</div>'},
/* {notempty name='bases'} */
@ -65,7 +71,7 @@
layui.form.on('switch(StatusSwitch)', function (obj) {
$.form.load("{:url('state')}", {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0}, 'post', function (ret) {
if (ret.code < 1) $.msg.error(ret.info, 3, function () {
$('#UserData').trigger('reload'); // 操作异常时重载数据
$('#UserData').trigger('reload');
});
return false;
}, false);

View File

@ -3,16 +3,16 @@
<form class="layui-form layui-form-pane form-search" action="{:sysuri()}" onsubmit="return false" method="get" autocomplete="off">
<div class="layui-form-item layui-inline">
<label class="layui-form-label">用户名称</label>
<label class="layui-form-label">登录账号</label>
<label class="layui-input-inline">
<input name="nickname" value="{$get.nickname|default=''}" placeholder="请输入用户名称" class="layui-input">
<input name="username" value="{$get.username|default=''}" placeholder="请输入登录账号" class="layui-input">
</label>
</div>
<div class="layui-form-item layui-inline">
<label class="layui-form-label">登录账号</label>
<label class="layui-form-label">用户名称</label>
<label class="layui-input-inline">
<input name="username" value="{$get.username|default=''}" placeholder="请输入登录账号" class="layui-input">
<input name="nickname" value="{$get.nickname|default=''}" placeholder="请输入用户名称" class="layui-input">
</label>
</div>

View File

@ -693,9 +693,12 @@ $(function () {
option.done = function () {
layui.sessionData('pages', {key: table.id, value: this.page.curr || 1}), (table.loading = true);
$table.next().find('[data-load],[data-queue],[data-action],[data-iframe]').not('[data-table-id]').attr('data-table-id', table.id);
}, option.parseData = function (res) {
};
option.parseData = function (res) {
if (typeof params.filter === 'function') res.data = params.filter(res.data);
var maxp = Math.ceil(res.count / table.limit), curp = layui.sessionData('pages')[option.id] || 1;
if (curp > maxp && curp > 1) table.elem.trigger('reload', {page: {curr: maxp}});
return res;
};
// 实例并绑定的对象
$table.data('this', layui.table.render(bindData(option)));