index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!--
  2. * @Author: zk
  3. * @Date: 2022-02-09 15:47:09
  4. * @LastEditTime: 2022-03-02 10:58:29
  5. * @LastEditors: your name
  6. * @Description: 用户组树
  7. * @FilePath: \Foshan4A4.0\src\components\usergrouptree\index.vue
  8. -->
  9. <template>
  10. <div class="userGroupTree">
  11. <div class="head">
  12. <p>{{ title }}</p>
  13. </div>
  14. <div :class="type ? 'radioBg':''" class="content">
  15. <el-scrollbar style="height: 100%" wrap-style="overflow-x:hidden;">
  16. <el-tree ref="tree" :data="data" show-checkbox :check-strictly="true" :default-props="defaultProps" :expand-on-click-node="false" node-key="GroupId" highlight-current @check-change="currentChange">
  17. <span slot-scope="{ data }" class="custom-tree-node">
  18. {{ data.GroupName }}
  19. </span>
  20. </el-tree>
  21. </el-scrollbar>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import { GetGroupTree } from '@/api/AccountGroup'
  27. import { translateDataToTreeAll } from '@/utils/validate'
  28. export default {
  29. name: 'UserGroupTree',
  30. props: {
  31. title: {
  32. // 标题
  33. type: String,
  34. default: ''
  35. },
  36. checkedKeys: {
  37. // 已选中
  38. type: Array,
  39. default: () => []
  40. },
  41. type: {
  42. type: Boolean,
  43. default: false
  44. },
  45. defaultProps: {
  46. type: Object,
  47. default: () => ({
  48. children: 'children',
  49. label: 'GroupName'
  50. })
  51. },
  52. checkDisabled: {
  53. type: Boolean,
  54. default: false
  55. }
  56. },
  57. data () {
  58. return {
  59. data: [], // tree数据
  60. checkedList: [], // 已选中数据
  61. pageIndex: 1,
  62. pageSize: 20
  63. }
  64. },
  65. watch: {
  66. checkedKeys: {
  67. handler (val) {
  68. this.checkedList = val
  69. this.$refs.tree.setCheckedKeys(val)
  70. },
  71. deep: true
  72. }
  73. },
  74. created () {
  75. this.getGroupTree()
  76. },
  77. methods: {
  78. // 复选框选中
  79. currentChange (data, isChecked) {
  80. if (this.type) {
  81. const { GroupId } = data
  82. this.$emit('getTreeData', this.$refs.tree.getCheckedNodes())
  83. if (isChecked) {
  84. const checked = [GroupId]
  85. this.$refs.tree.setCheckedKeys(checked)
  86. }
  87. } else {
  88. const arr = this.$refs.tree.getCheckedNodes()
  89. this.$emit('getTreeData', arr)
  90. }
  91. },
  92. async getGroupTree () {
  93. const result = await GetGroupTree({
  94. QueryName: '',
  95. PageIndex: this.pageIndex,
  96. PageSize: this.pageSize
  97. })
  98. const datas = result.returnData
  99. if (this.checkDisabled) {
  100. datas.forEach(data => {
  101. data.disabled = true
  102. })
  103. }
  104. const tree = translateDataToTreeAll(datas, 'GroupUpid', 'GroupId')
  105. const obj = {
  106. AuthCount: 0,
  107. GroupId: -1,
  108. GroupName: '系统用户组',
  109. GroupUpid: 0,
  110. QueryTarget: 0,
  111. Status: 0,
  112. UserCount: 0,
  113. disabled: true,
  114. children: tree
  115. }
  116. this.data = [obj]
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .userGroupTree {
  123. width: 100%;
  124. height: 100%;
  125. background: #ffffff;
  126. -webkit-box-shadow: 0px 6px 7px 0px rgb(0 0 0 / 6%);
  127. box-shadow: 0px 6px 7px 0px rgb(0 0 0 / 6%);
  128. border-radius: 16px;
  129. padding: 0 32px 0 32px;
  130. .head {
  131. width: 100%;
  132. height: 90px;
  133. display: flex;
  134. align-items: center;
  135. p {
  136. margin: 0;
  137. font-size: 24px;
  138. font-family: Microsoft YaHei;
  139. font-weight: bold;
  140. color: #303133;
  141. }
  142. }
  143. ::v-deep .content {
  144. width: 100%;
  145. height: calc(100% - 112px);
  146. box-sizing: border-box;
  147. .custom-tree-node {
  148. margin-left: 10px;
  149. font-size: 14px;
  150. }
  151. }
  152. ::v-deep .radioBg {
  153. .el-checkbox__inner {
  154. border-radius: 50%;
  155. &::after {
  156. width: 5px;
  157. height: 5px;
  158. background: #ffffff;
  159. border-radius: 50%;
  160. top: 3px;
  161. left: 3px;
  162. }
  163. }
  164. }
  165. }
  166. </style>