mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-08-30 12:45:32 +08:00
feat(mcp): 密钥授权页,仅创建者拥有的节点可授权(防越权与漂移)
This commit is contained in:
@@ -8,4 +8,5 @@ var init = {
|
||||
deleteUrl: 'system.mcp_key/delete',
|
||||
exportUrl: 'system.mcp_key/export',
|
||||
modifyUrl: 'system.mcp_key/modify',
|
||||
authorize_url: 'system.mcp_key/authorize',
|
||||
};
|
||||
|
||||
59
extend/base/admin/view/system/mcp_key/authorize.html
Normal file
59
extend/base/admin/view/system/mcp_key/authorize.html
Normal file
@@ -0,0 +1,59 @@
|
||||
<div class="layuimini-container">
|
||||
<form id="app-form" class="layui-form layuimini-form">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">密钥名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="title" readonly class="layui-input" value="{$row.title|default=''}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">分配节点</label>
|
||||
<div class="layui-input-block">
|
||||
<table class="layui-table" lay-size="sm">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="white-space: nowrap;">模块</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>
|
||||
|
||||
<input type="hidden" name="id" readonly class="layui-input" value="{$row.id}">
|
||||
|
||||
<div class="hr-line"></div>
|
||||
<div class="layui-form-item text-center">
|
||||
<button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="system.mcp_key/saveAuthorize">确认</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
50
extend/base/admin/view/system/mcp_key/authorize.js
Normal file
50
extend/base/admin/view/system/mcp_key/authorize.js
Normal file
@@ -0,0 +1,50 @@
|
||||
$(function () {
|
||||
|
||||
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);
|
||||
}
|
||||
})
|
||||
});
|
||||
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();
|
||||
});
|
||||
@@ -6,6 +6,7 @@
|
||||
data-auth-edit="{:auth('system.mcp_key/edit')}"
|
||||
data-auth-delete="{:auth('system.mcp_key/delete')}"
|
||||
data-auth-modify="{:auth('system.mcp_key/modify')}"
|
||||
data-auth-authorize="{:auth('system.mcp_key/authorize')}"
|
||||
lay-filter="currentTable">
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -40,7 +40,15 @@ $(function(){
|
||||
{field: 'status', search: 'select', selectList: ua.getDataBrage('select_list_status'), title: '状态', width: 100, templet: ua.table.switch},
|
||||
{field: 'remark', title: '备注', templet: ua.table.text},
|
||||
{
|
||||
width: 150, title: '操作', templet: ua.table.tool, fixed: 'right', operat: [
|
||||
width: 210, title: '操作', templet: ua.table.tool, fixed: 'right', operat: [
|
||||
[{
|
||||
text: '授权',
|
||||
url: init.authorize_url,
|
||||
method: 'open',
|
||||
auth: 'authorize',
|
||||
class: 'layui-btn layui-btn-normal layui-btn-xs',
|
||||
extend: 'data-full="true"'
|
||||
}],
|
||||
'edit',
|
||||
'delete'
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user