Files
zhgh_zjvtit/target/classes/views/platform/sys/role/index.html
T
2026-08-26 14:25:17 +08:00

1134 lines
50 KiB
HTML

<!--#
layout("/layouts/platform.html"){
#-->
<style>
.highlight {
background-color: yellow;
font-weight: bold;
padding: 1px 2px;
border-radius: 2px;
}
/* 关联用户弹窗固定占用可视区域,数据过多时仅表格内部滚动。 */
.role-user-dialog {
display: flex;
flex-direction: column;
height: 90vh;
margin-bottom: 0;
overflow: hidden;
}
.role-user-dialog .el-dialog__header {
flex: 0 0 auto;
padding: 22px 30px 18px;
border-bottom: 1px solid #ebeef5;
}
.role-user-dialog .el-dialog__title {
color: #1f2d3d;
font-size: 18px;
font-weight: 600;
}
.role-user-dialog .el-dialog__body {
flex: 1 1 auto;
min-height: 0;
padding: 8px 30px 12px;
overflow: hidden;
}
.role-user-dialog .el-dialog__footer {
flex: 0 0 auto;
padding: 14px 30px 18px;
border-top: 1px solid #ebeef5;
}
.role-user-layout {
display: flex;
flex-direction: column;
height: 100%;
min-height: 0;
overflow: hidden;
}
.role-user-tip {
flex: 0 0 auto;
padding: 13px 16px;
color: #1677ff;
background: #f0f7ff;
border-radius: 4px;
}
.role-user-tip i {
margin-right: 8px;
}
.role-user-toolbar {
display: flex;
flex: 0 0 auto;
align-items: center;
gap: 12px;
margin: 16px 0;
}
.role-user-add-area,
.role-user-search-area {
display: flex;
align-items: center;
gap: 8px;
}
.role-user-remove-button {
margin-left: auto;
}
.role-user-table-wrap {
flex: 1 1 auto;
min-height: 0;
overflow: hidden;
}
.role-user-pagination {
flex: 0 0 auto;
margin-top: 16px;
}
.role-user-status-dot {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
border-radius: 50%;
}
.role-user-status-dot.is-success {
background: #21c77a;
}
.role-user-status-dot.is-danger {
background: #f56c6c;
}
/* 角色管理列表固定占满平台内容区,避免页面主体出现纵向滚动条。 */
#app .role-manage-page {
display: flex;
flex-direction: column;
height: calc(100vh - 82px);
min-height: 0;
overflow: hidden;
}
#app .role-manage-query-card {
flex: 0 0 auto;
}
#app .role-manage-list-card {
flex: 1 1 auto;
min-height: 0;
overflow: hidden;
}
#app .role-manage-list-card > .el-card__body {
box-sizing: border-box;
display: flex;
flex-direction: column;
height: 100%;
min-height: 0;
overflow: hidden;
}
#app .role-manage-list-card .el-pagination-container {
flex: 0 0 auto;
}
</style>
<div id="app" v-cloak>
<div class="role-manage-page">
<el-card class="role-manage-query-card" shadow="never">
<el-row type="flex" style="column-gap: 10px">
<el-select v-model="pageForm.moduleId" style="width: 180px" filterable clearable
placeholder="请选择所属模块">
<el-option v-for="item in moduleOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
<el-input placeholder="请输入内容" v-model="pageForm.searchKeyword" style="width: 300px"
@keyup.enter.native="doSearch">
<el-select v-model="pageForm.searchName" slot="prepend" placeholder="查询类型" style="width: 120px">
<el-option label="角色名称" value="`name`"></el-option>
<el-option label="角色标识" value="`code`"></el-option>
</el-select>
</el-input>
<el-input placeholder="请输入内容" v-model="pageForm.searchKeyword2" @keyup.enter.native="doSearch"
style="width: 300px">
<el-select v-model="pageForm.searchName2" slot="prepend" placeholder="查询类型" style="width: 80px">
<el-option label="姓名" value="username"></el-option>
<el-option label="工号" value="loginname"></el-option>
</el-select>
</el-input>
<el-button icon="el-icon-search" @click="doSearch" type="primary"></el-button>
<div style="margin-left: auto">
<el-button size="medium" @click="openAdd" type="primary">
<i class="ti-plus"></i>
新建角色
</el-button>
<el-button @click="$refs.sortRef.onOpen()" size="medium" type="primary" icon="el-icon-sort">排序
</el-button>
</div>
</el-row>
<!-- <div class="pull-right offscreen-right mt5 ml5">-->
<!-- <el-button size="medium" @click="doSettingMemberRole" type="primary"><i class="el-icon-s-tools"></i>-->
<!-- 一键设会员角色-->
<!-- </el-button>-->
<!-- </div>-->
<!-- <div class="pull-right offscreen-right mt5 ml5">-->
<!-- <el-button size="medium" @click="doPublic" type="primary">一键设置公共角色</el-button>-->
<!-- </div>-->
<!-- <div class="pull-right offscreen-right mt5 ml5">-->
<!-- <el-button size="medium" @click="openAdd" type="primary"><i class="ti-plus"></i> 新建角色</el-button>-->
<!-- </div>-->
<!-- <div class="pull-right offscreen-right mt5">-->
<!-- <el-button size="medium" @click="exportRoles" type="primary"><i class="el-icon-download"></i> 导出角色-->
<!-- </el-button>-->
<!-- </div>-->
</el-card>
<el-card shadow="never" class="mt10 role-manage-list-card">
<el-table
:data="tableData"
ref="roleTableRef"
:height="roleTableHeight"
@sort-change="pageOrder"
header-align="center"
:default-sort="{prop: 'serialNumber', order: 'ascending'}"
style="width: 100%"
>
<el-table-column sortable type="index" :index="indexMethod" label="序号" width="100px"
align="center"></el-table-column>
<el-table-column sortable prop="name" label="角色名称" align="center"></el-table-column>
<el-table-column sortable prop="sort" label="排序编号" align="center"></el-table-column>
<el-table-column prop="code" sortable label="角色标识" align="center"
:show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="moduleName" label="所属模块" align="center" :show-overflow-tooltip="true">
</el-table-column>
<el-table-column sortable prop="disabled" label="启用状态" align="center" :show-overflow-tooltip="true">
<template slot-scope="scope">
<i v-if="scope.row.disabled" class="fa fa-circle text-danger ml5"></i>
<i v-if="!scope.row.disabled" class="fa fa-circle text-success ml5"></i>
</template>
</el-table-column>
<el-table-column prop="useronline" label="操作" width="120">
<template slot-scope="scope">
<el-dropdown @command="dropdownCommand">
<el-button size="mini">
<i class="ti-settings"></i>
<span class="ti-angle-down"></span>
</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="{type:'role',id:scope.row.id,name:scope.row.name}">
查看系统权限
</el-dropdown-item>
<el-dropdown-item :command="{type:'menu',id:scope.row.id,name:scope.row.name}">
分配PC系统权限
</el-dropdown-item>
<el-dropdown-item :command="{type:'h5_menu',id:scope.row.id,name:scope.row.name}">
分配H5系统权限
</el-dropdown-item>
<el-dropdown-item :command="{type:'user',id:scope.row.id,name:scope.row.name}">关联用户
</el-dropdown-item>
<el-dropdown-item divided
:command="{type:'enable',id:scope.row.id,name:scope.row.name,row:scope.row}">
启用
</el-dropdown-item>
<el-dropdown-item
:command="{type:'disable',id:scope.row.id,name:scope.row.name,row:scope.row}">禁用
</el-dropdown-item>
<el-dropdown-item divided :command="{type:'edit',id:scope.row.id}">修改</el-dropdown-item>
<el-dropdown-item
:command="{type:'delete',id:scope.row.id,name:scope.row.name}"
v-if="scope.row.code!='superadmin'&&scope.row.code!='public'"
>
删除
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
<!--#include("/layouts/pagination.html"){}#-->
</el-card>
</div>
<el-dialog append-to-body title="新建角色" :visible.sync="addDialogVisible" :close-on-click-modal="false"
width="70%">
<el-form :model="formData" ref="addForm" :rules="formRules" size="small" label-width="80px">
<el-form-item prop="moduleId" label="所属模块">
<el-select v-model="formData.moduleId" style="width: 100%" filterable placeholder="请选择所属模块">
<el-option v-for="item in moduleOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
</el-form-item>
<el-form-item prop="name" label="角色名称">
<el-input maxlength="50" placeholder="角色名称" v-model="formData.name" auto-complete="off" tabindex="2"
type="text"></el-input>
</el-form-item>
<el-form-item prop="code" label="角色标识">
<el-input maxlength="150" placeholder="角色标识" v-model="formData.code" auto-complete="off"
tabindex="3" type="text"></el-input>
</el-form-item>
<el-form-item prop="sort" label="排序编号">
<el-input-number placeholder="排序编号" v-model="formData.sort"></el-input-number>
</el-form-item>
<el-form-item prop="disabled" label="启用状态">
<el-switch v-model="formData.disabled" active-color="#ff4949" inactive-color="#13ce66"></el-switch>
</el-form-item>
<!-- <el-form-item prop="" label="分配权限">-->
<!-- <el-row style="margin-bottom: 3px">-->
<!-- <el-button size="small" @click="addRoleSelAll">全选</el-button>-->
<!-- <el-button size="small" @click="addRoleSelClear">清空</el-button>-->
<!-- </el-row>-->
<!-- <el-tree ref="addMenuTree" :data="addMenuData" show-checkbox check-strictly node-key="id" :props="defaultProps">-->
<!-- <span class="custom-tree-node" slot-scope="scope">-->
<!-- <span>{{ scope.node.label }}</span>-->
<!-- <span>-->
<!-- <span v-if="scope.data.type=='menu'" style="font-weight: bold">菜单权限</span>-->
<!-- <span v-if="scope.data.type=='data'">数据权限</span>-->
<!-- </span>-->
<!-- </span>-->
<!-- </el-tree>-->
<!-- </el-form-item>-->
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="addDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="doAdd">确 定</el-button>
</span>
</el-dialog>
<el-dialog append-to-body title="修改角色" :visible.sync="editDialogVisible" :close-on-click-modal="false"
width="40%">
<el-form :model="formData" ref="editForm" :rules="formRules" size="small" label-width="80px">
<el-form-item prop="name" label="角色名称">
<el-input maxlength="50" placeholder="角色名称" v-model="formData.name" auto-complete="off" tabindex="2"
type="text"></el-input>
</el-form-item>
<el-form-item prop="code" label="角色标识">
<el-input maxlength="150" placeholder="角色标识" v-model="formData.code" auto-complete="off"
tabindex="3" type="text"></el-input>
</el-form-item>
<el-form-item prop="moduleId" label="所属模块">
<el-select v-model="formData.moduleId" style="width: 100%" filterable placeholder="请选择所属模块">
<el-option v-for="item in moduleOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
</el-form-item>
<el-form-item prop="sort" label="排序编号">
<el-input-number placeholder="排序编号" v-model="formData.sort"></el-input-number>
</el-form-item>
<el-form-item prop="disabled" label="启用状态">
<el-switch v-model="formData.disabled" active-color="#ff4949" inactive-color="#13ce66"></el-switch>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="editDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="doEdit">确 定</el-button>
</span>
</el-dialog>
<el-dialog :title="roleDialogTitle" :visible.sync="roleDialogVisible" width="70%">
<el-table :data="roleTableData" style="width: 100%" size="small" :highlight-current-row="true" row-key="id" lazy
:load="loadRoleChild">
<el-table-column
label="菜单名称"
header-align="center"
prop="name"
width="200"
:show-overflow-tooltip="true"
align="left"
></el-table-column>
<el-table-column label="URL" header-align="center" prop="href"
:show-overflow-tooltip="true"></el-table-column>
<el-table-column label="资源类型" header-align="center" prop="type" :show-overflow-tooltip="true"
align="center">
<template slot-scope="scope">
<i v-if="scope.row.type=='menu'" style="font-weight: bold">菜单</i>
<i v-if="scope.row.type=='data'">数据</i>
</template>
</el-table-column>
<el-table-column label="权限标识" header-align="center" prop="permission"
:show-overflow-tooltip="true"></el-table-column>
</el-table>
<span slot="footer" class="dialog-footer">
<el-button @click="roleDialogVisible = false">关 闭</el-button>
</span>
</el-dialog>
<el-dialog append-to-body :title="menuDialogTitle" :visible.sync="menuDialogVisible" :close-on-click-modal="false"
width="70%">
<!-- 搜索框 -->
<el-row style="margin-bottom: 10px">
<el-input
v-model="searchText"
placeholder="请输入权限名称"
size="small"
clearable
style="width: 300px"
@input="handleSearch"
>
<i slot="prefix" class="el-input__icon el-icon-search"></i>
</el-input>
</el-row>
<el-row style="margin-bottom: 3px">
<el-button size="small" @click="menuRoleSelAll">全选</el-button>
<el-button size="small" @click="menuRoleSelClear">清空</el-button>
</el-row>
<!-- :data="doMenuData"-->
<el-tree
ref="doMenuTree"
:data="doMenuData"
:default-checked-keys="doMenuCheckedData"
check-strictly
show-checkbox
node-key="id"
check-strictly
:props="defaultProps"
:filter-node-method="filterNode"
@check="handleMenuCheck"
>
<span class="custom-tree-node" slot-scope="{ node, data }">
<span v-html="getDisplayText(node, data)"></span>
<span>
<span v-if="data.type=='menu'" style="font-weight: bold; color: #409EFF;">菜单权限</span>
<span v-if="data.type=='data'" style="color: #67C23A;">数据权限</span>
</span>
</span>
</el-tree>
<span slot="footer" class="dialog-footer">
<el-button @click="menuDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="doMenu">确 定</el-button>
</span>
</el-dialog>
<el-dialog append-to-body :title="userDialogTitle" :visible.sync="userDialogVisible" :close-on-click-modal="false"
custom-class="role-user-dialog" top="5vh" width="82%" @opened="updateUserTableHeight">
<div class="role-user-layout">
<div class="role-user-toolbar">
<div class="role-user-add-area">
<el-select
size="small"
style="width: 360px"
v-model="selUsers"
multiple
filterable
remote
default-first-option
reserve-keyword
:remote-method="remoteMethod"
:loading="loading"
placeholder="请输入用户工号或姓名"
>
<el-option v-for="item in dbUsers" :key="item.value" :label="item.label"
:value="item.value"></el-option>
</el-select>
<el-button size="small" type="primary" plain icon="el-icon-circle-plus-outline"
@click="userAddRole">将用户加入角色</el-button>
</div>
<div class="role-user-search-area">
<el-input v-model="userForm.searchKeyword" clearable size="small" style="width: 280px"
placeholder="请输入查询内容" @clear="doUserSearch"
@keyup.enter.native="doUserSearch">
<el-select v-model="userForm.searchName" slot="prepend" style="width: 100px">
<el-option label="工号" value="loginname"></el-option>
<el-option label="姓名" value="username"></el-option>
</el-select>
</el-input>
<el-button size="small" type="primary" icon="el-icon-search" @click="doUserSearch">查询</el-button>
</div>
<el-button class="role-user-remove-button" size="small" type="danger" plain
icon="el-icon-delete" @click="userDelRole">从角色中移除</el-button>
</div>
<div class="role-user-table-wrap">
<el-table
ref="userTableRef"
:data="userTableData"
:height="userTableHeight"
@sort-change="userPageOrder"
size="small"
border
header-align="center"
style="width: 100%"
@selection-change="userSelectionChange"
>
<el-table-column type="selection" width="55" align="center"></el-table-column>
<el-table-column sortable prop="loginname" label="用户工号" header-align="center" align="center"></el-table-column>
<el-table-column prop="username" label="姓名" header-align="center" align="center"
:show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="unitname" label="所属单位" header-align="center" align="center"
:show-overflow-tooltip="true"></el-table-column>
<el-table-column sortable prop="disabled" label="账号状态" header-align="center" align="center"
:show-overflow-tooltip="true">
<template slot-scope="scope">
<span class="role-user-status-dot" :class="scope.row.disabled ? 'is-danger' : 'is-success'"></span>
<span>{{ scope.row.disabled ? '禁用' : '正常' }}</span>
</template>
</el-table-column>
<el-table-column sortable prop="useronline" label="在线状态" header-align="center" align="center"
:show-overflow-tooltip="true">
<template slot-scope="scope">
<span :class="scope.row.useronline ? 'text-success' : 'text-danger'">
{{ scope.row.useronline ? '在线' : '离线' }}
</span>
</template>
</el-table-column>
</el-table>
</div>
<el-pagination
class="role-user-pagination"
@size-change="userPageSizeChange"
@current-change="userPageNumberChange"
:current-page="userForm.pageNumber"
:page-sizes="[10, 20, 30, 50]"
:page-size="userForm.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="userForm.totalCount"
></el-pagination>
</div>
</el-dialog>
<sort ref="sortRef" @refresh="doSearch"></sort>
</div>
<script nonce="${cspNonce!}">
<!--#include("sort.js"){}#-->
const vue = new Vue({
el: "#app",
dicts: ["SYS_MENU_PLATFORM"],
mixins: [initTableMixins],
components: {
sort: sort_component
},
data() {
const self = this
const validateName = function (rule, value, callback) {
const regex = new RegExp("^[a-zA-Z][a-zA-Z0-9_]{1,100}$")
if (!regex.test(value)) {
callback(new Error("角色标识以字母开头2-100字,允许使用字母/数字/下划线"))
} else {
callback()
}
}
const validateUnit = function (rule, value, callback) {
if (
self.parentUnit.length < 1 ||
self.parentUnit[self.parentUnit.length - 1] === "" ||
self.parentUnit[self.parentUnit.length - 1] === "root"
) {
callback(new Error("请选择所属单位!"))
} else {
callback()
}
}
return {
addDialogVisible: false,
editDialogVisible: false,
roleDialogVisible: false,
menuDialogVisible: false,
userDialogVisible: false,
treeData: {
label: "name",
children: "zones",
id: "id",
isLeaf: "leaf"
},
tableData: [],
roleTableHeight: 300,
roleTableResizeObserver: null,
roleTableResizeHandler: null,
moduleOptions: [],
options: [],
parentUnit: [],
parentUnitSearch: [],
pageForm: {
searchUnit: "",
searchName: "`name`",
searchKeyword: "",
searchName2: "username",
searchKeyword2: "",
moduleId: "",
pageNumber: 1,
pageSize: 10,
totalCount: 0,
pageOrderName: "",
pageOrderBy: ""
},
formData: {
id: "",
unitid: "",
moduleId: "",
disabled: false,
menuIds: ""
},
formRules: {
// parentUnit: [{ validator: validateUnit, trigger: ["blur", "change"] }],
name: [{required: true, message: "角色名称", trigger: ["blur", "change"]}],
code: [
{required: true, message: "角色标识", trigger: ["blur", "change"]},
{validator: validateName, trigger: ["blur", "change"]}
],
moduleId: [{required: true, message: "所属模块必填", trigger: ["blur", "change"]}]
},
editRules: {
// parentUnit: [{ validator: validateUnit, trigger: ["blur", "change"] }],
name: [{required: true, message: "角色名称", trigger: ["blur", "change"]}],
code: [
{required: true, message: "角色标识", trigger: ["blur", "change"]},
{validator: validateName, trigger: ["blur", "change"]}
]
},
roleDialogTitle: "查看角色权限",
menuDialogTitle: "分配角色菜单",
userDialogTitle: "分配用户",
roleTableData: [], //treeTable后台取出的数据
roleId: "", //当前角色ID
defaultProps: {
children: "children",
label: "label"
},
addMenuData: [],
doMenuData: [],
doMenuCheckedData: [], //已分配的权限选中状态
menuCheckedMap: {}, //完整权限树的勾选状态,搜索隐藏节点时仍需保留
doCmsData: [],
doCmsCheckedData: [], //已分配的CMS权限
doCmsForm: {},
userForm: {
roleId: "",
searchName: "loginname",
searchKeyword: "",
pageNumber: 1,
pageSize: 10,
totalCount: 0,
pageOrderName: "",
pageOrderBy: ""
},
userTableData: [],
userTableHeight: 360,
loading: false,
dbUsers: [], //分配用户
selUsers: [], //分配选中的用户
userSelection: [],
props: {
lazy: true,
checkStrictly: true,
multiple: false,
lazyLoad: (node, resolve) => {
this.$axios.post("/platform/sys/unit/tree", {pid: node.value}).then((res) => {
if (res.code === 0) {
resolve(res.data)
}
})
}
},
platform: "",
// 分配权限搜索
searchText: ''
}
},
computed: {
// 根据第一级菜单名称过滤数据
filteredMenuData() {
if (!this.searchText.trim()) {
return this.doMenuData;
}
const searchText = this.searchText.toLowerCase();
return this.doMenuData.filter(item => {
return item.label.toLowerCase().includes(searchText);
});
}
},
methods: {
// 搜索处理
handleSearch(value) {
// 弹框初次渲染完成后再执行筛选,避免树实例尚未创建。
this.$nextTick(() => {
this.$refs.doMenuTree.filter(value)
})
},
// 更新单个权限的勾选状态,避免搜索隐藏的权限在保存时丢失。
handleMenuCheck(data, checked) {
const isChecked = checked.checkedKeys.indexOf(data.id) !== -1
this.$set(this.menuCheckedMap, data.id, isChecked)
},
// 过滤节点方法
filterNode(value, data) {
if (!value) return true;
return data.label.toLowerCase().indexOf(value.toLowerCase()) !== -1;
},
// 获取显示文本(只对第一级菜单高亮)
getDisplayText(node, data) {
const text = node.label;
// 判断是否为第一级菜单(没有父节点或父节点是根节点)
if (node.level === 1 && this.searchText) {
return this.highlightText(text);
}
return text;
},
// 高亮搜索文本
highlightText(text) {
if (!this.searchText || !text) {
return text;
}
const searchRegex = new RegExp('(' + this.searchText + ')', 'gi');
return text.replace(searchRegex, '<span class="highlight">$1</span>');
},
exportRoles() {
this.$downLoad.post(loc() + "/exportRoles?" + this.pageForm)
},
doPublic() {
this.$confirm("确定要把所有用户加入公共角色吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(async () => {
const loading = this.$loading({
lock: true,
text: "正在提交...",
spinner: "el-icon-loading"
})
const resp = await this.$axios.post(loc() + "/doPublic")
loading.close()
})
},
doSettingMemberRole() {
this.$confirm("是否确定一键设置会员角色?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(async () => {
const {code, msg} = await this.$axios.post("/platform/sys/role/doSettingMemberRole")
if (code === 0) {
this.$message.success(msg)
}
})
.catch(() => {
})
},
formatAt(val) {
if (val > 0) return moment(val).format("YYYY-MM-DD HH:mm")
return ""
},
doSearch() {
let unit = this.parentUnitSearch[this.parentUnitSearch.length - 1]
if ("root" === unit) {
unit = ""
}
this.pageForm.searchUnit = unit
this.pageForm.pageNumber = 1
this.pageData()
},
// 根据角色列表卡片的剩余空间设置表格高度,分页区域始终保持可见。
updateRoleTableHeight() {
this.$nextTick(() => {
const cardBody = this.$el.querySelector('.role-manage-list-card > .el-card__body')
if (!cardBody || cardBody.clientHeight <= 0) {
return
}
const pagination = cardBody.querySelector('.el-pagination-container')
const bodyStyle = window.getComputedStyle(cardBody)
const bodyPadding = (parseFloat(bodyStyle.paddingTop) || 0)
+ (parseFloat(bodyStyle.paddingBottom) || 0)
const paginationStyle = pagination ? window.getComputedStyle(pagination) : null
const paginationHeight = pagination
? pagination.offsetHeight
+ (parseFloat(paginationStyle.marginTop) || 0)
+ (parseFloat(paginationStyle.marginBottom) || 0)
: 0
this.roleTableHeight = Math.max(1, Math.floor(cardBody.clientHeight - bodyPadding - paginationHeight))
this.$nextTick(() => {
if (this.$refs.roleTableRef) {
this.$refs.roleTableRef.doLayout()
}
})
})
},
// 加载可选 PC 模块,创建、编辑和列表筛选共用同一数据源。
loadModuleOptions() {
this.$axios.post("/platform/sys/role/listModule").then((res) => {
if (res.code === 0) {
this.$set(this, "moduleOptions", res.data)
}
})
},
addMenuLoad() {
this.$axios.post("/platform/sys/role/menuAll/", {}).then((res) => {
if (res.code === 0) {
this.addMenuData = res.data
}
})
},
doMenuLoad() {
this.$axios.post("/platform/sys/role/menuRole/" + this.roleId + "/" + this.platform, {}).then((res) => {
if (res.code === 0) {
const menuCheckedMap = {}
res.data.cmenu.forEach((menuId) => {
menuCheckedMap[menuId] = true
})
this.$set(this, "doMenuData", res.data.menu)
this.$set(this, "doMenuCheckedData", res.data.cmenu)
this.$set(this, "menuCheckedMap", menuCheckedMap)
// 权限树数据刷新后清空上次搜索产生的筛选状态。
this.handleSearch(this.searchText)
}
})
},
userSelectionChange(val) {
this.userSelection = val
},
userPageOrder(column) {
//按字段排序
this.userForm.pageOrderName = column.prop
this.userForm.pageOrderBy = column.order
this.doUserLoad()
},
userPageNumberChange: function (val) {
//页码更新操作
this.userForm.pageNumber = val
this.doUserLoad()
},
userPageSizeChange: function (val) {
//分页大小更新操作
this.userForm.pageSize = val
this.doUserLoad()
},
// 查询当前角色已关联用户,查询时从第一页重新加载。
doUserSearch() {
this.userForm.pageNumber = 1
this.doUserLoad()
},
// 根据弹窗内表格容器的剩余空间计算高度,确保仅表格内部产生滚动条。
updateUserTableHeight() {
this.$nextTick(() => {
const tableWrap = document.querySelector('.role-user-dialog .role-user-table-wrap')
if (!tableWrap || tableWrap.clientHeight <= 0) {
return
}
this.userTableHeight = Math.max(180, Math.floor(tableWrap.clientHeight))
this.$nextTick(() => {
if (this.$refs.userTableRef) {
this.$refs.userTableRef.doLayout()
}
})
})
},
remoteMethod(query) {
if (query !== "") {
this.loading = true
this.$axios
.post("/platform/sys/role/userSearch", {
query: query,
roleId: this.roleId
})
.then((res) => {
if (res.code === 0) {
this.dbUsers = res.data.list
}
this.loading = false
})
} else {
this.selUsers = []
}
},
doUserLoad() {
this.$axios.post("/platform/sys/role/user", this.userForm).then((res) => {
if (res.code === 0) {
this.userTableData = res.data.list
this.userForm.totalCount = res.data.totalCount
}
})
},
openAdd() {
this.addDialogVisible = true
this.formData = {} //打开新增窗口,表单先清空
if (this.$refs["addForm"]) this.$refs["addForm"].resetFields()
this.addMenuLoad()
},
doAdd() {
this.$refs["addForm"].validate((valid) => {
if (valid) {
// this.formData.menuIds = this.$refs["addMenuTree"].getCheckedKeys().toString()
// this.formData.unitid = this.parentUnit[this.parentUnit.length - 1] || ""
this.$axios.post("/platform/sys/role/addDo", this.formData).then((res) => {
if (res.code === 0) {
this.$message.success(res.msg)
this.parentUnitSearch = []
this.doSearch()
this.addDialogVisible = false
}
})
}
})
},
doEdit() {
this.$refs["editForm"].validate((valid) => {
if (valid) {
this.$axios.post("/platform/sys/role/editDo", this.formData).then((res) => {
if (res.code === 0) {
this.$message.success(res.msg)
this.doSearch()
this.editDialogVisible = false
}
})
}
})
},
doMenu() {
// if (this.searchText) {
// this.$message.warning('请清空搜索条件后再提交')
// return;
// }
// 从完整权限树的状态中组装提交数据,搜索隐藏节点不会被遗漏。
const allMenuIds = []
this.getTreeAllIds(allMenuIds, this.doMenuData)
const ids = allMenuIds.filter((menuId) => this.menuCheckedMap[menuId])
if (!ids || ids.length === 0) {
this.$message.warning("请选择菜单或数据权限")
return
}
const loading = this.$loading({
lock: true,
text: "正在提交...",
spinner: "el-icon-loading"
})
this.$axios
.post("/platform/sys/role/menuDo", {
roleId: this.roleId,
platform: this.platform,
menuIds: ids.toString()
})
.then((res) => {
if (res.code === 0) {
this.$message.success(res.msg)
this.menuDialogVisible = false
}
loading.close()
})
},
initRoleTreeTable() {
this.$axios.post("/platform/sys/role/menu/" + this.roleId, {pid: ""}).then((res) => {
if (res.code === 0) {
this.roleTableData = res.data
}
})
},
loadRoleChild(tree, treeNode, resolve) {
this.$axios.post("/platform/sys/role/menu/" + this.roleId, {pid: tree.id}).then((res) => {
if (res.code === 0) {
resolve(res.data)
}
})
},
dropdownCommand(command) {
//监听下拉框事件
if ("role" === command.type) {
this.roleDialogVisible = true
this.roleDialogTitle = "查看角色 【" + command.name + "】 的权限"
this.roleId = command.id
this.initRoleTreeTable()
}
if ("menu" === command.type) {
this.menuDialogTitle = "分配角色 【" + command.name + "】 的PC端权限"
this.menuDialogVisible = true
this.platform = "PC"
this.roleId = command.id
this.$set(this, "searchText", "")
this.doMenuLoad()
}
if ("h5_menu" === command.type) {
this.menuDialogTitle = "分配角色 【" + command.name + "】 的H5端权限"
this.menuDialogVisible = true
this.platform = "H5"
this.roleId = command.id
this.$set(this, "searchText", "")
this.doMenuLoad()
}
if ("user" === command.type) {
this.userDialogTitle = "分配角色 【" + command.name + "】 的用户"
this.userDialogVisible = true
this.roleId = command.id
this.userForm.roleId = command.id
this.userForm.pageNumber = 1
this.doUserLoad()
}
if ("enable" === command.type || "disable" === command.type) {
this.$axios.post("/platform/sys/role/" + command.type + "/" + command.id, {}).then((res) => {
if (res.code === 0) {
this.$message.success(res.msg)
if ("disabled" === command.type) {
command.row.disabled = true
}
if ("enable" === command.type) {
command.row.disabled = false
}
}
})
}
if ("edit" === command.type) {
this.$axios.post("/platform/sys/role/edit/" + command.id, {}).then((res) => {
if (res.code === 0) {
this.formData = res.data
this.editDialogVisible = true
}
})
}
if ("delete" === command.type) {
this.$confirm("此操作将删除 " + command.name, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
this.$axios.post("/platform/sys/role/delete/" + command.id, {}).then((res) => {
if (res.code === 0) {
this.$message.success(res.msg)
this.doSearch()
}
})
})
}
},
userAddRole() {
if (this.selUsers.length === 0) {
this.$message.warning("请选择用户")
return
}
this.$axios
.post("/platform/sys/role/usersAdd", {
roleId: this.roleId,
users: this.selUsers.toString()
})
.then((res) => {
if (res.code === 0) {
this.$message.success(res.msg)
this.selUsers = [] //清除已选择的用户
this.dbUsers = [] //清除数据库查询的用户,已添加到角色的用户不应该还存在so..
this.doUserLoad()
}
})
},
userDelRole() {
if (this.userSelection.length === 0) {
this.$message.warning("请选择用户")
return
}
const users = this.userSelection.map((user) => user.id)
this.$axios
.post("/platform/sys/role/usersDel", {
roleId: this.roleId,
users: users.toString()
})
.then((res) => {
if (res.code === 0) {
this.$message.success(res.msg)
this.selUsers = [] //清除已选择的用户
this.dbUsers = [] //清除数据库查询的用户,已添加到角色的用户不应该还存在so..
this.doUserLoad()
}
})
},
getTreeAllIds(ids, obj) {
const self = this
if (obj && obj.length > 0) {
obj.forEach(function (o) {
ids.push(o.id)
if (o.children) {
self.getTreeAllIds(ids, o.children)
}
})
}
},
addRoleSelAll() {
const ids = []
this.getTreeAllIds(ids, this.addMenuData)
this.$refs["addMenuTree"].setCheckedKeys(ids)
},
addRoleSelClear() {
this.$refs["addMenuTree"].setCheckedKeys([])
},
menuRoleSelAll() {
const ids = []
this.getTreeAllIds(ids, this.doMenuData)
const menuCheckedMap = {}
ids.forEach((menuId) => {
menuCheckedMap[menuId] = true
})
this.$set(this, "menuCheckedMap", menuCheckedMap)
this.$refs["doMenuTree"].setCheckedKeys(ids)
},
menuRoleSelClear() {
this.$set(this, "menuCheckedMap", {})
this.$refs["doMenuTree"].setCheckedKeys([])
},
clearButtons(list) {
for (let o of list) {
this.$set(o, "buttons", [])
if (o.hasChildren) {
this.clearButtons(o.children)
}
}
},
selParentChannel(list, pid, keys) {
const self = this
list.forEach(function (o) {
if (pid === o.id) {
keys.push(pid)
}
if (o.children) {
self.selParentChannel(o.children, pid, keys)
}
})
}
// async getMenuOptions() {
// const { data } = await $.get(loc() + "/getMenuOptions")
// this.menuOptions = data
// }
},
created() {
this.loadModuleOptions()
this.pageData()
// await this.getMenuOptions()
},
mounted() {
this.updateRoleTableHeight()
window.addEventListener("resize", this.updateUserTableHeight)
const page = this.$el.querySelector('.role-manage-page')
if (window.ResizeObserver && page) {
this.roleTableResizeObserver = new ResizeObserver(() => {
this.updateRoleTableHeight()
})
this.roleTableResizeObserver.observe(page)
} else {
this.roleTableResizeHandler = () => {
this.updateRoleTableHeight()
}
window.addEventListener("resize", this.roleTableResizeHandler)
}
},
beforeDestroy() {
window.removeEventListener("resize", this.updateUserTableHeight)
if (this.roleTableResizeObserver) {
this.roleTableResizeObserver.disconnect()
}
if (this.roleTableResizeHandler) {
window.removeEventListener("resize", this.roleTableResizeHandler)
}
}
})
</script>
<style>
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
</style>
<!--#
}
#-->