index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. <template>
  2. <div class="page-container">
  3. <div class="content-container">
  4. <div class="main">
  5. <div class="table-nav">
  6. <div class="tags">
  7. <div class="tag" :class="{ activeClass: over == 1 }" @click="getRole">角色</div>
  8. <div class="tag" :class="{ activeClass: over == 2 }" @click="getFunctionalAuthority">功能权限</div>
  9. <div class="tag" :class="{ activeClass: over == 3 }" @click="getHeaderPermission">表头权限</div>
  10. </div>
  11. <div class="actions">
  12. <el-button type="primary" icon="el-icon-plus" size="mini " @click="handleAdd" v-show="roleShow" v-hasPermi="['system:role:add']">添加</el-button>
  13. </div>
  14. </div>
  15. <!-- 角色列表 -->
  16. <el-table v-loading="loading" :data="roleList" :cell-style="{ cursor: 'pointer' }" border @row-click="roleLineClick" v-show="roleShow">
  17. <el-table-column label="名称" prop="roleName" width="200">
  18. <template slot-scope="scope">
  19. <a href="javascript:void(0);" class="linked" @click="roleLineDbclick(scope.row)">{{ scope.row.roleName }}</a>
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="描述" prop="remark" />
  23. <el-table-column align="center" label="创建时间" prop="createTime" width="200">
  24. <template slot-scope="scope">
  25. <span>{{ parseTime(scope.row.createTime) }}</span>
  26. </template>
  27. </el-table-column>
  28. <el-table-column align="center" label="状态" width="117" prop="status">
  29. <template slot-scope="scope">
  30. <span>{{ scope.row.status == 0 ? '正常' : '停用' }}</span>
  31. </template>
  32. </el-table-column>
  33. <el-table-column align="center" label="操作" class-name="small-padding fixed-width" width="300">
  34. <template slot-scope="scope">
  35. <el-button size="mini" type="text" icon="el-icon-edit" v-hasPermi="['system:role:edit']" @click="handleUpdate(scope.row)">修改</el-button>
  36. <el-button size="mini" type="text" icon="el-icon-remove-outline" @click="handleStatusChange(scope.row)">{{ scope.row.status == '0' ? '禁用' : '启用' }}</el-button>
  37. <el-button size="mini" type="text" icon="el-icon-delete-solid" v-hasPermi="['system:role:remove']" @click="handleDelete(scope.row)">删除</el-button>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <!-- 功能权限列表 -->
  42. <el-table
  43. v-loading="loading"
  44. :data="FuncListTree"
  45. row-key="menuId"
  46. :tree-props="{ children: 'children' }"
  47. border
  48. :cell-style="{ cursor: 'pointer' }"
  49. @row-click="functionalLineClick"
  50. v-show="functionalShow"
  51. >
  52. <el-table-column label="名称" prop="menuName" width="200">
  53. <template slot-scope="scope">
  54. <a href="javascript:void(0);" class="linked" @click="functionalLineDbclick(scope.row)">{{ scope.row.menuName }}</a>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="描述" prop="remark" width="231" />
  58. <el-table-column label="权限" prop="createTime" width="55" align="center">
  59. <template slot-scope="scope">
  60. <span><input type="checkbox" :checked="isChecked(scope.row)" @change="handleCheckedTreeConnect($event, 'menu', scope.row)" /></span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="操作" class-name="small-padding fixed-width">
  64. <template slot-scope="scope">
  65. <el-button
  66. size="mini"
  67. type="text"
  68. :style="{ color: checkedKeys.includes(item.menuId) ? '#409EFF' : '#909399' }"
  69. v-for="(item, index) in btnListss(scope.row.menuId)"
  70. :key="index"
  71. @click="updateBtn(item, scope.row)"
  72. ><span>{{ item.menuName }}</span>
  73. </el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <!-- 表头权限列表 -->
  78. <el-table v-loading="loading" :data="headList" border :cell-style="{ cursor: 'pointer' }" @row-click="headlLineClick" v-show="headShow">
  79. <el-table-column label="列表名称" width="200">{{ listName }}</el-table-column>
  80. <el-table-column label="列名称" prop="columnName" width="200" />
  81. <el-table-column label="状态" class-name="small-padding fixed-width">
  82. <template slot-scope="scope">
  83. <el-button
  84. size="mini"
  85. :disabled="disabled"
  86. type="text"
  87. icon="el-icon-remove-outline"
  88. :style="{ color: scope.row.isShow == 0 ? '#409EFF' : '#909399' }"
  89. @click="showOrHide(scope.row)"
  90. >显示</el-button
  91. >
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. <pagination v-show="total > 0 && roleShow" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  96. <!-- 添加或修改角色配置对话框 -->
  97. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  98. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  99. <el-form-item label="角色名称" prop="roleName">
  100. <el-input v-model="form.roleName" placeholder="请输入角色名称" />
  101. </el-form-item>
  102. <el-form-item label="状态">
  103. <el-radio-group v-model="form.status">
  104. <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{ dict.label }}</el-radio>
  105. </el-radio-group>
  106. </el-form-item>
  107. <el-form-item label="描述">
  108. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  109. </el-form-item>
  110. </el-form>
  111. <div slot="footer" class="dialog-footer">
  112. <el-button size="small" type="primary" @click="submitForm">确 定</el-button>
  113. <el-button size="small" @click="cancel">取 消</el-button>
  114. </div>
  115. </el-dialog>
  116. </div>
  117. </div>
  118. </div>
  119. </template>
  120. <script>
  121. import {
  122. listRole,
  123. getRole,
  124. delRole,
  125. addRole,
  126. updateRole,
  127. dataScope,
  128. changeRoleStatus,
  129. getRoleMenuTreeselect,
  130. saveRoleMenu,
  131. getTableHeadList,
  132. authUserCancelAll,
  133. setSysTableCfgIsShow
  134. } from '@/api/system/role'
  135. import { treeselect as menuTreeselect, roleMenuTreeselect } from '@/api/system/menu'
  136. import { treeselect as deptTreeselect, roleDeptTreeselect } from '@/api/system/dept'
  137. import pinyin from 'js-pinyin'
  138. export default {
  139. name: 'Role',
  140. dicts: ['sys_normal_disable'],
  141. data() {
  142. return {
  143. // 遮罩层
  144. loading: true,
  145. // 总条数
  146. total: 0,
  147. // 角色表格数据
  148. roleList: [],
  149. // 弹出层标题
  150. title: '',
  151. // 是否显示弹出层
  152. open: false,
  153. // 是否显示弹出层(数据权限)
  154. openDataScope: false,
  155. menuExpand: false,
  156. menuNodeAll: false,
  157. deptExpand: true,
  158. deptNodeAll: false,
  159. // 日期范围
  160. dateRange: [],
  161. // 菜单列表
  162. menuOptions: [],
  163. // 部门列表
  164. deptOptions: [],
  165. // 查询参数
  166. queryParams: {
  167. pageNum: 1,
  168. pageSize: 10,
  169. roleName: undefined,
  170. roleKey: undefined,
  171. status: undefined
  172. },
  173. // 表单参数
  174. form: {},
  175. form1: {},
  176. // 表单校验
  177. rules: {
  178. roleName: [{ required: true, message: '角色名称不能为空', trigger: 'blur' }]
  179. },
  180. roleShow: true,
  181. functionalShow: false,
  182. headShow: false,
  183. over: 1,
  184. background: '',
  185. getIndex: null,
  186. getIndex1: null,
  187. getIndex2: null,
  188. functionList: [], // 功能权限列表
  189. btnList: [], // 功能权限按钮列表
  190. headList: [],
  191. FuncList: [],
  192. FuncListTree: [],
  193. objRole: {},
  194. objFun: {},
  195. btnsLists: [],
  196. btnsList: [],
  197. checkedKeys: [],
  198. checked: false,
  199. roleId: '',
  200. listName: '',
  201. menuId: '',
  202. checkStatus: -1,
  203. disabled: false
  204. }
  205. },
  206. created() {
  207. this.getList()
  208. },
  209. filters: {},
  210. methods: {
  211. // 角色列表
  212. getRole() {
  213. this.getList()
  214. this.over = 1
  215. this.roleShow = true
  216. this.functionalShow = false
  217. this.headShow = false
  218. },
  219. // 功能权限列表
  220. getFunctionalAuthority() {
  221. this.getList()
  222. this.roleLineDbclick(this.objRole)
  223. this.headShow = false
  224. },
  225. // 表头权限;列表
  226. getHeaderPermission() {
  227. this.functionalLineDbclick(this.objFun)
  228. this.getList()
  229. },
  230. /** 查询角色列表 */
  231. getList() {
  232. this.loading = true
  233. listRole(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
  234. this.roleList = response.rows
  235. this.total = response.total
  236. this.loading = false
  237. })
  238. },
  239. // 单击角色表格某一行 行点击事件,这里获取到的行对象(row)是没有index属性的
  240. roleLineClick(row) {
  241. this.getIndex = row.index
  242. this.objRole = row
  243. },
  244. //为行对象(row)设置index属性
  245. tableRowClassName({ row, rowIndex }) {
  246. row.index = rowIndex
  247. },
  248. // 双击角色表格某一行
  249. roleLineDbclick(row) {
  250. if (JSON.stringify(row) !== '{}') {
  251. this.roleId = ''
  252. this.functionList = []
  253. this.checkedKeys = []
  254. this.btnList = []
  255. this.FuncList = []
  256. this.FuncListTree = []
  257. this.roleId = row.roleId
  258. getRoleMenuTreeselect(row.roleId).then((res) => {
  259. if (res.code === 200) {
  260. this.checkedKeys = res.data.checkedKeys
  261. this.functionList = res.data.menus
  262. this.btnList = this.functionList.filter((item, index, c) => item.menuType == 'F')
  263. this.btnsLists = this.functionList.filter((item, index, c) => item.menuType == 'C')
  264. this.FuncList = this.functionList.filter((item, index, c) => item.menuType == 'M' || item.menuType == 'C')
  265. this.FuncListTree = this.handleTree(this.FuncList, 'menuId', 'parentId')
  266. }
  267. })
  268. this.functionalShow = true
  269. this.roleShow = false
  270. this.over = 2
  271. } else {
  272. this.$notify({
  273. title: '警告',
  274. message: '请选择角色',
  275. type: 'warning'
  276. })
  277. }
  278. },
  279. // 单击功能权限表格某一行
  280. functionalLineClick(row, event, column) {
  281. if (row) {
  282. this.getIndex1 = row.index
  283. this.objFun = row
  284. }
  285. },
  286. // 双击功能权限表格某一行
  287. functionalLineDbclick(row, event, column) {
  288. this.disabled = this.isChecked(row) ? false : true
  289. this.headList = []
  290. this.functionalShow = false
  291. this.headShow = true
  292. this.over = 3
  293. this.listName = row.menuName
  294. this.menuId = row.menuId
  295. this.checkStatus = this.isChecked(row) ? 0 : 1
  296. getTableHeadList(this.roleId, row.menuId, this.checkStatus).then((res) => {
  297. this.headList = res.data
  298. })
  299. },
  300. // 单击表头权限表格某一行
  301. headlLineClick(row, event, column) {
  302. this.getIndex2 = row.index
  303. },
  304. /** 查询菜单树结构 */
  305. getMenuTreeselect() {
  306. menuTreeselect().then((response) => {
  307. this.menuOptions = response.data
  308. })
  309. },
  310. /** 查询部门树结构 */
  311. getDeptTreeselect() {
  312. deptTreeselect().then((response) => {
  313. this.deptOptions = response.data
  314. })
  315. },
  316. // 所有菜单节点数据
  317. // getMenuAllCheckedKeys() {
  318. // // 目前被选中的菜单节点
  319. // let checkedKeys = this.$refs.menu.getCheckedKeys();
  320. // // 半选中的菜单节点
  321. // let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
  322. // checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  323. // return checkedKeys;
  324. // },
  325. // // 所有部门节点数据
  326. // getDeptAllCheckedKeys() {
  327. // // 目前被选中的部门节点
  328. // let checkedKeys = this.$refs.dept.getCheckedKeys();
  329. // // 半选中的部门节点
  330. // let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys();
  331. // checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  332. // return checkedKeys;
  333. // },
  334. /** 根据角色ID查询菜单树结构 */
  335. getRoleMenuTreeselect(roleId) {
  336. return roleMenuTreeselect(roleId).then((response) => {
  337. this.menuOptions = response.menus
  338. return response
  339. })
  340. },
  341. /** 根据角色ID查询部门树结构 */
  342. getRoleDeptTreeselect(roleId) {
  343. return roleDeptTreeselect(roleId).then((response) => {
  344. this.deptOptions = response.depts
  345. return response
  346. })
  347. },
  348. // 角色状态修改
  349. handleStatusChange(row) {
  350. let text = row.status === '0' ? '禁用' : '启用'
  351. this.$modal
  352. .confirm('确认要"' + text + '""' + row.roleName + '"角色吗?')
  353. .then(function () {
  354. row.status = row.status === '0' ? '1' : '0'
  355. return changeRoleStatus(row.roleId, row.status)
  356. })
  357. .then(() => {
  358. this.$modal.msgSuccess(text + '成功')
  359. })
  360. .catch(function () {
  361. row.status = row.status === '0' ? '1' : '0'
  362. })
  363. },
  364. // 修改功能操作权限
  365. updateBtn(e, obj1) {
  366. let obj = {
  367. menuId: e.menuId,
  368. roleId: this.roleId
  369. }
  370. let arr = []
  371. arr.push(obj)
  372. // let parent = this.functionList.find((item) => item.menuId == e.parentId)
  373. // let parents = []
  374. // while (parent) {
  375. // parents.push(parent)
  376. // parent = this.functionList.find((item) => item.menuId == parent.parentId)
  377. // }
  378. if (this.checkedKeys.includes(e.menuId)) {
  379. authUserCancelAll(arr).then((res) => {
  380. if (res.code == 200) {
  381. this.checkedKeys = this.checkedKeys.filter((item) => item != e.menuId)
  382. this.$msg({ message: '修改成功' })
  383. }
  384. })
  385. } else {
  386. // let arrs = []
  387. // arrs.push(obj)
  388. // parents.forEach(element => {
  389. // let e = {
  390. // menuId: element.menuId,
  391. // roleId: this.roleId
  392. // }
  393. // arrs.push(e)
  394. // });
  395. saveRoleMenu(arr).then((res) => {
  396. if (res.code == 200) {
  397. this.checkedKeys.push(e.menuId)
  398. this.$msg({ message: '修改成功' })
  399. // this.checkedKeys.push(obj1.menuId)
  400. // parents.forEach(element => {
  401. // this.checkedKeys.push(element.menuId)
  402. // });
  403. }
  404. })
  405. }
  406. // let checked = !this.checkedKeys.includes(e.menuId)
  407. // let obj = {
  408. // menuId: e.menuId,
  409. // roleId: this.roleId
  410. // }
  411. // let arr = []
  412. // arr.push(obj)
  413. // saveRoleMenu(arr).then((res) => {
  414. // if (res.code == 200) {
  415. // this.checkedKeys.push(e.menuId)
  416. // }
  417. // })
  418. // if (checked) {
  419. // let sArr = [...this.checkedKeys, e.menuId]
  420. // parents.forEach((p) => {
  421. // if (this.findChildrenIds(p).every((item) => sArr.includes(item))) {
  422. // arr.push({
  423. // menuId: p.menuId,
  424. // roleId: this.roleId
  425. // })
  426. // }
  427. // })
  428. // } else {
  429. // parents.forEach((p) => {
  430. // arr.push({
  431. // menuId: p.menuId,
  432. // roleId: this.roleId
  433. // })
  434. // })
  435. // }
  436. // let req = JSON.stringify(arr)
  437. // this.form1.json = req
  438. // if (!checked) {
  439. // authUserCancelAll(arr).then((res) => {
  440. // if (res.code == 200) {
  441. // this.checkedKeys = this.checkedKeys.filter((item) => item != e.menuId)
  442. // }
  443. // })
  444. // } else {
  445. // saveRoleMenu(arr).then((res) => {
  446. // if (res.code == 200) {
  447. // this.checkedKeys.push(e.menuId)
  448. // }
  449. // })
  450. // }
  451. },
  452. // 表头权限显示
  453. showOrHide(row) {
  454. let iss = row.isShow === '1' ? '0' : '1'
  455. setSysTableCfgIsShow(row.id, iss, this.menuId, this.roleId).then((res) => {
  456. if (res.code == 200) {
  457. row.isShow = row.isShow == '1' || row.isShow == null ? '0' : '1'
  458. this.$msg({ message: '修改成功' })
  459. }
  460. })
  461. },
  462. // 取消按钮
  463. cancel() {
  464. this.open = false
  465. this.reset()
  466. },
  467. // 取消按钮(数据权限)
  468. cancelDataScope() {
  469. this.openDataScope = false
  470. this.reset()
  471. },
  472. // 表单重置
  473. reset() {
  474. // if (this.$refs.menu != undefined) {
  475. // this.$refs.menu.setCheckedKeys([]);
  476. // }
  477. ;(this.menuExpand = false),
  478. (this.menuNodeAll = false),
  479. (this.deptExpand = true),
  480. (this.deptNodeAll = false),
  481. (this.form = {
  482. roleId: undefined,
  483. roleName: undefined,
  484. roleKey: undefined,
  485. roleSort: 0,
  486. status: '0',
  487. menuIds: [],
  488. deptIds: [],
  489. menuCheckStrictly: true,
  490. deptCheckStrictly: true,
  491. remark: undefined
  492. })
  493. this.resetForm('form')
  494. },
  495. // /** 搜索按钮操作 */
  496. // handleQuery() {
  497. // this.queryParams.pageNum = 1
  498. // this.getList()
  499. // },
  500. // /** 重置按钮操作 */
  501. // resetQuery() {
  502. // this.dateRange = []
  503. // this.resetForm('queryForm')
  504. // this.handleQuery()
  505. // },
  506. // 树权限(展开/折叠)
  507. // handleCheckedTreeExpand(value, type) {
  508. // if (type == 'menu') {
  509. // let treeList = this.menuOptions
  510. // for (let i = 0; i < treeList.length; i++) {
  511. // this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value
  512. // }
  513. // } else if (type == 'dept') {
  514. // let treeList = this.deptOptions
  515. // for (let i = 0; i < treeList.length; i++) {
  516. // this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value
  517. // }
  518. // }
  519. // },
  520. // 树权限(全选/全不选)
  521. // handleCheckedTreeNodeAll(value, type) {
  522. // if (type == 'menu') {
  523. // this.$refs.menu.setCheckedNodes(value ? this.menuOptions: []);
  524. // } else if (type == 'dept') {
  525. // this.$refs.dept.setCheckedNodes(value ? this.deptOptions: []);
  526. // }
  527. // },
  528. // 树权限(父子联动)
  529. handleCheckedTreeConnect(e, type, item) {
  530. let value = e.target.checked
  531. // if (item.parentId) {
  532. // }
  533. // let ms = this.functionList.filter((item, index, c) => item.menuType == 'M')
  534. // let mss = this.functionList.filter((it, index, c) => it.parentId == item.parentId)
  535. // let m = ms.filter(i => i.menuId == item.parentId)
  536. // console.log(mss)
  537. // let ids = this.findChildrenIds(item)
  538. // let objs = ids.map((m) => {
  539. // return {
  540. // menuId: m,
  541. // roleId: this.roleId
  542. // }
  543. // })
  544. // objs.push({
  545. // menuId: item.menuId,
  546. // roleId: this.roleId
  547. // })
  548. if (value) {
  549. this.checkStatus = 0
  550. this.disabled = false
  551. this.checkedKeys.push(item.menuId)
  552. let obj = {
  553. menuId: item.menuId,
  554. roleId: this.roleId
  555. }
  556. let arr = []
  557. arr.push(obj)
  558. saveRoleMenu(arr).then((res) => {
  559. if (res.code == 200) {
  560. this.$msg({ message: '修改成功' })
  561. }
  562. })
  563. } else {
  564. this.checkedKeys = this.checkedKeys.filter((f) => f != item.menuId)
  565. this.checkStatus = 1
  566. this.disabled = true
  567. let obj = {
  568. menuId: item.menuId,
  569. roleId: this.roleId
  570. }
  571. let arr = []
  572. arr.push(obj)
  573. authUserCancelAll(arr).then((res) => {
  574. if (res.code == 200) {
  575. this.$msg({ message: '修改成功' })
  576. }
  577. })
  578. }
  579. },
  580. /** 新增按钮操作 */
  581. handleAdd() {
  582. this.reset()
  583. this.getMenuTreeselect()
  584. this.open = true
  585. this.title = '添加角色'
  586. },
  587. /** 修改按钮操作 */
  588. handleUpdate(row) {
  589. this.reset()
  590. const roleId = row.roleId || this.ids
  591. // const roleMenu = this.getRoleMenuTreeselect(roleId);
  592. getRole(roleId).then((response) => {
  593. this.form = response.data
  594. this.open = true
  595. // this.$nextTick(() => {
  596. // roleMenu.then(res => {
  597. // let checkedKeys = res.checkedKeys
  598. // checkedKeys.forEach((v) => {
  599. // this.$nextTick(()=>{
  600. // this.$refs.menu.setChecked(v, true ,false);
  601. // })
  602. // })
  603. // });
  604. // });
  605. this.title = '修改角色'
  606. })
  607. },
  608. /** 选择角色权限范围触发 */
  609. // dataScopeSelectChange(value) {
  610. // if(value !== '2') {
  611. // this.$refs.dept.setCheckedKeys([]);
  612. // }
  613. // },
  614. /** 分配数据权限操作 */
  615. handleDataScope(row) {
  616. this.reset()
  617. const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId)
  618. getRole(row.roleId).then((response) => {
  619. this.form = response.data
  620. this.openDataScope = true
  621. // this.$nextTick(() => {
  622. // roleDeptTreeselect.then(res => {
  623. // this.$refs.dept.setCheckedKeys(res.checkedKeys);
  624. // });
  625. // });
  626. this.title = '分配数据权限'
  627. })
  628. },
  629. /** 分配用户操作 */
  630. // handleAuthUser: function (row) {
  631. // const roleId = row.roleId
  632. // this.$router.push('/system/role-auth/user/' + roleId)
  633. // },
  634. /** 提交按钮 */
  635. submitForm: function () {
  636. this.$refs['form'].validate((valid) => {
  637. if (valid) {
  638. if (this.form.roleId != undefined) {
  639. // this.form.menuIds = this.getMenuAllCheckedKeys();
  640. this.form.menuIds = []
  641. updateRole(this.form).then((response) => {
  642. console.log(response)
  643. this.$modal.msgSuccess('修改成功')
  644. this.open = false
  645. this.getList()
  646. })
  647. } else {
  648. // this.form.menuIds = this.getMenuAllCheckedKeys();
  649. let val = this.form.roleName
  650. this.form.roleKey = pinyin.getFullChars(val)
  651. addRole(this.form).then((response) => {
  652. this.$modal.msgSuccess('新增成功')
  653. this.open = false
  654. this.getList()
  655. })
  656. }
  657. }
  658. })
  659. },
  660. /** 提交按钮(数据权限) */
  661. submitDataScope: function () {
  662. if (this.form.roleId != undefined) {
  663. this.form.deptIds = this.getDeptAllCheckedKeys()
  664. dataScope(this.form).then((response) => {
  665. this.$modal.msgSuccess('修改成功')
  666. this.openDataScope = false
  667. this.getList()
  668. })
  669. }
  670. },
  671. /** 删除按钮操作 */
  672. handleDelete(row) {
  673. const roleIds = row.roleId || this.ids
  674. this.$modal
  675. .confirm('是否确认删除角色为"' + row.roleName + '"的数据项?')
  676. .then(function () {
  677. return delRole(roleIds)
  678. })
  679. .then((res) => {
  680. if (res.code === 200) {
  681. this.getList()
  682. this.$modal.msgSuccess('删除成功')
  683. } else if (res.code === 500) {
  684. this.getList()
  685. this.$notify({
  686. title: '警告',
  687. message: res.msg,
  688. type: 'warning'
  689. })
  690. }
  691. })
  692. .catch(() => {})
  693. },
  694. /** 导出按钮操作 */
  695. // handleExport() {
  696. // this.download(
  697. // 'system/role/export',
  698. // {
  699. // ...this.queryParams
  700. // },
  701. // `role_${new Date().getTime()}.xlsx`
  702. // )
  703. // },
  704. //寻找子id集合
  705. findIds(parent) {
  706. if (!parent.children) {
  707. return
  708. }
  709. let res = []
  710. parent.children.forEach((item) => {
  711. if (item.menuType == 'C') {
  712. res.push(item)
  713. } else {
  714. res = res.concat(this.findIds(item))
  715. }
  716. })
  717. return res
  718. },
  719. //寻找子id集合
  720. findChildrenIds(parent) {
  721. if (parent.menuType == 'M') {
  722. let childIds = this.findIds(parent).map((item) => item.menuId)
  723. return this.btnList.filter((item) => childIds.includes(item.parentId)).map((item) => item.menuId)
  724. } else if (parent.menuType == 'C') {
  725. return this.btnList.filter((item) => item.parentId == parent.menuId).map((item) => item.menuId)
  726. }
  727. }
  728. },
  729. computed: {
  730. btnListss() {
  731. return function (pid) {
  732. return this.btnList.filter((item) => item.parentId == pid)
  733. }
  734. },
  735. isChecked() {
  736. return function (obj) {
  737. // return this.findChildrenIds(obj).length > 0 && this.findChildrenIds(obj).every((item) => this.checkedKeys.includes(item))
  738. return this.checkedKeys.includes(obj.menuId)
  739. }
  740. }
  741. }
  742. }
  743. </script>
  744. <style scoped>
  745. .activeClass {
  746. color: #409eff;
  747. }
  748. </style>