role-set.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <el-drawer title="权限设置" :visible.sync="showStatus" size="70%" :before-close="closeFn">
  3. <div class="role-set-wrap">
  4. <div class="role-list" v-for="(item, index) in permTree" :key="index">
  5. <el-checkbox
  6. :indeterminate="isIndeterminate[index]"
  7. v-model="checkAll[index]"
  8. @change="handleCheckAllChange($event, index)"
  9. >{{ item.authName }}</el-checkbox
  10. >
  11. <div style="margin: 15px 0;"></div>
  12. <el-checkbox-group
  13. v-model="checkedPerm"
  14. @change="handlecheckedPermChange($event, index)"
  15. >
  16. <el-checkbox
  17. v-for="(items, subIndex) in item.children"
  18. :label="items.id"
  19. :key="items.id"
  20. >{{ items.authName }}</el-checkbox
  21. >
  22. </el-checkbox-group>
  23. </div>
  24. </div>
  25. <!-- button -->
  26. <div class="button-wrap flex-center">
  27. <el-button size="mini" @click="closeFn">关闭</el-button>
  28. <el-button type="primary" size="mini" @click="saveFn">保存</el-button>
  29. </div>
  30. </el-drawer>
  31. </template>
  32. <script>
  33. export default {
  34. name: 'role-set',
  35. props: {
  36. show: {
  37. type: Boolean,
  38. default: false
  39. },
  40. info: {
  41. type: Object,
  42. default: () => {}
  43. }
  44. },
  45. data() {
  46. return {
  47. showStatus: false,
  48. data: {},
  49. permTree: [],
  50. checkAll: [],
  51. checkedPerm: [],
  52. isIndeterminate: []
  53. };
  54. },
  55. watch: {
  56. show(val) {
  57. this.showStatus = val;
  58. if (val) {
  59. this.init();
  60. }
  61. }
  62. },
  63. methods: {
  64. init() {
  65. this._getTreeB().then(res => {
  66. console.log('res', res);
  67. if (this.$projectName == 'business') {
  68. this._getAuthB();
  69. }
  70. });
  71. },
  72. async _getTreeB() {
  73. let data = {};
  74. await this.$service.common.permTree({ endId: 1 }).then(res => {
  75. this.permTree = res;
  76. this.permTree.map(() => {
  77. this.isIndeterminate.push(false);
  78. this.checkAll.push(false);
  79. });
  80. data = res;
  81. });
  82. return data;
  83. },
  84. async _getAuthB() {
  85. let data = {};
  86. await this.$service.auth.authList({ roleId: this.info.roleId }).then(res => {
  87. data = res;
  88. });
  89. return data;
  90. },
  91. saveFn() {
  92. console.log('this.info', this.info);
  93. this.$service.auth
  94. .authUpdate({
  95. roleId: this.info.roleId,
  96. authIdList: this.checkedPerm
  97. })
  98. .then(res => {
  99. this.closeFn();
  100. this.$message.success('保存成功!');
  101. });
  102. },
  103. closeFn(done) {
  104. this.$emit('update:show', false);
  105. if (done) {
  106. done();
  107. }
  108. },
  109. handleCheckAllChange(val, index) {
  110. let arr = this.permTree[index].children
  111. ? this.permTree[index].children
  112. : this.permTree[index];
  113. arr = arr.map(e => e.id);
  114. this.checkedPerm = val ? arr : [];
  115. this.$set(this.isIndeterminate, index, false);
  116. },
  117. handlecheckedPermChange(value, index) {
  118. let checkedCount = value.length;
  119. let arrLen = this.permTree[index].children ? this.permTree[index].children.length : 0;
  120. let checkAllStatus = checkedCount === arrLen;
  121. this.$set(this.checkAll, index, checkAllStatus);
  122. let isIndeterminateStatus = checkedCount > 0 && checkedCount < arrLen;
  123. this.$set(this.isIndeterminate, index, isIndeterminateStatus);
  124. }
  125. }
  126. };
  127. </script>
  128. <style lang="scss" scoped>
  129. .role-set-wrap {
  130. padding: 0 20px;
  131. height: calc(100% - 50px);
  132. }
  133. .button-wrap {
  134. padding-left: 20px;
  135. }
  136. .el-checkbox-group {
  137. margin-left: 25px;
  138. }
  139. </style>