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 | 3 | // 查询角色列表 |
| 4 | 4 | export function listRole(query) { |
| 5 | 5 | return request({ |
| 6 | - url: '/system/role/list', | |
| 6 | + url: '/system/role/page', | |
| 7 | 7 | method: 'get', |
| 8 | 8 | params: query |
| 9 | 9 | }) |
| ... | ... | @@ -12,7 +12,7 @@ export function listRole(query) { |
| 12 | 12 | // 查询角色详细 |
| 13 | 13 | export function getRole(roleId) { |
| 14 | 14 | return request({ |
| 15 | - url: '/system/role/' + roleId, | |
| 15 | + url: '/system/role/get?id=' + roleId, | |
| 16 | 16 | method: 'get' |
| 17 | 17 | }) |
| 18 | 18 | } |
| ... | ... | @@ -20,7 +20,7 @@ export function getRole(roleId) { |
| 20 | 20 | // 新增角色 |
| 21 | 21 | export function addRole(data) { |
| 22 | 22 | return request({ |
| 23 | - url: '/system/role', | |
| 23 | + url: '/system/role/create', | |
| 24 | 24 | method: 'post', |
| 25 | 25 | data: data |
| 26 | 26 | }) |
| ... | ... | @@ -29,8 +29,8 @@ export function addRole(data) { |
| 29 | 29 | // 修改角色 |
| 30 | 30 | export function updateRole(data) { |
| 31 | 31 | return request({ |
| 32 | - url: '/system/role', | |
| 33 | - method: 'put', | |
| 32 | + url: '/system/role/update', | |
| 33 | + method: 'post', | |
| 34 | 34 | data: data |
| 35 | 35 | }) |
| 36 | 36 | } |
| ... | ... | @@ -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 | 49 | const data = { |
| 50 | - roleId, | |
| 50 | + id, | |
| 51 | 51 | status |
| 52 | 52 | } |
| 53 | 53 | return request({ |
| 54 | - url: '/system/role/changeStatus', | |
| 55 | - method: 'put', | |
| 54 | + url: '/system/role/update-status', | |
| 55 | + method: 'post', | |
| 56 | 56 | data: data |
| 57 | 57 | }) |
| 58 | 58 | } |
| ... | ... | @@ -60,8 +60,8 @@ export function changeRoleStatus(roleId, status) { |
| 60 | 60 | // 删除角色 |
| 61 | 61 | export function delRole(roleId) { |
| 62 | 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 | 72 | method: 'get', |
| 73 | 73 | params: query |
| 74 | 74 | }) |
| 75 | -} | |
| 76 | 75 | \ No newline at end of file |
| 76 | +} | ... | ... |
ruoyi-ui/src/utils/dict.js
ruoyi-ui/src/views/system/menu/index.vue
| ... | ... | @@ -14,9 +14,9 @@ |
| 14 | 14 | <el-select v-model="queryParams.status" placeholder="菜单状态" clearable size="small"> |
| 15 | 15 | <el-option |
| 16 | 16 | v-for="dict in statusDictDatas" |
| 17 | - :key="dict.value" | |
| 17 | + :key="parseInt(dict.value)" | |
| 18 | 18 | :label="dict.label" |
| 19 | - :value="dict.value" | |
| 19 | + :value="parseInt(dict.value)" | |
| 20 | 20 | /> |
| 21 | 21 | </el-select> |
| 22 | 22 | </el-form-item> | ... | ... |
ruoyi-ui/src/views/system/role/index.vue
| 1 | 1 | <template> |
| 2 | 2 | <div class="app-container"> |
| 3 | 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 | 5 | <el-input |
| 6 | - v-model="queryParams.roleName" | |
| 6 | + v-model="queryParams.name" | |
| 7 | 7 | placeholder="请输入角色名称" |
| 8 | 8 | clearable |
| 9 | 9 | size="small" |
| ... | ... | @@ -11,10 +11,10 @@ |
| 11 | 11 | @keyup.enter.native="handleQuery" |
| 12 | 12 | /> |
| 13 | 13 | </el-form-item> |
| 14 | - <el-form-item label="权限字符" prop="roleKey"> | |
| 14 | + <el-form-item label="角色标识" prop="code"> | |
| 15 | 15 | <el-input |
| 16 | - v-model="queryParams.roleKey" | |
| 17 | - placeholder="请输入权限字符" | |
| 16 | + v-model="queryParams.code" | |
| 17 | + placeholder="请输入角色标识" | |
| 18 | 18 | clearable |
| 19 | 19 | size="small" |
| 20 | 20 | style="width: 240px" |
| ... | ... | @@ -30,10 +30,10 @@ |
| 30 | 30 | style="width: 240px" |
| 31 | 31 | > |
| 32 | 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 | 38 | </el-select> |
| 39 | 39 | </el-form-item> |
| ... | ... | @@ -67,26 +67,6 @@ |
| 67 | 67 | </el-col> |
| 68 | 68 | <el-col :span="1.5"> |
| 69 | 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 | 70 | type="warning" |
| 91 | 71 | icon="el-icon-download" |
| 92 | 72 | size="mini" |
| ... | ... | @@ -97,18 +77,18 @@ |
| 97 | 77 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 98 | 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 | 86 | <el-table-column label="状态" align="center" width="100"> |
| 107 | 87 | <template slot-scope="scope"> |
| 108 | 88 | <el-switch |
| 109 | 89 | v-model="scope.row.status" |
| 110 | - active-value="0" | |
| 111 | - inactive-value="1" | |
| 90 | + :active-value="0" | |
| 91 | + :inactive-value="1" | |
| 112 | 92 | @change="handleStatusChange(scope.row)" |
| 113 | 93 | ></el-switch> |
| 114 | 94 | </template> |
| ... | ... | @@ -128,6 +108,13 @@ |
| 128 | 108 | v-hasPermi="['system:role:edit']" |
| 129 | 109 | >修改</el-button> |
| 130 | 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 | 118 | size="mini" |
| 132 | 119 | type="text" |
| 133 | 120 | icon="el-icon-circle-check" |
| ... | ... | @@ -156,38 +143,14 @@ |
| 156 | 143 | <!-- 添加或修改角色配置对话框 --> |
| 157 | 144 | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> |
| 158 | 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 | 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 | 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 | 154 | </el-form-item> |
| 192 | 155 | <el-form-item label="备注"> |
| 193 | 156 | <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input> |
| ... | ... | @@ -199,14 +162,14 @@ |
| 199 | 162 | </div> |
| 200 | 163 | </el-dialog> |
| 201 | 164 | |
| 202 | - <!-- 分配角色数据权限对话框 --> | |
| 165 | + <!-- 分配角色的数据权限对话框 --> | |
| 203 | 166 | <el-dialog :title="title" :visible.sync="openDataScope" width="500px" append-to-body> |
| 204 | 167 | <el-form :model="form" label-width="80px"> |
| 205 | 168 | <el-form-item label="角色名称"> |
| 206 | - <el-input v-model="form.roleName" :disabled="true" /> | |
| 169 | + <el-input v-model="form.name" :disabled="true" /> | |
| 207 | 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 | 173 | </el-form-item> |
| 211 | 174 | <el-form-item label="权限范围"> |
| 212 | 175 | <el-select v-model="form.dataScope"> |
| ... | ... | @@ -240,6 +203,37 @@ |
| 240 | 203 | <el-button @click="cancelDataScope">取 消</el-button> |
| 241 | 204 | </div> |
| 242 | 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 | 237 | </div> |
| 244 | 238 | </template> |
| 245 | 239 | |
| ... | ... | @@ -247,6 +241,8 @@ |
| 247 | 241 | import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role"; |
| 248 | 242 | import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu"; |
| 249 | 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 | 247 | export default { |
| 252 | 248 | name: "Role", |
| ... | ... | @@ -254,12 +250,6 @@ export default { |
| 254 | 250 | return { |
| 255 | 251 | // 遮罩层 |
| 256 | 252 | loading: true, |
| 257 | - // 选中数组 | |
| 258 | - ids: [], | |
| 259 | - // 非单个禁用 | |
| 260 | - single: true, | |
| 261 | - // 非多个禁用 | |
| 262 | - multiple: true, | |
| 263 | 253 | // 显示搜索条件 |
| 264 | 254 | showSearch: true, |
| 265 | 255 | // 总条数 |
| ... | ... | @@ -272,6 +262,9 @@ export default { |
| 272 | 262 | open: false, |
| 273 | 263 | // 是否显示弹出层(数据权限) |
| 274 | 264 | openDataScope: false, |
| 265 | + // 是否显示弹出层(菜单权限) | |
| 266 | + openMenu: false, | |
| 267 | + // TODO 需要简化下 | |
| 275 | 268 | menuExpand: false, |
| 276 | 269 | menuNodeAll: false, |
| 277 | 270 | deptExpand: true, |
| ... | ... | @@ -309,10 +302,10 @@ export default { |
| 309 | 302 | deptOptions: [], |
| 310 | 303 | // 查询参数 |
| 311 | 304 | queryParams: { |
| 312 | - pageNum: 1, | |
| 305 | + pageNo: 1, | |
| 313 | 306 | pageSize: 10, |
| 314 | - roleName: undefined, | |
| 315 | - roleKey: undefined, | |
| 307 | + name: undefined, | |
| 308 | + code: undefined, | |
| 316 | 309 | status: undefined |
| 317 | 310 | }, |
| 318 | 311 | // 表单参数 |
| ... | ... | @@ -323,23 +316,26 @@ export default { |
| 323 | 316 | }, |
| 324 | 317 | // 表单校验 |
| 325 | 318 | rules: { |
| 326 | - roleName: [ | |
| 319 | + name: [ | |
| 327 | 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 | 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 | 337 | created() { |
| 339 | 338 | this.getList(); |
| 340 | - this.getDicts("sys_normal_disable").then(response => { | |
| 341 | - this.statusOptions = response.data; | |
| 342 | - }); | |
| 343 | 339 | }, |
| 344 | 340 | methods: { |
| 345 | 341 | /** 查询角色列表 */ |
| ... | ... | @@ -347,8 +343,8 @@ export default { |
| 347 | 343 | this.loading = true; |
| 348 | 344 | listRole(this.addDateRange(this.queryParams, this.dateRange)).then( |
| 349 | 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 | 348 | this.loading = false; |
| 353 | 349 | } |
| 354 | 350 | ); |
| ... | ... | @@ -384,34 +380,41 @@ export default { |
| 384 | 380 | return checkedKeys; |
| 385 | 381 | }, |
| 386 | 382 | /** 根据角色ID查询菜单树结构 */ |
| 387 | - getRoleMenuTreeselect(roleId) { | |
| 388 | - return roleMenuTreeselect(roleId).then(response => { | |
| 383 | + getRoleMenuTreeselect(id) { | |
| 384 | + return roleMenuTreeselect(id).then(response => { | |
| 389 | 385 | this.menuOptions = response.menus; |
| 390 | 386 | return response; |
| 391 | 387 | }); |
| 392 | 388 | }, |
| 393 | 389 | /** 根据角色ID查询部门树结构 */ |
| 394 | - getRoleDeptTreeselect(roleId) { | |
| 395 | - return roleDeptTreeselect(roleId).then(response => { | |
| 390 | + getRoleDeptTreeselect(id) { | |
| 391 | + return roleDeptTreeselect(id).then(response => { | |
| 396 | 392 | this.deptOptions = response.depts; |
| 397 | 393 | return response; |
| 398 | 394 | }); |
| 399 | 395 | }, |
| 400 | 396 | // 角色状态修改 |
| 401 | 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 | 401 | confirmButtonText: "确定", |
| 405 | 402 | cancelButtonText: "取消", |
| 406 | 403 | type: "warning" |
| 407 | 404 | }).then(function() { |
| 408 | - return changeRoleStatus(row.roleId, row.status); | |
| 405 | + return changeRoleStatus(row.id, row.status); | |
| 409 | 406 | }).then(() => { |
| 410 | 407 | this.msgSuccess(text + "成功"); |
| 411 | 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 | 419 | cancel() { |
| 417 | 420 | this.open = false; |
| ... | ... | @@ -422,6 +425,11 @@ export default { |
| 422 | 425 | this.openDataScope = false; |
| 423 | 426 | this.reset(); |
| 424 | 427 | }, |
| 428 | + // 取消按钮(菜单权限) | |
| 429 | + cancelMenu() { | |
| 430 | + this.openMenu = false; | |
| 431 | + this.reset(); | |
| 432 | + }, | |
| 425 | 433 | // 表单重置 |
| 426 | 434 | reset() { |
| 427 | 435 | if (this.$refs.menu != undefined) { |
| ... | ... | @@ -432,10 +440,10 @@ export default { |
| 432 | 440 | this.deptExpand = true, |
| 433 | 441 | this.deptNodeAll = false, |
| 434 | 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 | 447 | status: "0", |
| 440 | 448 | ids: [], |
| 441 | 449 | deptIds: [], |
| ... | ... | @@ -447,7 +455,7 @@ export default { |
| 447 | 455 | }, |
| 448 | 456 | /** 搜索按钮操作 */ |
| 449 | 457 | handleQuery() { |
| 450 | - this.queryParams.pageNum = 1; | |
| 458 | + this.queryParams.pageNo = 1; | |
| 451 | 459 | this.getList(); |
| 452 | 460 | }, |
| 453 | 461 | /** 重置按钮操作 */ |
| ... | ... | @@ -456,12 +464,6 @@ export default { |
| 456 | 464 | this.resetForm("queryForm"); |
| 457 | 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 | 468 | handleCheckedTreeExpand(value, type) { |
| 467 | 469 | if (type == 'menu') { |
| ... | ... | @@ -495,31 +497,50 @@ export default { |
| 495 | 497 | /** 新增按钮操作 */ |
| 496 | 498 | handleAdd() { |
| 497 | 499 | this.reset(); |
| 498 | - this.getMenuTreeselect(); | |
| 499 | 500 | this.open = true; |
| 500 | 501 | this.title = "添加角色"; |
| 501 | 502 | }, |
| 502 | 503 | /** 修改按钮操作 */ |
| 503 | 504 | handleUpdate(row) { |
| 504 | 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 | 508 | this.form = response.data; |
| 509 | 509 | this.open = true; |
| 510 | - this.$nextTick(() => { | |
| 511 | - roleMenu.then(res => { | |
| 512 | - this.$refs.menu.setCheckedKeys(res.checkedKeys); | |
| 513 | - }); | |
| 514 | - }); | |
| 515 | 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 | 540 | handleDataScope(row) { |
| 520 | 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 | 544 | this.form = response.data; |
| 524 | 545 | this.openDataScope = true; |
| 525 | 546 | this.$nextTick(() => { |
| ... | ... | @@ -534,15 +555,17 @@ export default { |
| 534 | 555 | submitForm: function() { |
| 535 | 556 | this.$refs["form"].validate(valid => { |
| 536 | 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 | 561 | updateRole(this.form).then(response => { |
| 540 | 562 | this.msgSuccess("修改成功"); |
| 541 | 563 | this.open = false; |
| 542 | 564 | this.getList(); |
| 543 | 565 | }); |
| 544 | 566 | } else { |
| 545 | - this.form.ids = this.getMenuAllCheckedKeys(); | |
| 567 | + // TODO 芋艿:需要迁移 | |
| 568 | + // this.form.ids = this.getMenuAllCheckedKeys(); | |
| 546 | 569 | addRole(this.form).then(response => { |
| 547 | 570 | this.msgSuccess("新增成功"); |
| 548 | 571 | this.open = false; |
| ... | ... | @@ -554,7 +577,19 @@ export default { |
| 554 | 577 | }, |
| 555 | 578 | /** 提交按钮(数据权限) */ |
| 556 | 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 | 593 | this.form.deptIds = this.getDeptAllCheckedKeys(); |
| 559 | 594 | dataScope(this.form).then(response => { |
| 560 | 595 | this.msgSuccess("修改成功"); |
| ... | ... | @@ -565,13 +600,13 @@ export default { |
| 565 | 600 | }, |
| 566 | 601 | /** 删除按钮操作 */ |
| 567 | 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 | 605 | confirmButtonText: "确定", |
| 571 | 606 | cancelButtonText: "取消", |
| 572 | 607 | type: "warning" |
| 573 | 608 | }).then(function() { |
| 574 | - return delRole(roleIds); | |
| 609 | + return delRole(ids); | |
| 575 | 610 | }).then(() => { |
| 576 | 611 | this.getList(); |
| 577 | 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 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.common.pojo.CommonResult; |
| 4 | 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 | 6 | import cn.iocoder.dashboard.modules.system.convert.permission.SysRoleConvert; |
| 10 | 7 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO; |
| 11 | 8 | import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService; |
| 12 | 9 | import io.swagger.annotations.Api; |
| 13 | 10 | import io.swagger.annotations.ApiImplicitParam; |
| 14 | -import io.swagger.annotations.ApiImplicitParams; | |
| 15 | 11 | import io.swagger.annotations.ApiOperation; |
| 16 | 12 | import org.springframework.validation.annotation.Validated; |
| 17 | 13 | import org.springframework.web.bind.annotation.*; |
| ... | ... | @@ -82,14 +78,10 @@ public class SysRoleController { |
| 82 | 78 | |
| 83 | 79 | @ApiOperation("修改角色状态") |
| 84 | 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 | 81 | // @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| 90 | 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 | 85 | return success(true); |
| 94 | 86 | } |
| 95 | 87 | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRoleBaseVO.java
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRoleRespVO.java
| ... | ... | @@ -28,9 +28,6 @@ public class SysRoleRespVO extends SysRoleBaseVO { |
| 28 | 28 | @ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "参见 RoleTypeEnum 枚举类") |
| 29 | 29 | private Integer type; |
| 30 | 30 | |
| 31 | - @ApiModelProperty(value = "备注", example = "我是一个角色") | |
| 32 | - private String remark; | |
| 33 | - | |
| 34 | 31 | @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") |
| 35 | 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 | 105 | |
| 106 | 106 | @Override |
| 107 | 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 | 111 | checkDuplicateRole(reqVO.getName(), reqVO.getCode(), reqVO.getId()); |
| 119 | 112 | // 更新到数据库 |
| ... | ... | @@ -123,15 +116,8 @@ public class SysRoleServiceImpl implements SysRoleService { |
| 123 | 116 | |
| 124 | 117 | @Override |
| 125 | 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 | 122 | roleMapper.deleteById(id); |
| 137 | 123 | // 删除相关数据 |
| ... | ... | @@ -152,11 +138,9 @@ public class SysRoleServiceImpl implements SysRoleService { |
| 152 | 138 | |
| 153 | 139 | @Override |
| 154 | 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 | 144 | SysRoleDO updateObject = new SysRoleDO(); |
| 161 | 145 | updateObject.setId(id); |
| 162 | 146 | updateObject.setStatus(status); |
| ... | ... | @@ -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 | } | ... | ... |