88 lines
2.6 KiB
HTML
88 lines
2.6 KiB
HTML
{extend name="common/base"/}
|
|
|
|
<!-- 主体 -->
|
|
{block name="body"}
|
|
<div class="body-table" style="margin-bottom:0;">
|
|
<div class="layui-form-bar">
|
|
<button class="layui-btn layui-btn-normal layui-btn-sm add-menu">+ 添加菜单</button>
|
|
</div>
|
|
<div>
|
|
<table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
|
|
</div>
|
|
</div>
|
|
{/block}
|
|
<!-- /主体 -->
|
|
|
|
<!-- 脚本 -->
|
|
{block name="script"}
|
|
<script>
|
|
var ptable = null, treeGrid = null,rightpage=null, layer = null, tableId = "treeTable";
|
|
function init(layui) {
|
|
treeGrid = layui.treeGrid;
|
|
rightpage = layui.rightpage;
|
|
layer = layui.layer;
|
|
ptable = treeGrid.render({
|
|
id: tableId
|
|
, elem: '#' + tableId
|
|
, idField: 'id'
|
|
, url: "/home/menu/index"
|
|
, cellMinWidth: 100
|
|
, treeId: 'id'//树形id字段名称
|
|
, treeUpId: 'pid'//树形父id字段名称
|
|
, treeShowName: 'title'//以树形式显示的字段
|
|
, height: 'full-0'
|
|
, cols: [[
|
|
{ field: 'sort', width: 80, title: '排序', align: 'center' }
|
|
, { field: 'id', width: 80, title: 'ID号', align: 'center' }
|
|
, { field: 'title', width: 240, title: '菜单名称'}
|
|
, { field: 'icon', width: 180, title: '图标class'}
|
|
, { field: 'src', title: '菜单路径'}
|
|
, { width: 160, title: '操作', align: 'center', templet: function (d) {
|
|
var html = '<span class="layui-btn-group"><button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="add">添加子菜单</button><button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button><button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button></span>';
|
|
return html;
|
|
}
|
|
}
|
|
]]
|
|
, page: false
|
|
//,skin:'line'
|
|
});
|
|
|
|
//表头工具栏事件
|
|
$('.add-menu').on('click',function(){
|
|
rightpage.open("/home/menu/add");
|
|
return;
|
|
});
|
|
|
|
//操作按钮
|
|
treeGrid.on('tool(' + tableId + ')', function (obj) {
|
|
if (obj.event === 'add') {
|
|
rightpage.open('/home/menu/add?pid='+obj.data.id);
|
|
return;
|
|
}
|
|
if (obj.event === 'edit') {
|
|
rightpage.open('/home/menu/add?id='+obj.data.id);
|
|
return;
|
|
}
|
|
if (obj.event === 'del') {
|
|
layer.confirm('确定要删除吗?', { icon: 3, title: '提示' }, function (index) {
|
|
$.ajax({
|
|
url: "/home/menu/delete",
|
|
type: 'post',
|
|
data: { id: obj.data.id },
|
|
success: function (e) {
|
|
layer.msg(e.msg);
|
|
if (e.code == 0) {
|
|
obj.del();
|
|
}
|
|
}
|
|
})
|
|
layer.close(index);
|
|
});
|
|
}
|
|
});
|
|
|
|
}
|
|
</script>
|
|
{include file="common/layui" base="base" extend="['treeGrid','rightpage']" callback="init" /}
|
|
{/block}
|
|
<!-- /脚本 --> |