diff --git a/extend/base/admin/view/system/auth/_common.js b/extend/base/admin/view/system/auth/_common.js
index 55f0a81..176e27f 100644
--- a/extend/base/admin/view/system/auth/_common.js
+++ b/extend/base/admin/view/system/auth/_common.js
@@ -8,4 +8,6 @@ var init = {
exportUrl: 'system.auth/export',
modifyUrl: 'system.auth/modify',
authorize_url: 'system.auth/authorize',
+ assignUsersUrl: 'system.auth/assignUsers',
+ toggleUserUrl: 'system.auth/toggleUser',
};
\ No newline at end of file
diff --git a/extend/base/admin/view/system/auth/assign_users.html b/extend/base/admin/view/system/auth/assign_users.html
new file mode 100644
index 0000000..b5f4732
--- /dev/null
+++ b/extend/base/admin/view/system/auth/assign_users.html
@@ -0,0 +1,14 @@
+
diff --git a/extend/base/admin/view/system/auth/assign_users.js b/extend/base/admin/view/system/auth/assign_users.js
new file mode 100644
index 0000000..6e491f7
--- /dev/null
+++ b/extend/base/admin/view/system/auth/assign_users.js
@@ -0,0 +1,68 @@
+$(function () {
+ // 本页自有 init,不复用 _common.js(index 页用),指向 assignUsers 数据源与 toggleUser 切换接口
+ var init = {
+ tableElem: '#currentTable',
+ tableRenderId: 'assignUsersRenderId',
+ indexUrl: 'system.auth/assignUsers', // AJAX 数据源:后端 isAjax 时返回用户列表(每行带 has_role)
+ toggleUserUrl: 'system.auth/toggleUser',
+ };
+
+ ua.table.render({
+ init: init,
+ // 把 role_id 带入分页请求,后端 assignUsers($id) 据此计算 FIND_IN_SET(has_role)
+ where: { id: $('#roleId').val() },
+ cols: [[
+ { field: 'id', width: 80, title: 'ID' },
+ { field: 'username', minWidth: 100, title: '登录账户' },
+ { field: 'nickname', minWidth: 100, title: '姓名' },
+ { field: 'phone', minWidth: 120, title: '手机' },
+ {
+ field: 'has_role',
+ width: 130,
+ title: '是否拥有此角色',
+ // 关键(Metis M1):filter:false 使 renderSwitch 不自动绑定到 modifyUrl
+ // (modifyUrl 未配置亦无妨,显式 false 更稳妥,避免 listenSwitch 发送 field=value 而非 user_id/role_id)
+ filter: false,
+ // 自定义 templet(绝不能用 ua.table.switch,它会把 id/field/value 发到 modifyUrl)
+ templet: function (d) {
+ var checked = (d.has_role > 0) ? ' checked' : '';
+ return '';
+ }
+ }
+ ]],
+ });
+
+ // 手动 switch 处理(因为 ua.table.switch / listenSwitch 会发 id/field/value 到 modifyUrl,
+ // 而本场景需要发 user_id + role_id 到 toggleUser)
+ layui.form.on('switch(hasRoleSwitch)', function (obj) {
+ var userId = this.value;
+ var roleId = $('#roleId').val();
+ var elem = this;
+ $.ajax({
+ // ulthon 风格相对 URL,必须经 ua.url() 补 /admin/ 前缀
+ url: ua.url(init.toggleUserUrl),
+ type: 'POST',
+ dataType: 'json',
+ data: { user_id: userId, role_id: roleId },
+ success: function (res) {
+ // 框架 success() 默认 code=0(见 JumpTraitBase::success),error() 默认 code=500
+ if (res.code === 0) {
+ layer.msg(res.msg || '操作成功', { icon: 1 });
+ } else {
+ // 业务失败:回滚开关状态
+ elem.checked = !elem.checked;
+ layui.form.render('checkbox');
+ layer.msg(res.msg || '操作失败', { icon: 2 });
+ }
+ },
+ error: function () {
+ // 网络错误:回滚开关状态
+ elem.checked = !elem.checked;
+ layui.form.render('checkbox');
+ layer.msg('网络错误', { icon: 2 });
+ }
+ });
+ });
+
+ ua.listen();
+});
diff --git a/extend/base/admin/view/system/auth/index.html b/extend/base/admin/view/system/auth/index.html
index 5bc071a..2a35509 100644
--- a/extend/base/admin/view/system/auth/index.html
+++ b/extend/base/admin/view/system/auth/index.html
@@ -5,6 +5,7 @@
data-auth-edit="{:auth('system.auth/edit')}"
data-auth-delete="{:auth('system.auth/delete')}"
data-auth-authorize="{:auth('system.auth/authorize')}"
+ data-auth-assignUsers="{:auth('system.auth/assignUsers')}"
data-auth-modify="{:auth('system.auth/modify')}"
lay-filter="currentTable">
diff --git a/extend/base/admin/view/system/auth/index.js b/extend/base/admin/view/system/auth/index.js
index e437f79..9bd70b1 100644
--- a/extend/base/admin/view/system/auth/index.js
+++ b/extend/base/admin/view/system/auth/index.js
@@ -24,6 +24,14 @@ $(function () {
class: 'layui-btn layui-btn-normal layui-btn-xs',
extend: 'data-full="true"'
}],
+ [{
+ text: '分配用户',
+ url: init.assignUsersUrl,
+ method: 'open',
+ auth: 'assignUsers',
+ class: 'layui-btn layui-btn-warm layui-btn-xs',
+ extend: 'data-full="true"'
+ }],
'delete'
]
}