createTasnsfer.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="transBox" v-if="open">
  3. <div class="allBag">
  4. <el-input
  5. style="width: 220px; margin-left: 18px; margin-top: 5px"
  6. v-model="allBag"
  7. placeholder="搜索"
  8. ></el-input>
  9. <div class="allLog">
  10. <el-tree
  11. ref="treeRef"
  12. :data="allTreeData"
  13. :props="allTreeProps"
  14. show-checkbox
  15. node-key="id"
  16. :default-expanded-keys="openTree"
  17. @check-change="allTreeChange"
  18. :default-checked-keys="backScreen"
  19. :check-strictly="false"
  20. />
  21. </div>
  22. </div>
  23. <div class="needBag">
  24. <div style="border-bottom: 1px solid gray" class="needBag_top">
  25. <span>已选择{{ chooseTagData.length }}人</span>
  26. <span style="color: red; font-size: 14px; float: right">清空</span>
  27. </div>
  28. <div class="needLog">
  29. <el-scrollbar>
  30. <el-tag
  31. v-for="(item) in chooseTagData"
  32. :key="item.userId"
  33. class="tagtag"
  34. :closable="lastPeople"
  35. @close="handleClose(item)"
  36. >
  37. {{ item.userName ? item.userName : item.name }}
  38. </el-tag>
  39. </el-scrollbar>
  40. </div>
  41. </div>
  42. </div>
  43. </template>
  44. <script setup>
  45. import { ref, onMounted, toRef, watch,defineEmits,toRaw } from "vue";
  46. import userTree from "../../../api/user/userTree";
  47. import fileShare from "../../../api/fileShare/fileShare";
  48. import fileCount from "../../../api/fileCount/fileCount";
  49. import { ElMessage } from "element-plus";
  50. const open = ref(true);
  51. const allTreeData = ref([]);
  52. const chooseTagData = ref([]);
  53. const lastPeople = ref(false);
  54. const openTree = ref([]);
  55. const backScreen = ref(props.checkUser);
  56. const allTreeProps = {
  57. label: "label",
  58. children: "children",
  59. disabled: false,
  60. id: "id",
  61. };
  62. const emit = defineEmits(["setUsers"]);
  63. const props = defineProps({
  64. openTrans: {
  65. type: Boolean,
  66. default: true,
  67. },
  68. checkUser: {
  69. type: Array,
  70. required: true,
  71. default: ()=>[],
  72. },
  73. });
  74. watch(
  75. () => props.openTrans,
  76. (newValue) => {
  77. console.log(111);
  78. open.value = newValue;
  79. }
  80. );
  81. function allTreeChange(e) {
  82. const id = e.id;
  83. const label = e.label;
  84. const disabled = e.disabled;
  85. // 查找是否已经存在相同 userId 的数据的索引
  86. const existingIndex = chooseTagData.value.findIndex(
  87. (item) => item.userId === id
  88. );
  89. if (existingIndex !== -1) {
  90. // 如果已存在,删除该项
  91. chooseTagData.value.splice(existingIndex, 1);
  92. } else {
  93. // 选择操作,将数据添加到 needTagData 中
  94. chooseTagData.value.push({
  95. userId: id,
  96. userName: label,
  97. disabled: disabled,
  98. });
  99. }
  100. if (chooseTagData.value.length === 1) {
  101. lastPeople.value = true;
  102. } else {
  103. lastPeople.value = false;
  104. }
  105. chooseTagData.value = chooseTagData.value.filter((item) => !item.disabled);
  106. emit("setUsers",toRaw(chooseTagData.value));
  107. console.log("chooseTagData", chooseTagData.value);
  108. }
  109. // 获取用户树
  110. function getAllUser() {
  111. userTree.getMentUserTree({}).then((res) => {
  112. console.log("userTree", res);
  113. allTreeData.value = [res];
  114. console.log('open',open.value);
  115. userTree.getMentUserTree({}).then((res) => {
  116. allTreeData.value = [res];
  117. // 递归函数来获取所有节点的 id
  118. function getAllNodeIds(nodes) {
  119. nodes.forEach((node) => {
  120. openTree.value.push(node.id);
  121. if (node.children && node.children.length > 0) {
  122. getAllNodeIds(node.children);
  123. }
  124. });
  125. }
  126. // 调用递归函数获取所有节点的 id
  127. getAllNodeIds(allTreeData.value);
  128. });
  129. });
  130. }
  131. onMounted(async() => {
  132. getAllUser();
  133. const checkUser = toRaw(props.checkUser)
  134. // console.log('checkUser',checkUser);
  135. // console.log('allTreeData.value',allTreeData.value);
  136. //设置勾选项
  137. const arr = checkUser.map(item=>{
  138. return item.userId
  139. })
  140. backScreen.value = arr
  141. // 设置右侧列表数据
  142. chooseTagData.value = checkUser.map(item=>{
  143. return {
  144. userId:item.userId,
  145. userName:item.userName,
  146. disabled:false
  147. }
  148. })
  149. // console.log('arr',arr);
  150. });
  151. </script>
  152. <style lang="scss" scoped>
  153. .transBox {
  154. width: 100%;
  155. height: 400px;
  156. margin: 0 auto;
  157. display: flex;
  158. justify-content: space-around;
  159. align-items: center;
  160. /* border: 1px solid black; */
  161. }
  162. .tagtag {
  163. display: flex;
  164. justify-content: space-between;
  165. align-items: center;
  166. text-align: start;
  167. width: 230px;
  168. margin: 0 auto;
  169. }
  170. .allBag {
  171. width: 60%;
  172. height: 380px;
  173. border: 1px solid green;
  174. }
  175. .needBag {
  176. width: 40%;
  177. height: 380px;
  178. border: 1px solid green;
  179. }
  180. .allLog {
  181. width: 245px;
  182. height: 330px;
  183. margin: 5px auto;
  184. /* border: 1px solid red; */
  185. overflow-y: auto;
  186. }
  187. .needBag_top {
  188. padding: 0 10px;
  189. height: 30px;
  190. display: flex;
  191. align-items: center;
  192. justify-content: space-between;
  193. }
  194. .needLog {
  195. height: 100%;
  196. }
  197. :deep(.el-tag__content) {
  198. display: block;
  199. }
  200. :deep(.el-icon el-tag__close) {
  201. display: block;
  202. }
  203. </style>