Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 修复菜单管理的一些问题 #136

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/admin/controller/system/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public function edit($id)
'icon|菜单图标' => 'require',
];
$this->validate($post, $rule);
//防止首页pid被修改而导致渲染时报错
if ($row->pid == MenuConstant::HOME_PID) {
unset($post['pid']);
}
try {
$save = $row->save($post);
} catch (\Exception $e) {
Expand Down
77 changes: 68 additions & 9 deletions public/static/admin/js/system/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
var table = layui.table,
treetable = layui.treetable,
iconPickerFa = layui.iconPickerFa,
autocomplete = layui.autocomplete;
autocomplete = layui.autocomplete,
form = layui.form;

var init = {
table_elem: '#currentTable',
Expand Down Expand Up @@ -75,8 +76,17 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
auth: 'edit',
class: 'layui-btn layui-btn-xs layui-btn-success',
extend: 'data-full="true"',
}],
'delete'
}, {
class: 'layui-btn layui-btn-danger layui-btn-xs',
method: 'url',
field: 'id',
icon: '',
text: '删除',
title: '确定删除?',
auth: 'delete',
url: init.delete_url,
extend: 'data-treetable-delete-row'
}]
]
}
]], init),
Expand All @@ -88,11 +98,9 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu

renderTable();

$('body').on('click', '[data-treetable-refresh]', function () {
$('body').on('click', '[data-treetable-refresh]', function () { //刷新
renderTable();
});

$('body').on('click', '[data-treetable-delete]', function () {
}).on('click', '[data-treetable-delete]', function () { //多选删除
var tableId = $(this).attr('data-treetable-delete'),
url = $(this).attr('data-url');
tableId = tableId || init.table_render_id;
Expand Down Expand Up @@ -120,11 +128,62 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
});
});
return false;
}).on('click', '[data-treetable-delete-row]', function () { //单行删除
var title = $(this).attr('data-title'),
url = $(this).attr('data-url');
url = url != undefined ? ea.url(url) : window.location.href;
ea.msg.confirm(title, function () {
ea.request.post({
url: url
}, function (res) {
ea.msg.success(res.msg, function () {
renderTable();
});
})
});
});

ea.table.listenSwitch({filter: 'status', url: init.modify_url});
//监听switch
form.on('switch(status)', function (obj) {
ea.request.post({
url: init.modify_url,
prefix: true,
data: {
id: obj.value,
field: obj.elem.name,
value: obj.elem.checked ? 1 : 0,
},
}, function (res) {
// renderTable();
}, function (res) {
ea.msg.error(res.msg, function () {
renderTable();
});
}, function () {
renderTable();
});
});

ea.table.listenEdit(init, 'currentTable', init.table_render_id, true);
//监听编辑
table.on('edit(currentTable)', function (obj) {
ea.request.post({
url: init.modify_url,
prefix: true,
data: {
id: obj.data.id,
field: obj.field,
value: obj.value,
},
}, function (res) {
renderTable();
}, function (res) {
ea.msg.error(res.msg, function () {
renderTable();
});
}, function () {
renderTable();
});
});

ea.listen();
},
Expand Down
4 changes: 4 additions & 0 deletions public/static/plugs/easy-admin/easy-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ define(["jquery", "tableSelect","xmSelect", "ckeditor"], function ($, tableSelec
formatToolbar.method = formatToolbar.method !== '' ? 'data-open="' + formatToolbar.url + '" data-title="' + formatToolbar.title + '" ' : '';
} else if (toolbar.method === 'none'){ // 常用于与extend配合,自定义监听按钮
formatToolbar.method = '';
} else if (toolbar.method === 'url') { // 与extend配合自定义监听url的处理方式
formatToolbar.method = formatToolbar.method !== '' ? 'data-url="' + formatToolbar.url + '" data-title="' + formatToolbar.title + '" ' : '';
} else {
formatToolbar.method = formatToolbar.method !== '' ? 'data-request="' + formatToolbar.url + '" data-title="' + formatToolbar.title + '" ' : '';
}
Expand Down Expand Up @@ -499,6 +501,8 @@ define(["jquery", "tableSelect","xmSelect", "ckeditor"], function ($, tableSelec
formatOperat.method = formatOperat.method !== '' ? 'data-open="' + formatOperat.url + '" data-title="' + formatOperat.title + '" ' : '';
} else if (operat.method === 'none'){ // 常用于与extend配合,自定义监听按钮
formatOperat.method = '';
} else if (operat.method === 'url') { // 与extend配合自定义监听url的处理方式
formatOperat.method = formatOperat.method !== '' ? 'data-url="' + formatOperat.url + '" data-title="' + formatOperat.title + '" ' : '';
} else {
formatOperat.method = formatOperat.method !== '' ? 'data-request="' + formatOperat.url + '" data-title="' + formatOperat.title + '" ' : '';
}
Expand Down