role-data-auth.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. this.$refs.tree.setCheckedKeys(this.form.dataScopeDeptIds.split(','))
  91. })
  92. },
  93. getListOrganizations(){
  94. this.authLoading = true;
  95. listOrganizations()
  96. .then((list) => {
  97. let _list = list.filter((i) => i.name != '超级管理员')
  98. this.authLoading = false;
  99. this.deptData = this.$util.toTreeData({
  100. data: _list,
  101. idField: 'id',
  102. parentIdField: 'parentId'
  103. });
  104. })
  105. .catch((e) => {
  106. this.loading = false;
  107. // this.$message.error(e.message);
  108. });
  109. },
  110. /* 保存权限分配 */
  111. save() {
  112. this.loading = true;
  113. if(this.form.dataScope=='2'){
  114. const ids = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys());
  115. this.form.dataScopeDeptIds = ids.join(',');
  116. }
  117. putRoles(this.form)
  118. .then((msg) => {
  119. this.loading = false;
  120. this.$message.success('操作成功');
  121. this.updateVisible();
  122. this.$emit('reload');
  123. })
  124. .catch((e) => {
  125. this.loading = false;
  126. // this.$message.error(e.message);
  127. });
  128. },
  129. /* 更新visible */
  130. updateVisible() {
  131. this.$emit('update:roleDataAuthDialogFlag', false);
  132. },
  133. },
  134. };
  135. </script>