index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <el-dialog v-model="isOpen" append-to-body width="700">
  3. <template #header>
  4. <div class="my-header">
  5. <div class="title">转存到</div>
  6. </div>
  7. </template>
  8. <div class="main-cont">
  9. <div class="main-cont-left">
  10. <div class="build-file" v-if="dirBulidNow">
  11. <img :src="fileImg" alt="" class="left-img build-img" />
  12. <el-input
  13. v-model="dirName"
  14. maxlength="32"
  15. class="bulid-input"
  16. clearable
  17. placeholder="新建目录"
  18. />
  19. <el-icon size="20" color="#327CEC" @click="sureDir"
  20. ><CircleCheckFilled
  21. /></el-icon>
  22. </div>
  23. <el-tree-v2
  24. ref="treeRef"
  25. :data="treeData"
  26. :highlight-current="true"
  27. :default-expanded-keys="[spaceId]"
  28. :show-checkbox="false"
  29. :height="280"
  30. :props="defaultProps"
  31. @node-click="handleNodeClick"
  32. >
  33. <template #default="{ node }">
  34. <span style="display: flex; align-items: center">
  35. <img :src="fileImg" alt="" class="left-img" />
  36. <!-- 放置图片 -->
  37. <span>{{ node.label }}</span>
  38. <!-- 显示节点标签 -->
  39. </span>
  40. </template>
  41. </el-tree-v2>
  42. </div>
  43. </div>
  44. <template #footer>
  45. <div class="footer">
  46. <span
  47. ><el-button @click.stop="buildFile" class="cancel-button"
  48. >新建文件夹</el-button
  49. ></span
  50. >
  51. <div>
  52. <span class="dialog-footer">
  53. <el-button @click="isOpen = false" class="cancel-button"
  54. >取消</el-button
  55. >
  56. <el-button type="primary" @click="confirm" class="sure-button">
  57. 确认
  58. </el-button>
  59. </span>
  60. </div>
  61. </div>
  62. </template>
  63. </el-dialog>
  64. </template>
  65. <script setup>
  66. import {
  67. reactive,
  68. ref,
  69. toRaw,
  70. toRefs,
  71. watch,
  72. nextTick,
  73. onMounted,
  74. getCurrentInstance,
  75. } from "vue";
  76. import { ElMessage } from "element-plus";
  77. import fileImg from "@/assets/images/file-img.png";
  78. import direction from "@/assets/images/direction.png";
  79. import useUserStore from "@/store/modules/user";
  80. import { defineEmits } from "vue";
  81. import { builtDir, fileCopy, spaceInfo, dirTree } from "@/api/chat/msg";
  82. const opent = ref(true);
  83. const props = defineProps({
  84. openForwardFile: {
  85. type: Boolean,
  86. default: false,
  87. },
  88. forwardTreeData: {
  89. type: Object,
  90. default: () => {},
  91. },
  92. docId: {
  93. type: String,
  94. },
  95. spaceId: {
  96. type: String,
  97. },
  98. });
  99. const defaultProps = {
  100. children: "children",
  101. label: "label",
  102. value: "id",
  103. };
  104. const dirName = ref(""); //新建文件夹名称
  105. const dirBulidNow = ref(false);
  106. const treeRef = ref(null);
  107. const isOpen = ref(props.openForwardFile);
  108. const instance = getCurrentInstance();
  109. watch(
  110. () => props.openForwardFile,
  111. (newValue) => {
  112. isOpen.value = newValue;
  113. }
  114. );
  115. const treeData = ref([]);
  116. const defaultExpandedKeys = ref([]);
  117. watchEffect(() => {
  118. treeData.value =[ props.forwardTreeData];
  119. // //默认展开第二级
  120. // treeData.data.forEach((node) => {
  121. // if (node.children) {
  122. // // 如果节点有子节点
  123. // const childKeys = node.children.map((child) => child.id); // 获取子节点的 key 数组
  124. // defaultExpandedKeys.value= [... defaultExpandedKeys.value, ...childKeys]; // 将子节点的 key 数组合并到 defaultExpandedKeys 中
  125. // }
  126. // });
  127. });
  128. //树
  129. const clickData = ref({});
  130. const handleNodeClick = (data) => {
  131. clickData.value = data;
  132. };
  133. //确定按钮
  134. const emit = defineEmits(["forwardChangeMsg"]);
  135. const confirm = async () => {
  136. const copyRes = await fileCopy({
  137. docId: props.docId,
  138. dirId: clickData.value.id,
  139. spaceId: props.spaceId,
  140. });
  141. if (copyRes.code === 200) {
  142. ElMessage({ message: "转存成功", type: "success" });
  143. dirBulidNow.value = false;
  144. }
  145. isOpen.value = false;
  146. };
  147. //新建目录显示
  148. const clickId = ref("");
  149. const buildFile = async () => {
  150. clickId.value = clickData.value.id;
  151. if (!clickId.value) {
  152. return ElMessage({ message: "请选中目录", type: "error" });
  153. }
  154. dirBulidNow.value = true;
  155. };
  156. const newTree = async () => {
  157. //重新获取树结构
  158. const resDir = await dirTree(3);
  159. treeData.value=[resDir]
  160. };
  161. //确认新建目录--点击勾选
  162. const sureDir = async () => {
  163. const selectedNode = treeRef.value.getCurrentNode()
  164. const siblings = selectedNode.children;
  165. const hasSameLabel = siblings.some((node) => node.label === dirName.value);
  166. if(hasSameLabel){
  167. ElMessage({ message: "该目录名字已存在,请重新创建", type: "error" });
  168. return
  169. }
  170. console.log('selectedNode', selectedNode)
  171. const dirRes = await builtDir({
  172. dirName: dirName.value,
  173. spaceId: props.spaceId,
  174. parentId: clickData.value.id,
  175. });
  176. if (dirRes.code == 200) {
  177. ElMessage({ message: "创建成功", type: "success" });
  178. dirBulidNow.value = false;
  179. clickId.value = "";
  180. dirName.value = "";
  181. newTree();
  182. }
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. @import "@/assets/styles/tree-common.scss";
  187. .sure-button,
  188. .cancel-button {
  189. width: 120px;
  190. }
  191. .left-img {
  192. width: 20px;
  193. height: 20px;
  194. margin-right: 5px;
  195. }
  196. .footer {
  197. display: flex;
  198. justify-content: space-between;
  199. }
  200. .title {
  201. font-family: "Inter-Medium";
  202. font-weight: 600;
  203. }
  204. :deep .el-tree {
  205. // margin-top: 4px;
  206. width: 100%;
  207. }
  208. .arrow-img {
  209. margin-left: 5px;
  210. width: 12px;
  211. height: 12px;
  212. }
  213. .build-file {
  214. background: #f5f7f9;
  215. padding: 3px 0;
  216. margin: 4px 0;
  217. display: flex;
  218. align-items: center;
  219. .build-img {
  220. margin-left: 24px;
  221. }
  222. .bulid-input {
  223. margin-right: 10px;
  224. }
  225. :deep .el-input {
  226. width: 240px !important;
  227. height: 29px;
  228. }
  229. }
  230. </style>