Commit ad1d1978d200f8be4a383863a724be7e6735d3c0
1 parent
9e59a6c1
1. 完成 Role 简单的 CRUD 的迁移
Showing
9 changed files
with
229 additions
and
179 deletions
ruoyi-ui/src/api/system/role.js
| @@ -3,7 +3,7 @@ import request from '@/utils/request' | @@ -3,7 +3,7 @@ import request from '@/utils/request' | ||
| 3 | // 查询角色列表 | 3 | // 查询角色列表 |
| 4 | export function listRole(query) { | 4 | export function listRole(query) { |
| 5 | return request({ | 5 | return request({ |
| 6 | - url: '/system/role/list', | 6 | + url: '/system/role/page', |
| 7 | method: 'get', | 7 | method: 'get', |
| 8 | params: query | 8 | params: query |
| 9 | }) | 9 | }) |
| @@ -12,7 +12,7 @@ export function listRole(query) { | @@ -12,7 +12,7 @@ export function listRole(query) { | ||
| 12 | // 查询角色详细 | 12 | // 查询角色详细 |
| 13 | export function getRole(roleId) { | 13 | export function getRole(roleId) { |
| 14 | return request({ | 14 | return request({ |
| 15 | - url: '/system/role/' + roleId, | 15 | + url: '/system/role/get?id=' + roleId, |
| 16 | method: 'get' | 16 | method: 'get' |
| 17 | }) | 17 | }) |
| 18 | } | 18 | } |
| @@ -20,7 +20,7 @@ export function getRole(roleId) { | @@ -20,7 +20,7 @@ export function getRole(roleId) { | ||
| 20 | // 新增角色 | 20 | // 新增角色 |
| 21 | export function addRole(data) { | 21 | export function addRole(data) { |
| 22 | return request({ | 22 | return request({ |
| 23 | - url: '/system/role', | 23 | + url: '/system/role/create', |
| 24 | method: 'post', | 24 | method: 'post', |
| 25 | data: data | 25 | data: data |
| 26 | }) | 26 | }) |
| @@ -29,8 +29,8 @@ export function addRole(data) { | @@ -29,8 +29,8 @@ export function addRole(data) { | ||
| 29 | // 修改角色 | 29 | // 修改角色 |
| 30 | export function updateRole(data) { | 30 | export function updateRole(data) { |
| 31 | return request({ | 31 | return request({ |
| 32 | - url: '/system/role', | ||
| 33 | - method: 'put', | 32 | + url: '/system/role/update', |
| 33 | + method: 'post', | ||
| 34 | data: data | 34 | data: data |
| 35 | }) | 35 | }) |
| 36 | } | 36 | } |
| @@ -45,14 +45,14 @@ export function dataScope(data) { | @@ -45,14 +45,14 @@ export function dataScope(data) { | ||
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | // 角色状态修改 | 47 | // 角色状态修改 |
| 48 | -export function changeRoleStatus(roleId, status) { | 48 | +export function changeRoleStatus(id, status) { |
| 49 | const data = { | 49 | const data = { |
| 50 | - roleId, | 50 | + id, |
| 51 | status | 51 | status |
| 52 | } | 52 | } |
| 53 | return request({ | 53 | return request({ |
| 54 | - url: '/system/role/changeStatus', | ||
| 55 | - method: 'put', | 54 | + url: '/system/role/update-status', |
| 55 | + method: 'post', | ||
| 56 | data: data | 56 | data: data |
| 57 | }) | 57 | }) |
| 58 | } | 58 | } |
| @@ -60,8 +60,8 @@ export function changeRoleStatus(roleId, status) { | @@ -60,8 +60,8 @@ export function changeRoleStatus(roleId, status) { | ||
| 60 | // 删除角色 | 60 | // 删除角色 |
| 61 | export function delRole(roleId) { | 61 | export function delRole(roleId) { |
| 62 | return request({ | 62 | return request({ |
| 63 | - url: '/system/role/' + roleId, | ||
| 64 | - method: 'delete' | 63 | + url: '/system/role/delete?id=' + roleId, |
| 64 | + method: 'post' | ||
| 65 | }) | 65 | }) |
| 66 | } | 66 | } |
| 67 | 67 | ||
| @@ -72,4 +72,4 @@ export function exportRole(query) { | @@ -72,4 +72,4 @@ export function exportRole(query) { | ||
| 72 | method: 'get', | 72 | method: 'get', |
| 73 | params: query | 73 | params: query |
| 74 | }) | 74 | }) |
| 75 | -} | ||
| 76 | \ No newline at end of file | 75 | \ No newline at end of file |
| 76 | +} |
ruoyi-ui/src/utils/dict.js
| @@ -7,7 +7,8 @@ import store from '@/store' | @@ -7,7 +7,8 @@ import store from '@/store' | ||
| 7 | 7 | ||
| 8 | export const DICT_TYPE = { | 8 | export const DICT_TYPE = { |
| 9 | SYS_COMMON_STATUS: 'sys_common_status', | 9 | SYS_COMMON_STATUS: 'sys_common_status', |
| 10 | - SYS_MENU_TYPE: 'sys_menu_type' | 10 | + SYS_MENU_TYPE: 'sys_menu_type', |
| 11 | + SYS_ROLE_TYPE: 'sys_role_type', | ||
| 11 | } | 12 | } |
| 12 | 13 | ||
| 13 | /** | 14 | /** |
ruoyi-ui/src/views/system/menu/index.vue
| @@ -14,9 +14,9 @@ | @@ -14,9 +14,9 @@ | ||
| 14 | <el-select v-model="queryParams.status" placeholder="菜单状态" clearable size="small"> | 14 | <el-select v-model="queryParams.status" placeholder="菜单状态" clearable size="small"> |
| 15 | <el-option | 15 | <el-option |
| 16 | v-for="dict in statusDictDatas" | 16 | v-for="dict in statusDictDatas" |
| 17 | - :key="dict.value" | 17 | + :key="parseInt(dict.value)" |
| 18 | :label="dict.label" | 18 | :label="dict.label" |
| 19 | - :value="dict.value" | 19 | + :value="parseInt(dict.value)" |
| 20 | /> | 20 | /> |
| 21 | </el-select> | 21 | </el-select> |
| 22 | </el-form-item> | 22 | </el-form-item> |
ruoyi-ui/src/views/system/role/index.vue
| 1 | <template> | 1 | <template> |
| 2 | <div class="app-container"> | 2 | <div class="app-container"> |
| 3 | <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true"> | 3 | <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true"> |
| 4 | - <el-form-item label="角色名称" prop="roleName"> | 4 | + <el-form-item label="角色名称" prop="name"> |
| 5 | <el-input | 5 | <el-input |
| 6 | - v-model="queryParams.roleName" | 6 | + v-model="queryParams.name" |
| 7 | placeholder="请输入角色名称" | 7 | placeholder="请输入角色名称" |
| 8 | clearable | 8 | clearable |
| 9 | size="small" | 9 | size="small" |
| @@ -11,10 +11,10 @@ | @@ -11,10 +11,10 @@ | ||
| 11 | @keyup.enter.native="handleQuery" | 11 | @keyup.enter.native="handleQuery" |
| 12 | /> | 12 | /> |
| 13 | </el-form-item> | 13 | </el-form-item> |
| 14 | - <el-form-item label="权限字符" prop="roleKey"> | 14 | + <el-form-item label="角色标识" prop="code"> |
| 15 | <el-input | 15 | <el-input |
| 16 | - v-model="queryParams.roleKey" | ||
| 17 | - placeholder="请输入权限字符" | 16 | + v-model="queryParams.code" |
| 17 | + placeholder="请输入角色标识" | ||
| 18 | clearable | 18 | clearable |
| 19 | size="small" | 19 | size="small" |
| 20 | style="width: 240px" | 20 | style="width: 240px" |
| @@ -30,10 +30,10 @@ | @@ -30,10 +30,10 @@ | ||
| 30 | style="width: 240px" | 30 | style="width: 240px" |
| 31 | > | 31 | > |
| 32 | <el-option | 32 | <el-option |
| 33 | - v-for="dict in statusOptions" | ||
| 34 | - :key="dict.dictValue" | ||
| 35 | - :label="dict.dictLabel" | ||
| 36 | - :value="dict.dictValue" | 33 | + v-for="dict in statusDictDatas" |
| 34 | + :key="parseInt(dict.value)" | ||
| 35 | + :label="dict.label" | ||
| 36 | + :value="parseInt(dict.value)" | ||
| 37 | /> | 37 | /> |
| 38 | </el-select> | 38 | </el-select> |
| 39 | </el-form-item> | 39 | </el-form-item> |
| @@ -67,26 +67,6 @@ | @@ -67,26 +67,6 @@ | ||
| 67 | </el-col> | 67 | </el-col> |
| 68 | <el-col :span="1.5"> | 68 | <el-col :span="1.5"> |
| 69 | <el-button | 69 | <el-button |
| 70 | - type="success" | ||
| 71 | - icon="el-icon-edit" | ||
| 72 | - size="mini" | ||
| 73 | - :disabled="single" | ||
| 74 | - @click="handleUpdate" | ||
| 75 | - v-hasPermi="['system:role:edit']" | ||
| 76 | - >修改</el-button> | ||
| 77 | - </el-col> | ||
| 78 | - <el-col :span="1.5"> | ||
| 79 | - <el-button | ||
| 80 | - type="danger" | ||
| 81 | - icon="el-icon-delete" | ||
| 82 | - size="mini" | ||
| 83 | - :disabled="multiple" | ||
| 84 | - @click="handleDelete" | ||
| 85 | - v-hasPermi="['system:role:remove']" | ||
| 86 | - >删除</el-button> | ||
| 87 | - </el-col> | ||
| 88 | - <el-col :span="1.5"> | ||
| 89 | - <el-button | ||
| 90 | type="warning" | 70 | type="warning" |
| 91 | icon="el-icon-download" | 71 | icon="el-icon-download" |
| 92 | size="mini" | 72 | size="mini" |
| @@ -97,18 +77,18 @@ | @@ -97,18 +77,18 @@ | ||
| 97 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | 77 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 98 | </el-row> | 78 | </el-row> |
| 99 | 79 | ||
| 100 | - <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange"> | ||
| 101 | - <el-table-column type="selection" width="55" align="center" /> | ||
| 102 | - <el-table-column label="角色编号" prop="roleId" width="120" /> | ||
| 103 | - <el-table-column label="角色名称" prop="roleName" :show-overflow-tooltip="true" width="150" /> | ||
| 104 | - <el-table-column label="权限字符" prop="roleKey" :show-overflow-tooltip="true" width="150" /> | ||
| 105 | - <el-table-column label="显示顺序" prop="roleSort" width="100" /> | 80 | + <el-table v-loading="loading" :data="roleList"> |
| 81 | + <el-table-column label="角色编号" prop="id" width="120" /> | ||
| 82 | + <el-table-column label="角色名称" prop="name" :show-overflow-tooltip="true" width="150" /> | ||
| 83 | + <el-table-column label="角色标识" prop="code" :show-overflow-tooltip="true" width="150" /> | ||
| 84 | + <el-table-column label="角色类型" prop="type" :formatter="typeFormat" width="80"></el-table-column> | ||
| 85 | + <el-table-column label="显示顺序" prop="sort" width="100" /> | ||
| 106 | <el-table-column label="状态" align="center" width="100"> | 86 | <el-table-column label="状态" align="center" width="100"> |
| 107 | <template slot-scope="scope"> | 87 | <template slot-scope="scope"> |
| 108 | <el-switch | 88 | <el-switch |
| 109 | v-model="scope.row.status" | 89 | v-model="scope.row.status" |
| 110 | - active-value="0" | ||
| 111 | - inactive-value="1" | 90 | + :active-value="0" |
| 91 | + :inactive-value="1" | ||
| 112 | @change="handleStatusChange(scope.row)" | 92 | @change="handleStatusChange(scope.row)" |
| 113 | ></el-switch> | 93 | ></el-switch> |
| 114 | </template> | 94 | </template> |
| @@ -128,6 +108,13 @@ | @@ -128,6 +108,13 @@ | ||
| 128 | v-hasPermi="['system:role:edit']" | 108 | v-hasPermi="['system:role:edit']" |
| 129 | >修改</el-button> | 109 | >修改</el-button> |
| 130 | <el-button | 110 | <el-button |
| 111 | + size="mini" | ||
| 112 | + type="text" | ||
| 113 | + icon="el-icon-circle-check" | ||
| 114 | + @click="handleMenu(scope.row)" | ||
| 115 | + v-hasPermi="['system:role:edit']" | ||
| 116 | + >菜单权限</el-button> | ||
| 117 | + <el-button | ||
| 131 | size="mini" | 118 | size="mini" |
| 132 | type="text" | 119 | type="text" |
| 133 | icon="el-icon-circle-check" | 120 | icon="el-icon-circle-check" |
| @@ -156,38 +143,14 @@ | @@ -156,38 +143,14 @@ | ||
| 156 | <!-- 添加或修改角色配置对话框 --> | 143 | <!-- 添加或修改角色配置对话框 --> |
| 157 | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> | 144 | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> |
| 158 | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | 145 | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
| 159 | - <el-form-item label="角色名称" prop="roleName"> | ||
| 160 | - <el-input v-model="form.roleName" placeholder="请输入角色名称" /> | ||
| 161 | - </el-form-item> | ||
| 162 | - <el-form-item label="权限字符" prop="roleKey"> | ||
| 163 | - <el-input v-model="form.roleKey" placeholder="请输入权限字符" /> | 146 | + <el-form-item label="角色名称" prop="name"> |
| 147 | + <el-input v-model="form.name" placeholder="请输入角色名称" /> | ||
| 164 | </el-form-item> | 148 | </el-form-item> |
| 165 | - <el-form-item label="角色顺序" prop="roleSort"> | ||
| 166 | - <el-input-number v-model="form.roleSort" controls-position="right" :min="0" /> | 149 | + <el-form-item label="角色标识" prop="code"> |
| 150 | + <el-input v-model="form.code" placeholder="请输入角色标识" /> | ||
| 167 | </el-form-item> | 151 | </el-form-item> |
| 168 | - <el-form-item label="状态"> | ||
| 169 | - <el-radio-group v-model="form.status"> | ||
| 170 | - <el-radio | ||
| 171 | - v-for="dict in statusOptions" | ||
| 172 | - :key="dict.dictValue" | ||
| 173 | - :label="dict.dictValue" | ||
| 174 | - >{{dict.dictLabel}}</el-radio> | ||
| 175 | - </el-radio-group> | ||
| 176 | - </el-form-item> | ||
| 177 | - <el-form-item label="菜单权限"> | ||
| 178 | - <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox> | ||
| 179 | - <el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox> | ||
| 180 | - <el-checkbox v-model="form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox> | ||
| 181 | - <el-tree | ||
| 182 | - class="tree-border" | ||
| 183 | - :data="menuOptions" | ||
| 184 | - show-checkbox | ||
| 185 | - ref="menu" | ||
| 186 | - node-key="id" | ||
| 187 | - :check-strictly="!form.menuCheckStrictly" | ||
| 188 | - empty-text="加载中,请稍后" | ||
| 189 | - :props="defaultProps" | ||
| 190 | - ></el-tree> | 152 | + <el-form-item label="角色顺序" prop="sort"> |
| 153 | + <el-input-number v-model="form.sort" controls-position="right" :min="0" /> | ||
| 191 | </el-form-item> | 154 | </el-form-item> |
| 192 | <el-form-item label="备注"> | 155 | <el-form-item label="备注"> |
| 193 | <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input> | 156 | <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input> |
| @@ -199,14 +162,14 @@ | @@ -199,14 +162,14 @@ | ||
| 199 | </div> | 162 | </div> |
| 200 | </el-dialog> | 163 | </el-dialog> |
| 201 | 164 | ||
| 202 | - <!-- 分配角色数据权限对话框 --> | 165 | + <!-- 分配角色的数据权限对话框 --> |
| 203 | <el-dialog :title="title" :visible.sync="openDataScope" width="500px" append-to-body> | 166 | <el-dialog :title="title" :visible.sync="openDataScope" width="500px" append-to-body> |
| 204 | <el-form :model="form" label-width="80px"> | 167 | <el-form :model="form" label-width="80px"> |
| 205 | <el-form-item label="角色名称"> | 168 | <el-form-item label="角色名称"> |
| 206 | - <el-input v-model="form.roleName" :disabled="true" /> | 169 | + <el-input v-model="form.name" :disabled="true" /> |
| 207 | </el-form-item> | 170 | </el-form-item> |
| 208 | - <el-form-item label="权限字符"> | ||
| 209 | - <el-input v-model="form.roleKey" :disabled="true" /> | 171 | + <el-form-item label="角色标识"> |
| 172 | + <el-input v-model="form.code" :disabled="true" /> | ||
| 210 | </el-form-item> | 173 | </el-form-item> |
| 211 | <el-form-item label="权限范围"> | 174 | <el-form-item label="权限范围"> |
| 212 | <el-select v-model="form.dataScope"> | 175 | <el-select v-model="form.dataScope"> |
| @@ -240,6 +203,37 @@ | @@ -240,6 +203,37 @@ | ||
| 240 | <el-button @click="cancelDataScope">取 消</el-button> | 203 | <el-button @click="cancelDataScope">取 消</el-button> |
| 241 | </div> | 204 | </div> |
| 242 | </el-dialog> | 205 | </el-dialog> |
| 206 | + | ||
| 207 | + <!-- 分配角色的菜单权限对话框 --> | ||
| 208 | + <el-dialog :title="title" :visible.sync="openMenu" width="500px" append-to-body> | ||
| 209 | + <el-form :model="form" label-width="80px"> | ||
| 210 | + <el-form-item label="角色名称"> | ||
| 211 | + <el-input v-model="form.name" :disabled="true" /> | ||
| 212 | + </el-form-item> | ||
| 213 | + <el-form-item label="角色标识"> | ||
| 214 | + <el-input v-model="form.code" :disabled="true" /> | ||
| 215 | + </el-form-item> | ||
| 216 | + <el-form-item label="菜单权限"> | ||
| 217 | + <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox> | ||
| 218 | + <el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox> | ||
| 219 | + <el-checkbox v-model="form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox> | ||
| 220 | + <el-tree | ||
| 221 | + class="tree-border" | ||
| 222 | + :data="menuOptions" | ||
| 223 | + show-checkbox | ||
| 224 | + ref="menu" | ||
| 225 | + node-key="id" | ||
| 226 | + :check-strictly="!form.menuCheckStrictly" | ||
| 227 | + empty-text="加载中,请稍后" | ||
| 228 | + :props="defaultProps" | ||
| 229 | + ></el-tree> | ||
| 230 | + </el-form-item> | ||
| 231 | + </el-form> | ||
| 232 | + <div slot="footer" class="dialog-footer"> | ||
| 233 | + <el-button type="primary" @click="submitMenu">确 定</el-button> | ||
| 234 | + <el-button @click="cancelMenu">取 消</el-button> | ||
| 235 | + </div> | ||
| 236 | + </el-dialog> | ||
| 243 | </div> | 237 | </div> |
| 244 | </template> | 238 | </template> |
| 245 | 239 | ||
| @@ -247,6 +241,8 @@ | @@ -247,6 +241,8 @@ | ||
| 247 | import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role"; | 241 | import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role"; |
| 248 | import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu"; | 242 | import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu"; |
| 249 | import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept"; | 243 | import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept"; |
| 244 | +import {SysCommonStatusEnum, SysMenuTypeEnum} from "@/utils/constants"; | ||
| 245 | +import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict"; | ||
| 250 | 246 | ||
| 251 | export default { | 247 | export default { |
| 252 | name: "Role", | 248 | name: "Role", |
| @@ -254,12 +250,6 @@ export default { | @@ -254,12 +250,6 @@ export default { | ||
| 254 | return { | 250 | return { |
| 255 | // 遮罩层 | 251 | // 遮罩层 |
| 256 | loading: true, | 252 | loading: true, |
| 257 | - // 选中数组 | ||
| 258 | - ids: [], | ||
| 259 | - // 非单个禁用 | ||
| 260 | - single: true, | ||
| 261 | - // 非多个禁用 | ||
| 262 | - multiple: true, | ||
| 263 | // 显示搜索条件 | 253 | // 显示搜索条件 |
| 264 | showSearch: true, | 254 | showSearch: true, |
| 265 | // 总条数 | 255 | // 总条数 |
| @@ -272,6 +262,9 @@ export default { | @@ -272,6 +262,9 @@ export default { | ||
| 272 | open: false, | 262 | open: false, |
| 273 | // 是否显示弹出层(数据权限) | 263 | // 是否显示弹出层(数据权限) |
| 274 | openDataScope: false, | 264 | openDataScope: false, |
| 265 | + // 是否显示弹出层(菜单权限) | ||
| 266 | + openMenu: false, | ||
| 267 | + // TODO 需要简化下 | ||
| 275 | menuExpand: false, | 268 | menuExpand: false, |
| 276 | menuNodeAll: false, | 269 | menuNodeAll: false, |
| 277 | deptExpand: true, | 270 | deptExpand: true, |
| @@ -309,10 +302,10 @@ export default { | @@ -309,10 +302,10 @@ export default { | ||
| 309 | deptOptions: [], | 302 | deptOptions: [], |
| 310 | // 查询参数 | 303 | // 查询参数 |
| 311 | queryParams: { | 304 | queryParams: { |
| 312 | - pageNum: 1, | 305 | + pageNo: 1, |
| 313 | pageSize: 10, | 306 | pageSize: 10, |
| 314 | - roleName: undefined, | ||
| 315 | - roleKey: undefined, | 307 | + name: undefined, |
| 308 | + code: undefined, | ||
| 316 | status: undefined | 309 | status: undefined |
| 317 | }, | 310 | }, |
| 318 | // 表单参数 | 311 | // 表单参数 |
| @@ -323,23 +316,26 @@ export default { | @@ -323,23 +316,26 @@ export default { | ||
| 323 | }, | 316 | }, |
| 324 | // 表单校验 | 317 | // 表单校验 |
| 325 | rules: { | 318 | rules: { |
| 326 | - roleName: [ | 319 | + name: [ |
| 327 | { required: true, message: "角色名称不能为空", trigger: "blur" } | 320 | { required: true, message: "角色名称不能为空", trigger: "blur" } |
| 328 | ], | 321 | ], |
| 329 | - roleKey: [ | ||
| 330 | - { required: true, message: "权限字符不能为空", trigger: "blur" } | 322 | + code: [ |
| 323 | + { required: true, message: "角色标识不能为空", trigger: "blur" } | ||
| 331 | ], | 324 | ], |
| 332 | - roleSort: [ | 325 | + sort: [ |
| 333 | { required: true, message: "角色顺序不能为空", trigger: "blur" } | 326 | { required: true, message: "角色顺序不能为空", trigger: "blur" } |
| 334 | ] | 327 | ] |
| 335 | - } | 328 | + }, |
| 329 | + | ||
| 330 | + // 枚举 | ||
| 331 | + CommonStatusEnum: SysCommonStatusEnum, | ||
| 332 | + // 数据字典 | ||
| 333 | + roleTypeDictDatas: getDictDatas(DICT_TYPE.SYS_ROLE_TYPE), | ||
| 334 | + statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS) | ||
| 336 | }; | 335 | }; |
| 337 | }, | 336 | }, |
| 338 | created() { | 337 | created() { |
| 339 | this.getList(); | 338 | this.getList(); |
| 340 | - this.getDicts("sys_normal_disable").then(response => { | ||
| 341 | - this.statusOptions = response.data; | ||
| 342 | - }); | ||
| 343 | }, | 339 | }, |
| 344 | methods: { | 340 | methods: { |
| 345 | /** 查询角色列表 */ | 341 | /** 查询角色列表 */ |
| @@ -347,8 +343,8 @@ export default { | @@ -347,8 +343,8 @@ export default { | ||
| 347 | this.loading = true; | 343 | this.loading = true; |
| 348 | listRole(this.addDateRange(this.queryParams, this.dateRange)).then( | 344 | listRole(this.addDateRange(this.queryParams, this.dateRange)).then( |
| 349 | response => { | 345 | response => { |
| 350 | - this.roleList = response.rows; | ||
| 351 | - this.total = response.total; | 346 | + this.roleList = response.data.list; |
| 347 | + this.total = response.data.total; | ||
| 352 | this.loading = false; | 348 | this.loading = false; |
| 353 | } | 349 | } |
| 354 | ); | 350 | ); |
| @@ -384,34 +380,41 @@ export default { | @@ -384,34 +380,41 @@ export default { | ||
| 384 | return checkedKeys; | 380 | return checkedKeys; |
| 385 | }, | 381 | }, |
| 386 | /** 根据角色ID查询菜单树结构 */ | 382 | /** 根据角色ID查询菜单树结构 */ |
| 387 | - getRoleMenuTreeselect(roleId) { | ||
| 388 | - return roleMenuTreeselect(roleId).then(response => { | 383 | + getRoleMenuTreeselect(id) { |
| 384 | + return roleMenuTreeselect(id).then(response => { | ||
| 389 | this.menuOptions = response.menus; | 385 | this.menuOptions = response.menus; |
| 390 | return response; | 386 | return response; |
| 391 | }); | 387 | }); |
| 392 | }, | 388 | }, |
| 393 | /** 根据角色ID查询部门树结构 */ | 389 | /** 根据角色ID查询部门树结构 */ |
| 394 | - getRoleDeptTreeselect(roleId) { | ||
| 395 | - return roleDeptTreeselect(roleId).then(response => { | 390 | + getRoleDeptTreeselect(id) { |
| 391 | + return roleDeptTreeselect(id).then(response => { | ||
| 396 | this.deptOptions = response.depts; | 392 | this.deptOptions = response.depts; |
| 397 | return response; | 393 | return response; |
| 398 | }); | 394 | }); |
| 399 | }, | 395 | }, |
| 400 | // 角色状态修改 | 396 | // 角色状态修改 |
| 401 | handleStatusChange(row) { | 397 | handleStatusChange(row) { |
| 402 | - let text = row.status === "0" ? "启用" : "停用"; | ||
| 403 | - this.$confirm('确认要"' + text + '""' + row.roleName + '"角色吗?', "警告", { | 398 | + // 此时,row 已经变成目标状态了,所以可以直接提交请求和提示 |
| 399 | + let text = row.status === SysCommonStatusEnum.ENABLE ? "启用" : "停用"; | ||
| 400 | + this.$confirm('确认要"' + text + '""' + row.name + '"角色吗?', "警告", { | ||
| 404 | confirmButtonText: "确定", | 401 | confirmButtonText: "确定", |
| 405 | cancelButtonText: "取消", | 402 | cancelButtonText: "取消", |
| 406 | type: "warning" | 403 | type: "warning" |
| 407 | }).then(function() { | 404 | }).then(function() { |
| 408 | - return changeRoleStatus(row.roleId, row.status); | 405 | + return changeRoleStatus(row.id, row.status); |
| 409 | }).then(() => { | 406 | }).then(() => { |
| 410 | this.msgSuccess(text + "成功"); | 407 | this.msgSuccess(text + "成功"); |
| 411 | }).catch(function() { | 408 | }).catch(function() { |
| 412 | - row.status = row.status === "0" ? "1" : "0"; | 409 | + // 异常时,需要将 row.status 状态重置回之前的 |
| 410 | + row.status = row.status === SysCommonStatusEnum.ENABLE ? SysCommonStatusEnum.DISABLE | ||
| 411 | + : SysCommonStatusEnum.ENABLE; | ||
| 413 | }); | 412 | }); |
| 414 | }, | 413 | }, |
| 414 | + // 角色类型字典翻译 | ||
| 415 | + typeFormat(row, column) { | ||
| 416 | + return getDictDataLabel(DICT_TYPE.SYS_ROLE_TYPE, row.type) | ||
| 417 | + }, | ||
| 415 | // 取消按钮 | 418 | // 取消按钮 |
| 416 | cancel() { | 419 | cancel() { |
| 417 | this.open = false; | 420 | this.open = false; |
| @@ -422,6 +425,11 @@ export default { | @@ -422,6 +425,11 @@ export default { | ||
| 422 | this.openDataScope = false; | 425 | this.openDataScope = false; |
| 423 | this.reset(); | 426 | this.reset(); |
| 424 | }, | 427 | }, |
| 428 | + // 取消按钮(菜单权限) | ||
| 429 | + cancelMenu() { | ||
| 430 | + this.openMenu = false; | ||
| 431 | + this.reset(); | ||
| 432 | + }, | ||
| 425 | // 表单重置 | 433 | // 表单重置 |
| 426 | reset() { | 434 | reset() { |
| 427 | if (this.$refs.menu != undefined) { | 435 | if (this.$refs.menu != undefined) { |
| @@ -432,10 +440,10 @@ export default { | @@ -432,10 +440,10 @@ export default { | ||
| 432 | this.deptExpand = true, | 440 | this.deptExpand = true, |
| 433 | this.deptNodeAll = false, | 441 | this.deptNodeAll = false, |
| 434 | this.form = { | 442 | this.form = { |
| 435 | - roleId: undefined, | ||
| 436 | - roleName: undefined, | ||
| 437 | - roleKey: undefined, | ||
| 438 | - roleSort: 0, | 443 | + id: undefined, |
| 444 | + name: undefined, | ||
| 445 | + code: undefined, | ||
| 446 | + sort: 0, | ||
| 439 | status: "0", | 447 | status: "0", |
| 440 | ids: [], | 448 | ids: [], |
| 441 | deptIds: [], | 449 | deptIds: [], |
| @@ -447,7 +455,7 @@ export default { | @@ -447,7 +455,7 @@ export default { | ||
| 447 | }, | 455 | }, |
| 448 | /** 搜索按钮操作 */ | 456 | /** 搜索按钮操作 */ |
| 449 | handleQuery() { | 457 | handleQuery() { |
| 450 | - this.queryParams.pageNum = 1; | 458 | + this.queryParams.pageNo = 1; |
| 451 | this.getList(); | 459 | this.getList(); |
| 452 | }, | 460 | }, |
| 453 | /** 重置按钮操作 */ | 461 | /** 重置按钮操作 */ |
| @@ -456,12 +464,6 @@ export default { | @@ -456,12 +464,6 @@ export default { | ||
| 456 | this.resetForm("queryForm"); | 464 | this.resetForm("queryForm"); |
| 457 | this.handleQuery(); | 465 | this.handleQuery(); |
| 458 | }, | 466 | }, |
| 459 | - // 多选框选中数据 | ||
| 460 | - handleSelectionChange(selection) { | ||
| 461 | - this.ids = selection.map(item => item.roleId) | ||
| 462 | - this.single = selection.length!=1 | ||
| 463 | - this.multiple = !selection.length | ||
| 464 | - }, | ||
| 465 | // 树权限(展开/折叠) | 467 | // 树权限(展开/折叠) |
| 466 | handleCheckedTreeExpand(value, type) { | 468 | handleCheckedTreeExpand(value, type) { |
| 467 | if (type == 'menu') { | 469 | if (type == 'menu') { |
| @@ -495,31 +497,50 @@ export default { | @@ -495,31 +497,50 @@ export default { | ||
| 495 | /** 新增按钮操作 */ | 497 | /** 新增按钮操作 */ |
| 496 | handleAdd() { | 498 | handleAdd() { |
| 497 | this.reset(); | 499 | this.reset(); |
| 498 | - this.getMenuTreeselect(); | ||
| 499 | this.open = true; | 500 | this.open = true; |
| 500 | this.title = "添加角色"; | 501 | this.title = "添加角色"; |
| 501 | }, | 502 | }, |
| 502 | /** 修改按钮操作 */ | 503 | /** 修改按钮操作 */ |
| 503 | handleUpdate(row) { | 504 | handleUpdate(row) { |
| 504 | this.reset(); | 505 | this.reset(); |
| 505 | - const roleId = row.roleId || this.ids | ||
| 506 | - const roleMenu = this.getRoleMenuTreeselect(roleId); | ||
| 507 | - getRole(roleId).then(response => { | 506 | + const id = row.id |
| 507 | + getRole(id).then(response => { | ||
| 508 | this.form = response.data; | 508 | this.form = response.data; |
| 509 | this.open = true; | 509 | this.open = true; |
| 510 | - this.$nextTick(() => { | ||
| 511 | - roleMenu.then(res => { | ||
| 512 | - this.$refs.menu.setCheckedKeys(res.checkedKeys); | ||
| 513 | - }); | ||
| 514 | - }); | ||
| 515 | this.title = "修改角色"; | 510 | this.title = "修改角色"; |
| 516 | }); | 511 | }); |
| 517 | }, | 512 | }, |
| 513 | + /** 分配菜单权限操作 */ | ||
| 514 | + handleMenu(row) { | ||
| 515 | + this.reset(); | ||
| 516 | + const id = row.id | ||
| 517 | + // TODO 优化 | ||
| 518 | + this.getMenuTreeselect(); | ||
| 519 | + const roleMenu = this.getRoleMenuTreeselect(id); | ||
| 520 | + this.$nextTick(() => { | ||
| 521 | + roleMenu.then(res => { | ||
| 522 | + this.$refs.menu.setCheckedKeys(res.checkedKeys); | ||
| 523 | + }); | ||
| 524 | + }); | ||
| 525 | + this.openMenu = true; | ||
| 526 | + | ||
| 527 | + // const roleDeptTreeselect = this.getRoleDeptTreeselect(row.id); | ||
| 528 | + // getRole(row.id).then(response => { | ||
| 529 | + // this.form = response.data; | ||
| 530 | + // this.openDataScope = true; | ||
| 531 | + // this.$nextTick(() => { | ||
| 532 | + // roleDeptTreeselect.then(res => { | ||
| 533 | + // this.$refs.dept.setCheckedKeys(res.checkedKeys); | ||
| 534 | + // }); | ||
| 535 | + // }); | ||
| 536 | + // this.title = "分配数据权限"; | ||
| 537 | + // }); | ||
| 538 | + }, | ||
| 518 | /** 分配数据权限操作 */ | 539 | /** 分配数据权限操作 */ |
| 519 | handleDataScope(row) { | 540 | handleDataScope(row) { |
| 520 | this.reset(); | 541 | this.reset(); |
| 521 | - const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId); | ||
| 522 | - getRole(row.roleId).then(response => { | 542 | + const roleDeptTreeselect = this.getRoleDeptTreeselect(row.id); |
| 543 | + getRole(row.id).then(response => { | ||
| 523 | this.form = response.data; | 544 | this.form = response.data; |
| 524 | this.openDataScope = true; | 545 | this.openDataScope = true; |
| 525 | this.$nextTick(() => { | 546 | this.$nextTick(() => { |
| @@ -534,15 +555,17 @@ export default { | @@ -534,15 +555,17 @@ export default { | ||
| 534 | submitForm: function() { | 555 | submitForm: function() { |
| 535 | this.$refs["form"].validate(valid => { | 556 | this.$refs["form"].validate(valid => { |
| 536 | if (valid) { | 557 | if (valid) { |
| 537 | - if (this.form.roleId != undefined) { | ||
| 538 | - this.form.ids = this.getMenuAllCheckedKeys(); | 558 | + if (this.form.id !== undefined) { |
| 559 | + // TODO 芋艿:需要迁移 | ||
| 560 | + // this.form.ids = this.getMenuAllCheckedKeys(); | ||
| 539 | updateRole(this.form).then(response => { | 561 | updateRole(this.form).then(response => { |
| 540 | this.msgSuccess("修改成功"); | 562 | this.msgSuccess("修改成功"); |
| 541 | this.open = false; | 563 | this.open = false; |
| 542 | this.getList(); | 564 | this.getList(); |
| 543 | }); | 565 | }); |
| 544 | } else { | 566 | } else { |
| 545 | - this.form.ids = this.getMenuAllCheckedKeys(); | 567 | + // TODO 芋艿:需要迁移 |
| 568 | + // this.form.ids = this.getMenuAllCheckedKeys(); | ||
| 546 | addRole(this.form).then(response => { | 569 | addRole(this.form).then(response => { |
| 547 | this.msgSuccess("新增成功"); | 570 | this.msgSuccess("新增成功"); |
| 548 | this.open = false; | 571 | this.open = false; |
| @@ -554,7 +577,19 @@ export default { | @@ -554,7 +577,19 @@ export default { | ||
| 554 | }, | 577 | }, |
| 555 | /** 提交按钮(数据权限) */ | 578 | /** 提交按钮(数据权限) */ |
| 556 | submitDataScope: function() { | 579 | submitDataScope: function() { |
| 557 | - if (this.form.roleId != undefined) { | 580 | + if (this.form.id != undefined) { |
| 581 | + this.form.deptIds = this.getDeptAllCheckedKeys(); | ||
| 582 | + dataScope(this.form).then(response => { | ||
| 583 | + this.msgSuccess("修改成功"); | ||
| 584 | + this.openDataScope = false; | ||
| 585 | + this.getList(); | ||
| 586 | + }); | ||
| 587 | + } | ||
| 588 | + }, | ||
| 589 | + /** 提交按钮(菜单权限) */ | ||
| 590 | + submitMenu: function() { | ||
| 591 | + // TODO 需要改动下 | ||
| 592 | + if (this.form.id != undefined) { | ||
| 558 | this.form.deptIds = this.getDeptAllCheckedKeys(); | 593 | this.form.deptIds = this.getDeptAllCheckedKeys(); |
| 559 | dataScope(this.form).then(response => { | 594 | dataScope(this.form).then(response => { |
| 560 | this.msgSuccess("修改成功"); | 595 | this.msgSuccess("修改成功"); |
| @@ -565,13 +600,13 @@ export default { | @@ -565,13 +600,13 @@ export default { | ||
| 565 | }, | 600 | }, |
| 566 | /** 删除按钮操作 */ | 601 | /** 删除按钮操作 */ |
| 567 | handleDelete(row) { | 602 | handleDelete(row) { |
| 568 | - const roleIds = row.roleId || this.ids; | ||
| 569 | - this.$confirm('是否确认删除角色编号为"' + roleIds + '"的数据项?', "警告", { | 603 | + const ids = row.id || this.ids; |
| 604 | + this.$confirm('是否确认删除角色编号为"' + ids + '"的数据项?', "警告", { | ||
| 570 | confirmButtonText: "确定", | 605 | confirmButtonText: "确定", |
| 571 | cancelButtonText: "取消", | 606 | cancelButtonText: "取消", |
| 572 | type: "warning" | 607 | type: "warning" |
| 573 | }).then(function() { | 608 | }).then(function() { |
| 574 | - return delRole(roleIds); | 609 | + return delRole(ids); |
| 575 | }).then(() => { | 610 | }).then(() => { |
| 576 | this.getList(); | 611 | this.getList(); |
| 577 | this.msgSuccess("删除成功"); | 612 | this.msgSuccess("删除成功"); |
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java
| @@ -2,16 +2,12 @@ package cn.iocoder.dashboard.modules.system.controller.permission; | @@ -2,16 +2,12 @@ package cn.iocoder.dashboard.modules.system.controller.permission; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.dashboard.common.pojo.CommonResult; | 3 | import cn.iocoder.dashboard.common.pojo.CommonResult; |
| 4 | import cn.iocoder.dashboard.common.pojo.PageResult; | 4 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 5 | -import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleCreateReqVO; | ||
| 6 | -import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRolePageReqVO; | ||
| 7 | -import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleRespVO; | ||
| 8 | -import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleUpdateReqVO; | 5 | +import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.*; |
| 9 | import cn.iocoder.dashboard.modules.system.convert.permission.SysRoleConvert; | 6 | import cn.iocoder.dashboard.modules.system.convert.permission.SysRoleConvert; |
| 10 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO; | 7 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO; |
| 11 | import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService; | 8 | import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService; |
| 12 | import io.swagger.annotations.Api; | 9 | import io.swagger.annotations.Api; |
| 13 | import io.swagger.annotations.ApiImplicitParam; | 10 | import io.swagger.annotations.ApiImplicitParam; |
| 14 | -import io.swagger.annotations.ApiImplicitParams; | ||
| 15 | import io.swagger.annotations.ApiOperation; | 11 | import io.swagger.annotations.ApiOperation; |
| 16 | import org.springframework.validation.annotation.Validated; | 12 | import org.springframework.validation.annotation.Validated; |
| 17 | import org.springframework.web.bind.annotation.*; | 13 | import org.springframework.web.bind.annotation.*; |
| @@ -82,14 +78,10 @@ public class SysRoleController { | @@ -82,14 +78,10 @@ public class SysRoleController { | ||
| 82 | 78 | ||
| 83 | @ApiOperation("修改角色状态") | 79 | @ApiOperation("修改角色状态") |
| 84 | @PostMapping("/update-status") | 80 | @PostMapping("/update-status") |
| 85 | - @ApiImplicitParams(value = { | ||
| 86 | - @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1024"), | ||
| 87 | - @ApiImplicitParam(name = "status", value = "状态", required = true, example = "1") | ||
| 88 | - }) | ||
| 89 | // @PreAuthorize("@ss.hasPermi('system:role:edit')") | 81 | // @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| 90 | // @Log(title = "角色管理", businessType = BusinessType.UPDATE) | 82 | // @Log(title = "角色管理", businessType = BusinessType.UPDATE) |
| 91 | - public CommonResult<Boolean> updateRoleStatus(@RequestParam("id") Long id, @RequestParam("status") Integer status) { | ||
| 92 | - roleService.updateRoleStatus(id, status); | 83 | + public CommonResult<Boolean> updateRoleStatus(@Validated @RequestBody SysRoleUpdateStatusReqVO reqVO) { |
| 84 | + roleService.updateRoleStatus(reqVO.getId(), reqVO.getStatus()); | ||
| 93 | return success(true); | 85 | return success(true); |
| 94 | } | 86 | } |
| 95 | 87 |
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRoleBaseVO.java
| @@ -30,4 +30,7 @@ public class SysRoleBaseVO { | @@ -30,4 +30,7 @@ public class SysRoleBaseVO { | ||
| 30 | @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "见 RoleTypeEnum 枚举") | 30 | @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "见 RoleTypeEnum 枚举") |
| 31 | private Integer type; | 31 | private Integer type; |
| 32 | 32 | ||
| 33 | + @ApiModelProperty(value = "备注", example = "我是一个角色") | ||
| 34 | + private String remark; | ||
| 35 | + | ||
| 33 | } | 36 | } |
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRoleRespVO.java
| @@ -28,9 +28,6 @@ public class SysRoleRespVO extends SysRoleBaseVO { | @@ -28,9 +28,6 @@ public class SysRoleRespVO extends SysRoleBaseVO { | ||
| 28 | @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "参见 RoleTypeEnum 枚举类") | 28 | @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "参见 RoleTypeEnum 枚举类") |
| 29 | private Integer type; | 29 | private Integer type; |
| 30 | 30 | ||
| 31 | - @ApiModelProperty(value = "备注", example = "我是一个角色") | ||
| 32 | - private String remark; | ||
| 33 | - | ||
| 34 | @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") | 31 | @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") |
| 35 | private Date createTime; | 32 | private Date createTime; |
| 36 | 33 |
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRoleUpdateStatusReqVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.system.controller.permission.vo.role; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +import javax.validation.constraints.NotNull; | ||
| 8 | + | ||
| 9 | +@ApiModel("角色更新状态 Request VO") | ||
| 10 | +@Data | ||
| 11 | +public class SysRoleUpdateStatusReqVO { | ||
| 12 | + | ||
| 13 | + @ApiModelProperty(value = "用户编号", required = true, example = "1024") | ||
| 14 | + @NotNull(message = "角色编号不能为空") | ||
| 15 | + private Long id; | ||
| 16 | + | ||
| 17 | + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举") | ||
| 18 | + @NotNull(message = "状态不能为空") | ||
| 19 | +// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") | ||
| 20 | + private Integer status; | ||
| 21 | + | ||
| 22 | +} |
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java
| @@ -105,15 +105,8 @@ public class SysRoleServiceImpl implements SysRoleService { | @@ -105,15 +105,8 @@ public class SysRoleServiceImpl implements SysRoleService { | ||
| 105 | 105 | ||
| 106 | @Override | 106 | @Override |
| 107 | public void updateRole(SysRoleUpdateReqVO reqVO) { | 107 | public void updateRole(SysRoleUpdateReqVO reqVO) { |
| 108 | - // 校验更新的角色是否存在 | ||
| 109 | - SysRoleDO role = roleMapper.selectById(reqVO.getId()); | ||
| 110 | - if (roleMapper.selectById(reqVO.getId()) == null) { | ||
| 111 | - throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS); | ||
| 112 | - } | ||
| 113 | - // 内置角色,不允许修改 | ||
| 114 | - if (RoleTypeEnum.SYSTEM.getType().equals(role.getType())) { | ||
| 115 | - throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE); | ||
| 116 | - } | 108 | + // 校验是否可以更新 |
| 109 | + this.checkUpdateRole(reqVO.getId()); | ||
| 117 | // 校验角色的唯一字段是否重复 | 110 | // 校验角色的唯一字段是否重复 |
| 118 | checkDuplicateRole(reqVO.getName(), reqVO.getCode(), reqVO.getId()); | 111 | checkDuplicateRole(reqVO.getName(), reqVO.getCode(), reqVO.getId()); |
| 119 | // 更新到数据库 | 112 | // 更新到数据库 |
| @@ -123,15 +116,8 @@ public class SysRoleServiceImpl implements SysRoleService { | @@ -123,15 +116,8 @@ public class SysRoleServiceImpl implements SysRoleService { | ||
| 123 | 116 | ||
| 124 | @Override | 117 | @Override |
| 125 | public void deleteRole(Long id) { | 118 | public void deleteRole(Long id) { |
| 126 | - // 校验删除的角色是否存在 | ||
| 127 | - SysRoleDO roleDO = roleMapper.selectById(id); | ||
| 128 | - if (roleMapper.selectById(id) == null) { | ||
| 129 | - throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS); | ||
| 130 | - } | ||
| 131 | - // 内置角色,不允许删除 | ||
| 132 | - if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { | ||
| 133 | - throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE); | ||
| 134 | - } | 119 | + // 校验是否可以更新 |
| 120 | + this.checkUpdateRole(id); | ||
| 135 | // 标记删除 | 121 | // 标记删除 |
| 136 | roleMapper.deleteById(id); | 122 | roleMapper.deleteById(id); |
| 137 | // 删除相关数据 | 123 | // 删除相关数据 |
| @@ -152,11 +138,9 @@ public class SysRoleServiceImpl implements SysRoleService { | @@ -152,11 +138,9 @@ public class SysRoleServiceImpl implements SysRoleService { | ||
| 152 | 138 | ||
| 153 | @Override | 139 | @Override |
| 154 | public void updateRoleStatus(Long id, Integer status) { | 140 | public void updateRoleStatus(Long id, Integer status) { |
| 155 | - // 校验修改的角色是否存在 | ||
| 156 | - SysRoleDO roleDO = roleMapper.selectById(id); | ||
| 157 | - if (roleMapper.selectById(id) == null) { | ||
| 158 | - throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS); | ||
| 159 | - } | 141 | + // 校验是否可以更新 |
| 142 | + this.checkUpdateRole(id); | ||
| 143 | + // 更新状态 | ||
| 160 | SysRoleDO updateObject = new SysRoleDO(); | 144 | SysRoleDO updateObject = new SysRoleDO(); |
| 161 | updateObject.setId(id); | 145 | updateObject.setId(id); |
| 162 | updateObject.setStatus(status); | 146 | updateObject.setStatus(status); |
| @@ -190,4 +174,20 @@ public class SysRoleServiceImpl implements SysRoleService { | @@ -190,4 +174,20 @@ public class SysRoleServiceImpl implements SysRoleService { | ||
| 190 | } | 174 | } |
| 191 | } | 175 | } |
| 192 | 176 | ||
| 177 | + /** | ||
| 178 | + * 校验角色是否可以被更新 | ||
| 179 | + * | ||
| 180 | + * @param id 角色编号 | ||
| 181 | + */ | ||
| 182 | + private void checkUpdateRole(Long id) { | ||
| 183 | + SysRoleDO roleDO = roleMapper.selectById(id); | ||
| 184 | + if (roleDO == null) { | ||
| 185 | + throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS); | ||
| 186 | + } | ||
| 187 | + // 内置角色,不允许删除 | ||
| 188 | + if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { | ||
| 189 | + throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE); | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | } | 193 | } |