113 lines
3.6 KiB
HTML
113 lines
3.6 KiB
HTML
<!doctype html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>用户授权</title>
|
|
<link rel="stylesheet" href="/static/component/pear/css/pear.css" />
|
|
<link rel="stylesheet" href="/static/admin/css/admin.css" />
|
|
<link rel="stylesheet" href="/static/admin/css/admin.dark.css" />
|
|
<link rel="stylesheet" href="/static/admin/css/variables.css" />
|
|
<link rel="stylesheet" href="/static/admin/css/reset.css" />
|
|
<!-- 依 赖 脚 本 -->
|
|
<script src="/static/component/layui/layui.js"></script>
|
|
<script src="/static/component/pear/pear.js"></script>
|
|
<script src="/static/js/pear_admin_flask.js"></script>
|
|
</head>
|
|
<body>
|
|
<div class="layui-panel">
|
|
<form class="layui-form" action="">
|
|
<div class="row" style="margin: 10px 5px">
|
|
<ul id="user_role" class="dtree" data-id="0"></ul>
|
|
</div>
|
|
<div class="bottom">
|
|
<div class="button-container">
|
|
<button
|
|
type="submit"
|
|
class="layui-btn layui-btn-primary layui-btn-sm"
|
|
lay-submit=""
|
|
lay-filter="role-rights-save"
|
|
>
|
|
<i class="layui-icon layui-icon-ok"></i>
|
|
提交
|
|
</button>
|
|
<button type="reset" class="layui-btn layui-btn-sm">
|
|
<i class="layui-icon layui-icon-refresh"></i>
|
|
重置
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<script>
|
|
layui.use(function () {
|
|
let tree = layui.tree;
|
|
let form = layui.form;
|
|
let $ = layui.jquery;
|
|
|
|
$.ajax({
|
|
url: "/api/v1/role?type=tree",
|
|
type: "get",
|
|
success: function (ret) {
|
|
let data = [];
|
|
$.each(ret.data, function (index, item) {
|
|
data.push({ id: item.id, title: item.name });
|
|
});
|
|
tree.render({
|
|
elem: "#user_role",
|
|
id: "user_role",
|
|
data: data,
|
|
showCheckbox: true,
|
|
});
|
|
// 请求获取当前用户的权限
|
|
$.ajax({
|
|
url: "/api/v1/user/user_role/{{ rid }}",
|
|
type: "get",
|
|
success: function (ret) {
|
|
tree.setChecked("user_role", ret.data);
|
|
},
|
|
});
|
|
},
|
|
});
|
|
|
|
function get_id(list_tree_data) {
|
|
if (Array.isArray(list_tree_data)) {
|
|
let ret = [];
|
|
$.each(list_tree_data, function (index, item) {
|
|
if (item?.children) {
|
|
ret.push(...get_id(item.children));
|
|
}
|
|
ret.push(...get_id(item));
|
|
});
|
|
return ret;
|
|
} else {
|
|
return [list_tree_data.id];
|
|
}
|
|
}
|
|
|
|
form.on("submit(role-rights-save)", function (data) {
|
|
let param = tree.getChecked("user_role"); // 获取选中节点的数据
|
|
let rights_ids = get_id(param).join();
|
|
$.ajax({
|
|
url: "/api/v1/user/user_role/{{ rid }}",
|
|
data: JSON.stringify({ rights_ids: rights_ids }),
|
|
dataType: "json",
|
|
contentType: "application/json",
|
|
type: "put",
|
|
success: function (result) {
|
|
if (result.code === 0) {
|
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
|
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
|
});
|
|
} else {
|
|
layer.msg(result.message, { icon: 2, time: 1000 });
|
|
}
|
|
},
|
|
});
|
|
return false;
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|