role-data-auth.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <!-- 角色权限分配弹窗 -->
  2. <template>
  3. <ele-modal
  4. width="460px"
  5. title="分配权限"
  6. :close-on-click-modal="false" custom-class="ele-dialog-form"
  7. :visible.sync="roleDataAuthDialogFlag"
  8. :before-close="updateVisible"
  9. >
  10. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  11. <el-form-item label="角色名称">
  12. <el-tag>{{ form.name }}</el-tag>
  13. </el-form-item>
  14. <!-- <el-form-item label="组织名称">
  15. <el-tag>{{ form.groupName }}</el-tag>
  16. </el-form-item> -->
  17. <el-form-item label="权限范围" prop="dataScope">
  18. <DictSelection
  19. dictName="角色数据权限字典"
  20. clearable
  21. v-model="form.dataScope"
  22. >
  23. </DictSelection>
  24. </el-form-item>
  25. <el-form-item prop="dataScope">
  26. <el-scrollbar
  27. v-if="form.dataScope=='2'"
  28. v-loading="authLoading"
  29. style="height: 40vh"
  30. wrap-style="overflow-x: hidden;">
  31. <el-tree
  32. ref="tree"
  33. :data="deptData"
  34. :check-strictly="true"
  35. highlight-current
  36. node-key="id"
  37. :props="{ label: 'name' }"
  38. :expand-on-click-node="false"
  39. show-checkbox
  40. :default-expand-all="true"
  41. :default-checked-keys="checkedKeys"
  42. />
  43. </el-scrollbar>
  44. </el-form-item>
  45. </el-form>
  46. <template v-slot:footer>
  47. <el-button @click="updateVisible">取消</el-button>
  48. <el-button type="primary" :loading="loading" @click="save">
  49. 保存
  50. </el-button>
  51. </template>
  52. </ele-modal>
  53. </template>
  54. <script>
  55. import {putRoles} from '@/api/system/role';
  56. import {listOrganizations} from "@/api/system/organization";
  57. export default {
  58. components: {},
  59. props: {
  60. // 弹窗是否打开
  61. roleDataAuthDialogFlag: Boolean,
  62. },
  63. data() {
  64. return {
  65. form: {
  66. dataScope: '',
  67. dataScopeDeptIds: ''
  68. },
  69. rules: {},
  70. // 权限数据
  71. deptData: [],
  72. // 权限数据请求状态
  73. authLoading: false,
  74. // 提交状态
  75. loading: false,
  76. // 角色权限选中的keys
  77. checkedKeys: [],
  78. ids: []
  79. };
  80. },
  81. created() {
  82. this.getListOrganizations()
  83. },
  84. methods: {
  85. /* 查询权限数据 */
  86. init(row) {
  87. this.form = row
  88. this.form.dataScope = this.form.dataScope + ''
  89. this.$nextTick(()=>{
  90. if(this.form.dataScope=='2'){
  91. this.$refs.tree.setCheckedKeys(this.form.dataScopeDeptIds.split(','))
  92. }
  93. })
  94. },
  95. getListOrganizations(){
  96. this.authLoading = true;
  97. listOrganizations()
  98. .then((list) => {
  99. let _list = list.filter((i) => i.name != '超级管理员')
  100. this.authLoading = false;
  101. this.deptData = this.$util.toTreeData({
  102. data: _list,
  103. idField: 'id',
  104. parentIdField: 'parentId'
  105. });
  106. })
  107. .catch((e) => {
  108. this.loading = false;
  109. // this.$message.error(e.message);
  110. });
  111. },
  112. /* 保存权限分配 */
  113. save() {
  114. this.loading = true;
  115. if(this.form.dataScope=='2'){
  116. const ids = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys());
  117. this.form.dataScopeDeptIds = ids.join(',');
  118. }
  119. putRoles(this.form)
  120. .then((msg) => {
  121. this.loading = false;
  122. this.$message.success('操作成功');
  123. this.updateVisible();
  124. this.$emit('reload');
  125. })
  126. .catch((e) => {
  127. this.loading = false;
  128. // this.$message.error(e.message);
  129. });
  130. },
  131. /* 更新visible */
  132. updateVisible() {
  133. this.$emit('update:roleDataAuthDialogFlag', false);
  134. },
  135. },
  136. };
  137. </script>