2021-01-30 20:59:12 +08:00

115 lines
3.4 KiB
HTML

{extend name="common/base"/}
{block name="style"}
<style>
html,
body {
height: calc(100% - 20px);
}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<div class="body-content" style="height: 100%">
<div style="height:39px;">
<a class="layui-btn layui-btn-normal layui-btn-sm" href="/admin/menu/add">添加菜单</a>
</div>
<div style="height: calc(100% - 30px)">
<table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
</div>
</div>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
var editObj = null, ptable = null, treeGrid = null, tableId = 'treeTable', layer = null;
function init(layui) {
var treeGrid = layui.treeGrid;//很重要
layer = layui.layer;
ptable = treeGrid.render({
id: tableId
, elem: '#' + tableId
, idField: 'id'
, url: '/admin/menu/get_list'
, cellMinWidth: 100
, treeId: 'id'//树形id字段名称
, treeUpId: 'pid'//树形父id字段名称
, treeShowName: 'title'//以树形式显示的字段
, height: 'full-0'
, cols: [[
{ field: 'order', width: 80, title: '排序', edit: "text", align: 'center' }
, { field: 'id', width: 80, title: 'ID号', align: 'center' }
, { field: 'title', edit: 'text', width: 240, title: '名称', edit: "text" }
, { field: 'icon', edit: 'text', width: 180, title: '图标<a href="{__LAYUI__}/font/extend/demo_index.html" target="_blank" style="color:#007AFF">[图标选择]</a>', edit: "text" }
, { field: 'pid', title: '父级ID', edit: "text", width: 80, align: 'center' }
, { field: 'src', title: '路径', edit: "text" }
, {
width: 100, title: '操作', align: 'center'
, templet: function (d) {
var html = '';
var addBtn = '<a class="layui-btn layui-btn-normal layui-btn-xs" href="/admin/menu/add?pid=' + d.id + '">添加</a>';
var delBtn = '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
return addBtn + delBtn;
}
}
]]
, page: false
//,skin:'line'
});
//单元格编辑
treeGrid.on('edit(' + tableId + ')', function (obj) {
layer.confirm('确定要提交修改吗?', { icon: 3, title: '提示' }, function (index) {
$.ajax({
url: "/admin/menu/post_submit",
type: 'post',
data: { id: obj.data.id, field: obj.field, value: obj.value },
success: function (res) {
if (res.code == 1) {
layer.msg(res.msg);
setTimeout('location.reload()', 2000);
}
}
})
layer.close(index);
});
});
//删除
treeGrid.on('tool(' + tableId + ')', function (obj) {
if (obj.event === 'del') {
layer.confirm('确定要删除吗?', { icon: 3, title: '提示' }, function (index) {
$.ajax({
url: "/admin/menu/delete",
type: 'post',
data: { id: obj.data.id },
success: function (res) {
layer.msg(res.msg);
if (res.code == 1) {
obj.del();
}
}
})
layer.close(index);
});
}
});
}
function openorclose() {
var map = treeGrid.getDataMap(tableId);
var o = map['1'];
treeGrid.treeNodeOpen(o, !o[treeGrid.config.cols.isOpen]);
}
function getCheckData() {
var checkStatus = treeGrid.checkStatus(tableId)
, data = checkStatus.data;
layer.alert(JSON.stringify(data));
}
</script>
{include file="common/layui" base='base' extend="['treeGrid']" use="['jquery','treeGrid','layer']" callback="init" /}
{/block}
<!-- /脚本 -->