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

@@ -11,7 +11,39 @@
<div class="layui-form-item">
<label class="layui-form-label required">分配节点</label>
<div class="layui-input-block">
<div id="node_ids" class="demo-tree-more"></div>
<table class="layui-table" lay-size="sm">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th>模块</th>
<th>功能</th>
<th>权限</th>
</tr>
</thead>
<tbody>
{volist name='$module_list' id='module'}
{volist name='$module.children' id='controller_item'}
<tr class="auth-node-tr">
<td style="white-space: nowrap;">{$controller_item.module}</td>
<td title="{$controller_item.node}">
<input lay-filter="controller-checkbox" type="checkbox" title="{$controller_item.title}">
</td>
<td>
{volist name='controller_item.children' id='action'}
<div title="{$action.node}" style="display: inline-block;">
<input type="checkbox" lay-filter="action-checkbox" name="node[]" title="{$action.title}" {$action.checked} {$action.disabled} value="{$action.node}">
</div>
{/volist}
</td>
</tr>
{/volist}
{/volist}
</tbody>
</table>
</div>
</div>

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();
});

View File

@@ -22,6 +22,7 @@ $(function () {
method: 'open',
auth: 'authorize',
class: 'layui-btn layui-btn-normal layui-btn-xs',
extend: 'data-full="true"'
}],
'delete'
]

View File

@@ -1,10 +1,61 @@
<div class="layuimini-container">
<div class="layuimini-main">
<table id="currentTable" class="layui-table layui-hide"
data-auth-refresh="{:auth('system.node/refreshNode')}"
data-auth-clear="{:auth('system.node/clearNode')}"
data-auth-modify="{:auth('system.node/modify')}"
lay-filter="currentTable">
</table>
<div class="layui-tabs">
<ul class="layui-tabs-header">
{volist name='module_list' id='vo'}
<li>{$vo.title}</li>
{/volist}
</ul>
<div class="layui-tabs-body">
{volist name='module_list' id='module_tab'}
<div class="layui-tabs-item">
<table class="layui-table" lay-size="sm">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th>模块</th>
<th>功能</th>
<th>权限</th>
</tr>
</thead>
<tbody>
{volist name='$module_list' id='module'}
{volist name='$module.children' id='controller_item'}
{if $module_tab.title == '全部' || $controller_item.module == $module_tab.title }
<tr>
<td style="white-space: nowrap;">{$controller_item.module}</td>
<td title="{$controller_item.node}">{$controller_item.title}</td>
<td>
<div class="layui-btn-container">
{volist name='controller_item.children' id='action'}
<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" title="{$action.node}">
{$action.title}
{if $action.auth}
<span class="layui-badge layui-bg-blue" title="已开启权限控制">
开启
</span>
{else/}
<span class="layui-badge" title="已关闭权限控制">
关闭
</span>
{/if}
</button>
{/volist}
</div>
</td>
</tr>
{/if}
{/volist}
{/volist}
</tbody>
</table>
</div>
{/volist}
</div>
</div>
</div>
</div>

View File

@@ -1,47 +1,3 @@
$(function () {
ua.table.render({
init: init,
search: false,
page: false,
toolbar: ['refresh',
[{
text: '更新节点',
title: '确定更新新节点?',
url: 'system.node/refreshNode?force=0',
method: 'request',
auth: 'refresh',
class: 'layui-btn layui-btn-success layui-btn-sm',
icon: 'fa fa-hourglass',
extend: 'data-table="' + init.tableRenderId + '"',
}, {
text: '强制更新节点',
title: '该操作会覆盖已存在的节点信息。<br>确定强制更新节点?',
url: 'system.node/refreshNode?force=1',
method: 'request',
auth: 'refresh',
class: 'layui-btn layui-btn-sm layui-btn-normal',
icon: 'fa fa-hourglass',
extend: 'data-table="' + init.tableRenderId + '"',
}, {
text: '清除失效节点',
title: '确定清除失效节点?',
url: 'system.node/clearNode',
method: 'request',
auth: 'clear',
class: 'layui-btn layui-btn-sm layui-btn-danger',
icon: 'fa fa-trash-o',
extend: 'data-table="' + init.tableRenderId + '"',
}
]],
cols: [[
{ field: 'node', sort: false, minWidth: 200, align: 'left', title: '系统节点' },
{ field: 'title', sort: false, minWidth: 80, title: '节点名称 <i class="table-edit-tips color-red">*</i>', edit: 'text' },
{ field: 'update_time', sort: false, minWidth: 80, title: '更新时间', search: 'range' },
{ field: 'is_auth', sort: false, title: '节点控制', width: 85, search: 'select', selectList: { 0: '禁用', 1: '启用' }, templet: ua.table.switch },
]],
});
ua.listen();
});