mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 10:32:48 +08:00
feat: 升级权限管理模式
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
@@ -22,6 +22,7 @@ $(function () {
|
||||
method: 'open',
|
||||
auth: 'authorize',
|
||||
class: 'layui-btn layui-btn-normal layui-btn-xs',
|
||||
extend: 'data-full="true"'
|
||||
}],
|
||||
'delete'
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user