feat: 升级权限管理模式

This commit is contained in:
augushong
2025-03-20 16:57:05 +08:00
parent 1887733b32
commit d3e85fa552
50 changed files with 330 additions and 1125 deletions

View File

@@ -1,32 +1,50 @@
$(function () {
var tree = layui.tree;
ua.request.get(
{
url: window.location.href,
}, function (res) {
res.data = res.data || [];
tree.render({
elem: '#node_ids',
data: res.data,
showCheckbox: true,
id: 'nodeDataId',
});
}
);
ua.listen(function (data) {
var checkedData = tree.getChecked('nodeDataId');
var ids = [];
$.each(checkedData, function (i, v) {
ids.push(v.id);
if (v.children !== undefined && v.children.length > 0) {
$.each(v.children, function (ii, vv) {
ids.push(vv.id);
});
layui.form.on('checkbox(controller-checkbox)', function (data) {
var elem = data.elem;
var checked = elem.checked;
$(elem).closest('tr').find('input').each(function(i,input){
if(!$(input).prop('disabled')){
$(input).prop('checked', checked);
}
});
data.node = JSON.stringify(ids);
return data;
})
});
layui.form.on('checkbox(action-checkbox)', function (data) {
initCheckedStatus();
});
function initCheckedStatus() {
$('.auth-node-tr').each(function (i, elem) {
var checkedCount = 0;
var totalCount = 0;
$(elem).find('[lay-filter="action-checkbox"]').each(function (j, checkbox) {
totalCount++;
if ($(checkbox).prop('checked')) {
checkedCount++;
}
});
var checkedStatus;
if (checkedCount === totalCount) {
checkedStatus = 1; // 全部选中
} else if (checkedCount === 0) {
checkedStatus = -1; // 全部未选中
} else {
checkedStatus = 0; // 部分选中
}
if (checkedStatus === 0) {
$(elem).find('[lay-filter="controller-checkbox"]').prop('checked', false);
$(elem).find('[lay-filter="controller-checkbox"]').prop('indeterminate', true);
} else if (checkedStatus > 0) {
$(elem).find('[lay-filter="controller-checkbox"]').prop('checked', true);
$(elem).find('[lay-filter="controller-checkbox"]').prop('indeterminate', false);
} else {
$(elem).find('[lay-filter="controller-checkbox"]').prop('checked', false);
$(elem).find('[lay-filter="controller-checkbox"]').prop('indeterminate', false);
}
layui.form.render('checkbox');
});
}
initCheckedStatus();
ua.listen();
});