MoveFiles.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <a-modal
  3. v-model:open="open"
  4. title="文件移动"
  5. @ok="handleOk"
  6. @cancel="closeModel"
  7. >
  8. <a-directory-tree
  9. class="directory-tree"
  10. v-model:expandedKeys="expandedKeys"
  11. v-model:selectedKeys="selectedKeys"
  12. :tree-data="treeData"
  13. style="
  14. border: 1px solid #e4e7ea;
  15. border-radius: 4px;
  16. padding: 10px;
  17. max-height: 400px;
  18. min-height: 200px;
  19. overflow-y: scroll;
  20. "
  21. >
  22. <template #icon="{ key, selected }">
  23. <MyIcon
  24. :icon="iconTypeName.dir"
  25. size="18"
  26. style="margin-right: 5px; margin-top: 2px"
  27. />
  28. </template>
  29. </a-directory-tree>
  30. </a-modal>
  31. </template>
  32. <script lang="ts" setup>
  33. /**
  34. * @description 文件移动弹窗
  35. */
  36. import { ref, onMounted, watch, toRefs, PropType } from "vue";
  37. import { message } from "ant-design-vue";
  38. import MyIcon from "@/components/myIcon/index.vue";
  39. import { getAllFolder } from "./http";
  40. import { iconTypeName } from "./config";
  41. import { moveFiles } from "./http";
  42. const props = defineProps({
  43. ids: {
  44. type: Array as PropType<string[]>,
  45. default: [],
  46. },
  47. open: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. closeModel: {
  52. type: Function,
  53. default: () => {},
  54. },
  55. });
  56. const { ids, open, closeModel } = toRefs(props);
  57. const expandedKeys = ref<string[]>(["root"]);
  58. const selectedKeys = ref<string[]>([]);
  59. const treeData = ref([
  60. {
  61. title: "我的文档",
  62. key: "root",
  63. children: [],
  64. },
  65. ]);
  66. onMounted(() => {
  67. initModel();
  68. });
  69. watch(
  70. () => open.value,
  71. () => {
  72. initModel();
  73. }
  74. );
  75. const initModel = () => {
  76. selectedKeys.value = [];
  77. getAllFolder().then((res) => {
  78. console.log(res);
  79. treeData.value[0].children = res.data.map((item: any) => {
  80. return {
  81. title: item.fileName,
  82. key: item.fileId,
  83. };
  84. });
  85. });
  86. };
  87. const handleOk = async () => {
  88. const selectKey =
  89. selectedKeys.value[0] == "root" ? "" : selectedKeys.value[0];
  90. const res: any = await moveFiles(ids.value, selectKey);
  91. console.log("res", res);
  92. if (res.success) {
  93. message.success("文件移动成功!");
  94. closeModel.value();
  95. } else {
  96. message.error("文件移动失败,请稍后重试!");
  97. }
  98. };
  99. </script>
  100. <style scoped lang="scss"></style>