2019-10-08 09:14:38 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div class="app-container">
|
2020-08-01 15:45:38 +08:00
|
|
|
|
<el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<el-form-item label="角色名称" prop="name">
|
2019-10-08 09:14:38 +08:00
|
|
|
|
<el-input
|
2021-01-09 13:32:27 +08:00
|
|
|
|
v-model="queryParams.name"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
placeholder="请输入角色名称"
|
|
|
|
|
clearable
|
|
|
|
|
size="small"
|
|
|
|
|
style="width: 240px"
|
|
|
|
|
@keyup.enter.native="handleQuery"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<el-form-item label="角色标识" prop="code">
|
2019-10-08 09:14:38 +08:00
|
|
|
|
<el-input
|
2021-01-09 13:32:27 +08:00
|
|
|
|
v-model="queryParams.code"
|
|
|
|
|
placeholder="请输入角色标识"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
clearable
|
|
|
|
|
size="small"
|
|
|
|
|
style="width: 240px"
|
|
|
|
|
@keyup.enter.native="handleQuery"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
2019-11-11 08:59:15 +08:00
|
|
|
|
<el-form-item label="状态" prop="status">
|
2019-10-08 09:14:38 +08:00
|
|
|
|
<el-select
|
|
|
|
|
v-model="queryParams.status"
|
|
|
|
|
placeholder="角色状态"
|
|
|
|
|
clearable
|
|
|
|
|
size="small"
|
|
|
|
|
style="width: 240px"
|
|
|
|
|
>
|
|
|
|
|
<el-option
|
2021-01-09 13:32:27 +08:00
|
|
|
|
v-for="dict in statusDictDatas"
|
|
|
|
|
:key="parseInt(dict.value)"
|
|
|
|
|
:label="dict.label"
|
|
|
|
|
:value="parseInt(dict.value)"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
/>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="创建时间">
|
|
|
|
|
<el-date-picker
|
|
|
|
|
v-model="dateRange"
|
|
|
|
|
size="small"
|
|
|
|
|
style="width: 240px"
|
|
|
|
|
value-format="yyyy-MM-dd"
|
|
|
|
|
type="daterange"
|
|
|
|
|
range-separator="-"
|
|
|
|
|
start-placeholder="开始日期"
|
|
|
|
|
end-placeholder="结束日期"
|
|
|
|
|
></el-date-picker>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item>
|
2020-08-01 15:45:38 +08:00
|
|
|
|
<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
2019-11-11 08:59:15 +08:00
|
|
|
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
<el-row :gutter="10" class="mb8">
|
|
|
|
|
<el-col :span="1.5">
|
2019-10-08 09:14:38 +08:00
|
|
|
|
<el-button
|
|
|
|
|
type="primary"
|
|
|
|
|
icon="el-icon-plus"
|
|
|
|
|
size="mini"
|
|
|
|
|
@click="handleAdd"
|
|
|
|
|
v-hasPermi="['system:role:add']"
|
|
|
|
|
>新增</el-button>
|
2019-11-11 08:59:15 +08:00
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="1.5">
|
|
|
|
|
<el-button
|
|
|
|
|
type="warning"
|
|
|
|
|
icon="el-icon-download"
|
|
|
|
|
size="mini"
|
|
|
|
|
@click="handleExport"
|
2020-07-29 21:16:53 +08:00
|
|
|
|
v-hasPermi="['system:role:export']"
|
2019-11-11 08:59:15 +08:00
|
|
|
|
>导出</el-button>
|
|
|
|
|
</el-col>
|
2020-08-10 10:12:39 +08:00
|
|
|
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
2019-11-11 08:59:15 +08:00
|
|
|
|
</el-row>
|
2019-10-08 09:14:38 +08:00
|
|
|
|
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<el-table v-loading="loading" :data="roleList">
|
|
|
|
|
<el-table-column label="角色编号" prop="id" width="120" />
|
|
|
|
|
<el-table-column label="角色名称" prop="name" :show-overflow-tooltip="true" width="150" />
|
|
|
|
|
<el-table-column label="角色标识" prop="code" :show-overflow-tooltip="true" width="150" />
|
|
|
|
|
<el-table-column label="角色类型" prop="type" :formatter="typeFormat" width="80"></el-table-column>
|
|
|
|
|
<el-table-column label="显示顺序" prop="sort" width="100" />
|
2019-11-11 08:59:15 +08:00
|
|
|
|
<el-table-column label="状态" align="center" width="100">
|
2019-10-08 09:14:38 +08:00
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-switch
|
|
|
|
|
v-model="scope.row.status"
|
2021-01-09 13:32:27 +08:00
|
|
|
|
:active-value="0"
|
|
|
|
|
:inactive-value="1"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
@change="handleStatusChange(scope.row)"
|
|
|
|
|
></el-switch>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
|
|
|
|
<template slot-scope="scope">
|
2019-10-09 17:21:43 +08:00
|
|
|
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
2019-10-08 09:14:38 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-button
|
|
|
|
|
size="mini"
|
|
|
|
|
type="text"
|
|
|
|
|
icon="el-icon-edit"
|
|
|
|
|
@click="handleUpdate(scope.row)"
|
|
|
|
|
v-hasPermi="['system:role:edit']"
|
|
|
|
|
>修改</el-button>
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<el-button
|
|
|
|
|
size="mini"
|
|
|
|
|
type="text"
|
|
|
|
|
icon="el-icon-circle-check"
|
|
|
|
|
@click="handleMenu(scope.row)"
|
2021-01-09 19:22:07 +08:00
|
|
|
|
v-hasPermi="['system:permission:assign-role-menu']"
|
2021-01-09 13:32:27 +08:00
|
|
|
|
>菜单权限</el-button>
|
2019-10-08 09:14:38 +08:00
|
|
|
|
<el-button
|
|
|
|
|
size="mini"
|
|
|
|
|
type="text"
|
|
|
|
|
icon="el-icon-circle-check"
|
|
|
|
|
@click="handleDataScope(scope.row)"
|
2021-01-09 19:22:07 +08:00
|
|
|
|
v-hasPermi="['system:permission:assign-role-data-scope']"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
>数据权限</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
size="mini"
|
|
|
|
|
type="text"
|
|
|
|
|
icon="el-icon-delete"
|
|
|
|
|
@click="handleDelete(scope.row)"
|
|
|
|
|
v-hasPermi="['system:role:remove']"
|
|
|
|
|
>删除</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
|
|
|
|
|
<pagination
|
|
|
|
|
v-show="total>0"
|
|
|
|
|
:total="total"
|
|
|
|
|
:page.sync="queryParams.pageNum"
|
|
|
|
|
:limit.sync="queryParams.pageSize"
|
|
|
|
|
@pagination="getList"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<!-- 添加或修改角色配置对话框 -->
|
2020-04-17 14:14:54 +08:00
|
|
|
|
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
2019-10-08 09:14:38 +08:00
|
|
|
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<el-form-item label="角色名称" prop="name">
|
|
|
|
|
<el-input v-model="form.name" placeholder="请输入角色名称" />
|
2019-10-08 09:14:38 +08:00
|
|
|
|
</el-form-item>
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<el-form-item label="角色标识" prop="code">
|
|
|
|
|
<el-input v-model="form.code" placeholder="请输入角色标识" />
|
2019-10-08 09:14:38 +08:00
|
|
|
|
</el-form-item>
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<el-form-item label="角色顺序" prop="sort">
|
|
|
|
|
<el-input-number v-model="form.sort" controls-position="right" :min="0" />
|
2019-10-08 09:14:38 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="备注">
|
|
|
|
|
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
|
|
|
<el-button @click="cancel">取 消</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<!-- 分配角色的数据权限对话框 -->
|
2021-01-09 22:00:22 +08:00
|
|
|
|
<el-dialog title="分配数据权限" :visible.sync="openDataScope" width="500px" append-to-body>
|
2019-10-08 09:14:38 +08:00
|
|
|
|
<el-form :model="form" label-width="80px">
|
|
|
|
|
<el-form-item label="角色名称">
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<el-input v-model="form.name" :disabled="true" />
|
2019-10-08 09:14:38 +08:00
|
|
|
|
</el-form-item>
|
2021-01-09 13:32:27 +08:00
|
|
|
|
<el-form-item label="角色标识">
|
|
|
|
|
<el-input v-model="form.code" :disabled="true" />
|
2019-10-08 09:14:38 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="权限范围">
|
|
|
|
|
<el-select v-model="form.dataScope">
|
|
|
|
|
<el-option
|
2021-01-09 22:00:22 +08:00
|
|
|
|
v-for="item in dataScopeDictDatas"
|
|
|
|
|
:key="parseInt(item.value)"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
:label="item.label"
|
2021-01-09 22:00:22 +08:00
|
|
|
|
:value="parseInt(item.value)"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
></el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
2021-01-09 22:00:22 +08:00
|
|
|
|
<el-form-item label="数据权限" v-show="form.dataScope === SysDataScopeEnum.DEPT_CUSTOM">
|
|
|
|
|
<el-checkbox v-model="!form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动(选中父节点,自动选择子节点)</el-checkbox>
|
2020-09-19 13:42:37 +08:00
|
|
|
|
<el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠</el-checkbox>
|
|
|
|
|
<el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox>
|
2019-10-08 09:14:38 +08:00
|
|
|
|
<el-tree
|
2020-09-19 13:42:37 +08:00
|
|
|
|
class="tree-border"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
:data="deptOptions"
|
|
|
|
|
show-checkbox
|
|
|
|
|
default-expand-all
|
|
|
|
|
ref="dept"
|
|
|
|
|
node-key="id"
|
2021-01-09 18:53:43 +08:00
|
|
|
|
:check-strictly="form.deptCheckStrictly"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
empty-text="加载中,请稍后"
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
></el-tree>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button type="primary" @click="submitDataScope">确 定</el-button>
|
|
|
|
|
<el-button @click="cancelDataScope">取 消</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
2021-01-09 13:32:27 +08:00
|
|
|
|
|
|
|
|
|
<!-- 分配角色的菜单权限对话框 -->
|
|
|
|
|
<el-dialog :title="title" :visible.sync="openMenu" width="500px" append-to-body>
|
|
|
|
|
<el-form :model="form" label-width="80px">
|
|
|
|
|
<el-form-item label="角色名称">
|
|
|
|
|
<el-input v-model="form.name" :disabled="true" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="角色标识">
|
|
|
|
|
<el-input v-model="form.code" :disabled="true" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="菜单权限">
|
|
|
|
|
<el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
|
|
|
|
|
<el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
|
|
|
|
|
<el-tree
|
|
|
|
|
class="tree-border"
|
|
|
|
|
:data="menuOptions"
|
|
|
|
|
show-checkbox
|
|
|
|
|
ref="menu"
|
|
|
|
|
node-key="id"
|
2021-01-09 18:53:43 +08:00
|
|
|
|
:check-strictly="form.menuCheckStrictly"
|
2021-01-09 13:32:27 +08:00
|
|
|
|
empty-text="加载中,请稍后"
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
></el-tree>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button type="primary" @click="submitMenu">确 定</el-button>
|
|
|
|
|
<el-button @click="cancelMenu">取 消</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
2019-10-08 09:14:38 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-01-09 22:00:22 +08:00
|
|
|
|
import {
|
|
|
|
|
addRole,
|
|
|
|
|
changeRoleStatus,
|
|
|
|
|
dataScope,
|
|
|
|
|
delRole,
|
|
|
|
|
exportRole,
|
|
|
|
|
getRole,
|
|
|
|
|
listRole,
|
|
|
|
|
updateRole
|
|
|
|
|
} from "@/api/system/role";
|
|
|
|
|
import {listSimpleMenus} from "@/api/system/menu";
|
|
|
|
|
import {assignRoleMenu, listRoleMenus} from "@/api/system/permission";
|
|
|
|
|
import {listSimpleDepts, treeselect as deptTreeselect} from "@/api/system/dept";
|
|
|
|
|
import {SysCommonStatusEnum, SysDataScopeEnum} from "@/utils/constants";
|
2021-01-09 13:32:27 +08:00
|
|
|
|
import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict";
|
2019-10-08 09:14:38 +08:00
|
|
|
|
|
|
|
|
|
export default {
|
2019-12-02 09:28:11 +08:00
|
|
|
|
name: "Role",
|
2019-10-08 09:14:38 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
// 遮罩层
|
|
|
|
|
loading: true,
|
2020-08-01 15:45:38 +08:00
|
|
|
|
// 显示搜索条件
|
|
|
|
|
showSearch: true,
|
2019-10-08 09:14:38 +08:00
|
|
|
|
// 总条数
|
|
|
|
|
total: 0,
|
|
|
|
|
// 角色表格数据
|
|
|
|
|
roleList: [],
|
|
|
|
|
// 弹出层标题
|
|
|
|
|
title: "",
|
|
|
|
|
// 是否显示弹出层
|
|
|
|
|
open: false,
|
|
|
|
|
// 是否显示弹出层(数据权限)
|
|
|
|
|
openDataScope: false,
|
2021-01-09 13:32:27 +08:00
|
|
|
|
// 是否显示弹出层(菜单权限)
|
|
|
|
|
openMenu: false,
|
2020-09-19 13:42:37 +08:00
|
|
|
|
menuExpand: false,
|
|
|
|
|
menuNodeAll: false,
|
|
|
|
|
deptExpand: true,
|
|
|
|
|
deptNodeAll: false,
|
2019-10-08 09:14:38 +08:00
|
|
|
|
// 日期范围
|
|
|
|
|
dateRange: [],
|
|
|
|
|
// 菜单列表
|
|
|
|
|
menuOptions: [],
|
|
|
|
|
// 部门列表
|
|
|
|
|
deptOptions: [],
|
|
|
|
|
// 查询参数
|
|
|
|
|
queryParams: {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
pageNo: 1,
|
2019-10-08 09:14:38 +08:00
|
|
|
|
pageSize: 10,
|
2021-01-09 13:32:27 +08:00
|
|
|
|
name: undefined,
|
|
|
|
|
code: undefined,
|
2019-10-08 09:14:38 +08:00
|
|
|
|
status: undefined
|
|
|
|
|
},
|
|
|
|
|
// 表单参数
|
|
|
|
|
form: {},
|
|
|
|
|
defaultProps: {
|
2021-01-09 18:53:43 +08:00
|
|
|
|
label: "name",
|
|
|
|
|
children: "children"
|
2019-10-08 09:14:38 +08:00
|
|
|
|
},
|
|
|
|
|
// 表单校验
|
|
|
|
|
rules: {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
name: [
|
2019-10-08 09:14:38 +08:00
|
|
|
|
{ required: true, message: "角色名称不能为空", trigger: "blur" }
|
|
|
|
|
],
|
2021-01-09 13:32:27 +08:00
|
|
|
|
code: [
|
|
|
|
|
{ required: true, message: "角色标识不能为空", trigger: "blur" }
|
2019-10-08 09:14:38 +08:00
|
|
|
|
],
|
2021-01-09 13:32:27 +08:00
|
|
|
|
sort: [
|
2019-10-08 09:14:38 +08:00
|
|
|
|
{ required: true, message: "角色顺序不能为空", trigger: "blur" }
|
|
|
|
|
]
|
2021-01-09 13:32:27 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 枚举
|
2021-01-09 22:00:22 +08:00
|
|
|
|
SysCommonStatusEnum: SysCommonStatusEnum,
|
|
|
|
|
SysDataScopeEnum: SysDataScopeEnum,
|
2021-01-09 13:32:27 +08:00
|
|
|
|
// 数据字典
|
|
|
|
|
roleTypeDictDatas: getDictDatas(DICT_TYPE.SYS_ROLE_TYPE),
|
2021-01-09 22:00:22 +08:00
|
|
|
|
statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS),
|
|
|
|
|
dataScopeDictDatas: getDictDatas(DICT_TYPE.SYS_DATA_SCOPE)
|
2019-10-08 09:14:38 +08:00
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.getList();
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
/** 查询角色列表 */
|
|
|
|
|
getList() {
|
|
|
|
|
this.loading = true;
|
|
|
|
|
listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
|
|
|
|
|
response => {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
this.roleList = response.data.list;
|
|
|
|
|
this.total = response.data.total;
|
2019-10-08 09:14:38 +08:00
|
|
|
|
this.loading = false;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
// 角色状态修改
|
|
|
|
|
handleStatusChange(row) {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
// 此时,row 已经变成目标状态了,所以可以直接提交请求和提示
|
|
|
|
|
let text = row.status === SysCommonStatusEnum.ENABLE ? "启用" : "停用";
|
|
|
|
|
this.$confirm('确认要"' + text + '""' + row.name + '"角色吗?', "警告", {
|
2019-10-08 09:14:38 +08:00
|
|
|
|
confirmButtonText: "确定",
|
|
|
|
|
cancelButtonText: "取消",
|
|
|
|
|
type: "warning"
|
|
|
|
|
}).then(function() {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
return changeRoleStatus(row.id, row.status);
|
2019-10-08 09:14:38 +08:00
|
|
|
|
}).then(() => {
|
|
|
|
|
this.msgSuccess(text + "成功");
|
|
|
|
|
}).catch(function() {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
// 异常时,需要将 row.status 状态重置回之前的
|
|
|
|
|
row.status = row.status === SysCommonStatusEnum.ENABLE ? SysCommonStatusEnum.DISABLE
|
|
|
|
|
: SysCommonStatusEnum.ENABLE;
|
2019-10-08 09:14:38 +08:00
|
|
|
|
});
|
|
|
|
|
},
|
2021-01-09 13:32:27 +08:00
|
|
|
|
// 角色类型字典翻译
|
|
|
|
|
typeFormat(row, column) {
|
|
|
|
|
return getDictDataLabel(DICT_TYPE.SYS_ROLE_TYPE, row.type)
|
|
|
|
|
},
|
2019-10-08 09:14:38 +08:00
|
|
|
|
// 取消按钮
|
|
|
|
|
cancel() {
|
|
|
|
|
this.open = false;
|
|
|
|
|
this.reset();
|
|
|
|
|
},
|
|
|
|
|
// 取消按钮(数据权限)
|
|
|
|
|
cancelDataScope() {
|
|
|
|
|
this.openDataScope = false;
|
|
|
|
|
this.reset();
|
|
|
|
|
},
|
2021-01-09 13:32:27 +08:00
|
|
|
|
// 取消按钮(菜单权限)
|
|
|
|
|
cancelMenu() {
|
|
|
|
|
this.openMenu = false;
|
|
|
|
|
this.reset();
|
|
|
|
|
},
|
2019-10-08 09:14:38 +08:00
|
|
|
|
// 表单重置
|
|
|
|
|
reset() {
|
2021-01-09 18:53:43 +08:00
|
|
|
|
if (this.$refs.menu !== undefined) {
|
2020-02-08 18:30:09 +08:00
|
|
|
|
this.$refs.menu.setCheckedKeys([]);
|
2019-10-08 09:14:38 +08:00
|
|
|
|
}
|
2021-01-09 18:53:43 +08:00
|
|
|
|
this.menuExpand = false;
|
|
|
|
|
this.menuNodeAll = false;
|
|
|
|
|
this.deptExpand = true;
|
|
|
|
|
this.deptNodeAll = false;
|
2019-10-08 09:14:38 +08:00
|
|
|
|
this.form = {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
id: undefined,
|
|
|
|
|
name: undefined,
|
|
|
|
|
code: undefined,
|
|
|
|
|
sort: 0,
|
2019-10-08 09:14:38 +08:00
|
|
|
|
deptIds: [],
|
2021-01-09 18:53:43 +08:00
|
|
|
|
menuIds: [],
|
|
|
|
|
deptCheckStrictly: false,
|
2019-10-08 09:14:38 +08:00
|
|
|
|
remark: undefined
|
|
|
|
|
};
|
|
|
|
|
this.resetForm("form");
|
|
|
|
|
},
|
|
|
|
|
/** 搜索按钮操作 */
|
|
|
|
|
handleQuery() {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
this.queryParams.pageNo = 1;
|
2019-10-08 09:14:38 +08:00
|
|
|
|
this.getList();
|
|
|
|
|
},
|
2019-11-11 08:59:15 +08:00
|
|
|
|
/** 重置按钮操作 */
|
|
|
|
|
resetQuery() {
|
|
|
|
|
this.dateRange = [];
|
|
|
|
|
this.resetForm("queryForm");
|
|
|
|
|
this.handleQuery();
|
|
|
|
|
},
|
2020-09-19 13:42:37 +08:00
|
|
|
|
// 树权限(展开/折叠)
|
|
|
|
|
handleCheckedTreeExpand(value, type) {
|
2021-01-09 18:53:43 +08:00
|
|
|
|
if (type === 'menu') {
|
2020-09-19 13:42:37 +08:00
|
|
|
|
let treeList = this.menuOptions;
|
|
|
|
|
for (let i = 0; i < treeList.length; i++) {
|
|
|
|
|
this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
|
|
|
|
|
}
|
2021-01-09 18:53:43 +08:00
|
|
|
|
} else if (type === 'dept') {
|
2020-09-19 13:42:37 +08:00
|
|
|
|
let treeList = this.deptOptions;
|
|
|
|
|
for (let i = 0; i < treeList.length; i++) {
|
|
|
|
|
this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 树权限(全选/全不选)
|
|
|
|
|
handleCheckedTreeNodeAll(value, type) {
|
2021-01-09 18:53:43 +08:00
|
|
|
|
if (type === 'menu') {
|
2020-09-19 13:42:37 +08:00
|
|
|
|
this.$refs.menu.setCheckedNodes(value ? this.menuOptions: []);
|
2021-01-09 18:53:43 +08:00
|
|
|
|
} else if (type === 'dept') {
|
2020-09-19 13:42:37 +08:00
|
|
|
|
this.$refs.dept.setCheckedNodes(value ? this.deptOptions: []);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 树权限(父子联动)
|
|
|
|
|
handleCheckedTreeConnect(value, type) {
|
2021-01-09 18:53:43 +08:00
|
|
|
|
if (type === 'menu') {
|
|
|
|
|
this.form.menuCheckStrictly = value;
|
|
|
|
|
} else if (type === 'dept') {
|
|
|
|
|
this.form.deptCheckStrictly = value;
|
2020-09-19 13:42:37 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-10-08 09:14:38 +08:00
|
|
|
|
/** 新增按钮操作 */
|
|
|
|
|
handleAdd() {
|
|
|
|
|
this.reset();
|
|
|
|
|
this.open = true;
|
|
|
|
|
this.title = "添加角色";
|
|
|
|
|
},
|
|
|
|
|
/** 修改按钮操作 */
|
|
|
|
|
handleUpdate(row) {
|
|
|
|
|
this.reset();
|
2021-01-09 13:32:27 +08:00
|
|
|
|
const id = row.id
|
|
|
|
|
getRole(id).then(response => {
|
2019-10-08 09:14:38 +08:00
|
|
|
|
this.form = response.data;
|
|
|
|
|
this.open = true;
|
|
|
|
|
this.title = "修改角色";
|
|
|
|
|
});
|
|
|
|
|
},
|
2021-01-09 13:32:27 +08:00
|
|
|
|
/** 分配菜单权限操作 */
|
|
|
|
|
handleMenu(row) {
|
|
|
|
|
this.reset();
|
|
|
|
|
const id = row.id
|
2021-01-09 18:53:43 +08:00
|
|
|
|
// 处理了 form 的角色 name 和 code 的展示
|
|
|
|
|
this.form.id = id;
|
|
|
|
|
this.form.name = row.name;
|
|
|
|
|
this.form.code = row.code;
|
|
|
|
|
// 打开弹窗
|
2021-01-09 13:32:27 +08:00
|
|
|
|
this.openMenu = true;
|
2021-01-09 18:53:43 +08:00
|
|
|
|
// 获得菜单列表
|
|
|
|
|
listSimpleMenus().then(response => {
|
|
|
|
|
// 处理 menuOptions 参数
|
|
|
|
|
this.menuOptions = [];
|
|
|
|
|
this.menuOptions.push(...this.handleTree(response.data, "id"));
|
|
|
|
|
});
|
|
|
|
|
// 获得角色拥有的菜单集合
|
|
|
|
|
listRoleMenus(id).then(response => {
|
|
|
|
|
// 设置选中
|
2021-01-09 19:22:07 +08:00
|
|
|
|
this.$refs.menu.setCheckedKeys(response.data, true, false);
|
2021-01-09 18:53:43 +08:00
|
|
|
|
})
|
2021-01-09 13:32:27 +08:00
|
|
|
|
},
|
2019-10-08 09:14:38 +08:00
|
|
|
|
/** 分配数据权限操作 */
|
|
|
|
|
handleDataScope(row) {
|
|
|
|
|
this.reset();
|
2021-01-09 22:00:22 +08:00
|
|
|
|
// 处理了 form 的角色 name 和 code 的展示
|
|
|
|
|
this.form.id = row.id;
|
|
|
|
|
this.form.name = row.name;
|
|
|
|
|
this.form.code = row.code;
|
|
|
|
|
// 打开弹窗
|
|
|
|
|
this.openDataScope = true;
|
|
|
|
|
// 获得部门列表
|
|
|
|
|
listSimpleDepts().then(response => {
|
|
|
|
|
// 处理 menuOptions 参数
|
|
|
|
|
this.deptOptions = [];
|
|
|
|
|
this.deptOptions.push(...this.handleTree(response.data, "id"));
|
|
|
|
|
});
|
|
|
|
|
// 获得角色拥有的数据权限
|
2021-01-09 13:32:27 +08:00
|
|
|
|
getRole(row.id).then(response => {
|
2021-01-09 22:00:22 +08:00
|
|
|
|
// TODO 搞一搞
|
|
|
|
|
// this.$refs.dept.setCheckedKeys(res.checkedKeys);
|
2019-10-08 09:14:38 +08:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
/** 提交按钮 */
|
|
|
|
|
submitForm: function() {
|
|
|
|
|
this.$refs["form"].validate(valid => {
|
|
|
|
|
if (valid) {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
if (this.form.id !== undefined) {
|
2019-10-08 09:14:38 +08:00
|
|
|
|
updateRole(this.form).then(response => {
|
2020-10-10 17:54:30 +08:00
|
|
|
|
this.msgSuccess("修改成功");
|
|
|
|
|
this.open = false;
|
|
|
|
|
this.getList();
|
2019-10-08 09:14:38 +08:00
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
addRole(this.form).then(response => {
|
2020-10-10 17:54:30 +08:00
|
|
|
|
this.msgSuccess("新增成功");
|
|
|
|
|
this.open = false;
|
|
|
|
|
this.getList();
|
2019-10-08 09:14:38 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
/** 提交按钮(数据权限) */
|
|
|
|
|
submitDataScope: function() {
|
2021-01-09 18:53:43 +08:00
|
|
|
|
if (this.form.id !== undefined) {
|
2021-01-09 22:00:22 +08:00
|
|
|
|
// this.form.deptIds = this.getDeptAllCheckedKeys();
|
|
|
|
|
debugger
|
|
|
|
|
dataScope({
|
|
|
|
|
roleId: this.form.id,
|
|
|
|
|
deptIds: this.form.dataScope !== SysDataScopeEnum.DEPT_CUSTOM ? [] :
|
|
|
|
|
this.$refs.dept.getCheckedKeys(false)
|
|
|
|
|
}).then(response => {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
this.msgSuccess("修改成功");
|
|
|
|
|
this.openDataScope = false;
|
|
|
|
|
this.getList();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/** 提交按钮(菜单权限) */
|
|
|
|
|
submitMenu: function() {
|
2021-01-09 18:53:43 +08:00
|
|
|
|
if (this.form.id !== undefined) {
|
|
|
|
|
assignRoleMenu({
|
|
|
|
|
roleId: this.form.id,
|
2021-01-09 19:22:07 +08:00
|
|
|
|
menuIds: this.$refs.menu.getCheckedKeys(true)
|
2021-01-09 18:53:43 +08:00
|
|
|
|
}).then(response => {
|
2020-10-10 17:54:30 +08:00
|
|
|
|
this.msgSuccess("修改成功");
|
2021-01-09 18:53:43 +08:00
|
|
|
|
this.openMenu = false;
|
2020-10-10 17:54:30 +08:00
|
|
|
|
this.getList();
|
2019-10-08 09:14:38 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/** 删除按钮操作 */
|
|
|
|
|
handleDelete(row) {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
const ids = row.id || this.ids;
|
|
|
|
|
this.$confirm('是否确认删除角色编号为"' + ids + '"的数据项?', "警告", {
|
2019-10-08 09:14:38 +08:00
|
|
|
|
confirmButtonText: "确定",
|
|
|
|
|
cancelButtonText: "取消",
|
|
|
|
|
type: "warning"
|
|
|
|
|
}).then(function() {
|
2021-01-09 13:32:27 +08:00
|
|
|
|
return delRole(ids);
|
2019-10-08 09:14:38 +08:00
|
|
|
|
}).then(() => {
|
|
|
|
|
this.getList();
|
|
|
|
|
this.msgSuccess("删除成功");
|
2020-10-10 17:54:30 +08:00
|
|
|
|
})
|
2019-11-11 08:59:15 +08:00
|
|
|
|
},
|
|
|
|
|
/** 导出按钮操作 */
|
|
|
|
|
handleExport() {
|
|
|
|
|
const queryParams = this.queryParams;
|
|
|
|
|
this.$confirm('是否确认导出所有角色数据项?', "警告", {
|
|
|
|
|
confirmButtonText: "确定",
|
|
|
|
|
cancelButtonText: "取消",
|
|
|
|
|
type: "warning"
|
|
|
|
|
}).then(function() {
|
|
|
|
|
return exportRole(queryParams);
|
|
|
|
|
}).then(response => {
|
|
|
|
|
this.download(response.msg);
|
2020-10-10 17:54:30 +08:00
|
|
|
|
})
|
2019-10-08 09:14:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-01-08 20:08:20 +08:00
|
|
|
|
</script>
|