From 3f6920f7a9775fc06a34dead90b1724b23b7759c Mon Sep 17 00:00:00 2001 From: Vben Date: Fri, 11 Jun 2021 23:19:03 +0800 Subject: [PATCH] perf(component): optimize tree and upload components --- src/components/Tree/index.ts | 2 +- src/components/Tree/src/Tree.vue | 4 +- src/components/Tree/src/TreeHeader.vue | 9 +- src/components/Tree/src/enum.ts | 8 -- src/components/Tree/src/props.ts | 2 +- .../Tree/src/{types.ts => typing.ts} | 0 src/components/Tree/src/useTree.ts | 2 +- src/components/Upload/index.ts | 5 +- src/components/Upload/src/BasicUpload.vue | 41 +++---- src/components/Upload/src/FileList.less | 31 ------ src/components/Upload/src/FileList.tsx | 72 ------------ src/components/Upload/src/FileList.vue | 104 ++++++++++++++++++ src/components/Upload/src/UploadModal.vue | 20 ++-- .../Upload/src/UploadPreviewModal.vue | 9 +- src/components/Upload/src/data.tsx | 5 +- src/components/Upload/src/props.ts | 2 +- .../Upload/src/{types.ts => typing.ts} | 0 src/components/Upload/src/useUpload.ts | 4 +- 18 files changed, 161 insertions(+), 159 deletions(-) delete mode 100644 src/components/Tree/src/enum.ts rename src/components/Tree/src/{types.ts => typing.ts} (100%) delete mode 100644 src/components/Upload/src/FileList.less delete mode 100644 src/components/Upload/src/FileList.tsx create mode 100644 src/components/Upload/src/FileList.vue rename src/components/Upload/src/{types.ts => typing.ts} (100%) diff --git a/src/components/Tree/index.ts b/src/components/Tree/index.ts index caf1f8f04da..f47820d7217 100644 --- a/src/components/Tree/index.ts +++ b/src/components/Tree/index.ts @@ -2,4 +2,4 @@ import BasicTree from './src/Tree.vue'; export { BasicTree }; export type { ContextMenuItem } from '/@/hooks/web/useContextMenu'; -export * from './src/types'; +export * from './src/typing'; diff --git a/src/components/Tree/src/Tree.vue b/src/components/Tree/src/Tree.vue index a9af80ac412..f4733313fc2 100644 --- a/src/components/Tree/src/Tree.vue +++ b/src/components/Tree/src/Tree.vue @@ -1,5 +1,5 @@ + diff --git a/src/components/Upload/src/UploadModal.vue b/src/components/Upload/src/UploadModal.vue index 5e1faba13d2..e2fa480d03d 100644 --- a/src/components/Upload/src/UploadModal.vue +++ b/src/components/Upload/src/UploadModal.vue @@ -50,7 +50,7 @@ import { useUploadType } from './useUpload'; import { useMessage } from '/@/hooks/web/useMessage'; // types - import { FileItem, UploadResultStatus } from './types'; + import { FileItem, UploadResultStatus } from './typing'; import { basicProps } from './props'; import { createTableColumns, createActionColumn } from './data'; // utils @@ -58,9 +58,9 @@ import { buildUUID } from '/@/utils/uuid'; import { isFunction } from '/@/utils/is'; import { warn } from '/@/utils/log'; - import FileList from './FileList'; - + import FileList from './FileList.vue'; import { useI18n } from '/@/hooks/web/useI18n'; + export default defineComponent({ components: { BasicModal, Upload, Alert, FileList }, props: { @@ -70,20 +70,20 @@ default: () => [], }, }, - emits: ['change', 'register'], + emits: ['change', 'register', 'delete'], setup(props, { emit }) { - const { t } = useI18n(); + const state = reactive<{ fileList: FileItem[] }>({ + fileList: [], + }); // 是否正在上传 const isUploadingRef = ref(false); const fileListRef = ref([]); - const state = reactive<{ fileList: FileItem[] }>({ - fileList: [], - }); + const { accept, helpText, maxNumber, maxSize } = toRefs(props); + const { t } = useI18n(); const [register, { closeModal }] = useModalInner(); - const { accept, helpText, maxNumber, maxSize } = toRefs(props); const { getAccept, getStringAccept, getHelpText } = useUploadType({ acceptRef: accept, helpTextRef: helpText, @@ -162,10 +162,12 @@ } return false; } + // 删除 function handleRemove(record: FileItem) { const index = fileListRef.value.findIndex((item) => item.uuid === record.uuid); index !== -1 && fileListRef.value.splice(index, 1); + emit('delete', record); } // 预览 diff --git a/src/components/Upload/src/UploadPreviewModal.vue b/src/components/Upload/src/UploadPreviewModal.vue index 9929aff0fcd..dca152ab1a1 100644 --- a/src/components/Upload/src/UploadPreviewModal.vue +++ b/src/components/Upload/src/UploadPreviewModal.vue @@ -12,18 +12,15 @@