role-set.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.$constant.)
  68. this._getAuthB()
  69. });
  70. },
  71. async _getTreeB() {
  72. let data = {};
  73. await this.$service.common.permTree({ endId: 1 }).then(res => {
  74. this.permTree = res;
  75. this.permTree.map(() => {
  76. this.isIndeterminate.push(false);
  77. this.checkAll.push(false);
  78. });
  79. data = res;
  80. });
  81. return data;
  82. },
  83. async _getAuthB() {
  84. let data = {};
  85. await this.$service.auth.authList({ roleId: this.info.roleId }).then(res => {
  86. data = res;
  87. });
  88. return data;
  89. },
  90. saveFn() {
  91. console.log('this.info', this.info);
  92. this.$service.auth
  93. .authUpdate({
  94. roleId: this.info.roleId,
  95. authIdList: this.checkedPerm
  96. })
  97. .then(res => {
  98. this.closeFn();
  99. this.$message.success('保存成功!');
  100. });
  101. },
  102. closeFn(done) {
  103. this.$emit('update:show', false);
  104. if (done) {
  105. done();
  106. }
  107. },
  108. handleCheckAllChange(val, index) {
  109. let arr = this.permTree[index].children
  110. ? this.permTree[index].children
  111. : this.permTree[index];
  112. arr = arr.map(e => e.id);
  113. this.checkedPerm = val ? arr : [];
  114. this.$set(this.isIndeterminate, index, false);
  115. },
  116. handlecheckedPermChange(value, index) {
  117. let checkedCount = value.length;
  118. let arrLen = this.permTree[index].children ? this.permTree[index].children.length : 0;
  119. let checkAllStatus = checkedCount === arrLen;
  120. this.$set(this.checkAll, index, checkAllStatus);
  121. let isIndeterminateStatus = checkedCount > 0 && checkedCount < arrLen;
  122. this.$set(this.isIndeterminate, index, isIndeterminateStatus);
  123. }
  124. }
  125. };
  126. </script>
  127. <style lang="scss" scoped>
  128. .role-set-wrap {
  129. padding: 0 20px;
  130. height: calc(100% - 50px);
  131. }
  132. .button-wrap {
  133. padding-left: 20px;
  134. }
  135. </style>