Skip to content

Commit 3f6920f

Browse files
committed
perf(component): optimize tree and upload components
1 parent fa828fd commit 3f6920f

File tree

18 files changed

+161
-159
lines changed

18 files changed

+161
-159
lines changed

src/components/Tree/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import BasicTree from './src/Tree.vue';
22

33
export { BasicTree };
44
export type { ContextMenuItem } from '/@/hooks/web/useContextMenu';
5-
export * from './src/types';
5+
export * from './src/typing';

src/components/Tree/src/Tree.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="tsx">
2-
import type { ReplaceFields, Keys, CheckKeys, TreeActionType, TreeItem } from './types';
2+
import type { ReplaceFields, Keys, CheckKeys, TreeActionType, TreeItem } from './typing';
33
44
import {
55
defineComponent,
@@ -30,7 +30,7 @@
3030
import { basicProps } from './props';
3131
import { CreateContextOptions } from '/@/components/ContextMenu';
3232
33-
import { CheckEvent } from './types';
33+
import { CheckEvent } from './typing';
3434
3535
interface State {
3636
expandedKeys: Keys;

src/components/Tree/src/TreeHeader.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@
4343
import { useI18n } from '/@/hooks/web/useI18n';
4444
import { useDebounceFn } from '@vueuse/core';
4545
46-
import { ToolbarEnum } from './enum';
46+
enum ToolbarEnum {
47+
SELECT_ALL,
48+
UN_SELECT_ALL,
49+
EXPAND_ALL,
50+
UN_EXPAND_ALL,
51+
CHECK_STRICTLY,
52+
CHECK_UN_STRICTLY,
53+
}
4754
4855
interface MenuInfo {
4956
key: ToolbarEnum;

src/components/Tree/src/enum.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/components/Tree/src/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { PropType } from 'vue';
2-
import type { ReplaceFields, ActionItem, Keys, CheckKeys, ContextMenuOptions } from './types';
2+
import type { ReplaceFields, ActionItem, Keys, CheckKeys, ContextMenuOptions } from './typing';
33
import type { ContextMenuItem } from '/@/hooks/web/useContextMenu';
44
import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
55
import { propTypes } from '/@/utils/propTypes';

src/components/Tree/src/useTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { InsertNodeParams, Keys, ReplaceFields } from './types';
1+
import type { InsertNodeParams, Keys, ReplaceFields } from './typing';
22
import type { Ref, ComputedRef } from 'vue';
33
import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
44

src/components/Upload/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export { default as BasicUpload } from './src/BasicUpload.vue';
1+
import { withInstall } from '/@/utils';
2+
import basicUpload from './src/BasicUpload.vue';
3+
4+
export const BasicUpload = withInstall(basicUpload);

src/components/Upload/src/BasicUpload.vue

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,41 @@
77
<Tooltip placement="bottom" v-if="showPreview">
88
<template #title>
99
{{ t('component.upload.uploaded') }}
10-
<template v-if="fileListRef.length">
11-
{{ fileListRef.length }}
10+
<template v-if="fileList.length">
11+
{{ fileList.length }}
1212
</template>
1313
</template>
1414
<a-button @click="openPreviewModal">
1515
<Icon icon="bi:eye" />
16-
<template v-if="fileListRef.length && showPreviewNumber">
17-
{{ fileListRef.length }}
16+
<template v-if="fileList.length && showPreviewNumber">
17+
{{ fileList.length }}
1818
</template>
1919
</a-button>
2020
</Tooltip>
2121
</a-button-group>
2222

2323
<UploadModal
2424
v-bind="bindValue"
25-
:previewFileList="fileListRef"
25+
:previewFileList="fileList"
2626
@register="registerUploadModal"
2727
@change="handleChange"
28+
@delete="handleDelete"
2829
/>
2930

3031
<UploadPreviewModal
31-
:value="fileListRef"
32+
:value="fileList"
3233
@register="registerPreviewModal"
3334
@list-change="handlePreviewChange"
3435
/>
3536
</div>
3637
</template>
3738
<script lang="ts">
3839
import { defineComponent, ref, watch, unref, computed } from 'vue';
39-
4040
import UploadModal from './UploadModal.vue';
4141
import UploadPreviewModal from './UploadPreviewModal.vue';
42-
import Icon from '/@/components/Icon';
42+
import { Icon } from '/@/components/Icon';
4343
import { Tooltip } from 'ant-design-vue';
44-
4544
import { useModal } from '/@/components/Modal';
46-
4745
import { uploadContainerProps } from './props';
4846
import { omit } from 'lodash-es';
4947
import { useI18n } from '/@/hooks/web/useI18n';
@@ -52,7 +50,7 @@
5250
name: 'BasicUpload',
5351
components: { UploadModal, UploadPreviewModal, Icon, Tooltip },
5452
props: uploadContainerProps,
55-
emits: ['change'],
53+
emits: ['change', 'delete'],
5654
5755
setup(props, { emit, attrs }) {
5856
const { t } = useI18n();
@@ -62,12 +60,12 @@
6260
// 预览modal
6361
const [registerPreviewModal, { openModal: openPreviewModal }] = useModal();
6462
65-
const fileListRef = ref<string[]>([]);
63+
const fileList = ref<string[]>([]);
6664
6765
const showPreview = computed(() => {
6866
const { emptyHidePreview } = props;
6967
if (!emptyHidePreview) return true;
70-
return emptyHidePreview ? fileListRef.value.length > 0 : true;
68+
return emptyHidePreview ? fileList.value.length > 0 : true;
7169
});
7270
7371
const bindValue = computed(() => {
@@ -78,21 +76,25 @@
7876
watch(
7977
() => props.value,
8078
(value = []) => {
81-
fileListRef.value = value;
79+
fileList.value = value;
8280
},
8381
{ immediate: true }
8482
);
8583
8684
// 上传modal保存操作
8785
function handleChange(urls: string[]) {
88-
fileListRef.value = [...unref(fileListRef), ...(urls || [])];
89-
emit('change', fileListRef.value);
86+
fileList.value = [...unref(fileList), ...(urls || [])];
87+
emit('change', fileList.value);
9088
}
9189
9290
// 预览modal保存操作
9391
function handlePreviewChange(urls: string[]) {
94-
fileListRef.value = [...(urls || [])];
95-
emit('change', fileListRef.value);
92+
fileList.value = [...(urls || [])];
93+
emit('change', fileList.value);
94+
}
95+
96+
function handleDelete(record: Recordable) {
97+
emit('delete', record);
9698
}
9799
98100
return {
@@ -102,9 +104,10 @@
102104
handlePreviewChange,
103105
registerPreviewModal,
104106
openPreviewModal,
105-
fileListRef,
107+
fileList,
106108
showPreview,
107109
bindValue,
110+
handleDelete,
108111
t,
109112
};
110113
},

src/components/Upload/src/FileList.less

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)