Skip to content

Commit

Permalink
perf(component): optimize tree and upload components
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jun 11, 2021
1 parent fa828fd commit 3f6920f
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 159 deletions.
2 changes: 1 addition & 1 deletion src/components/Tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
4 changes: 2 additions & 2 deletions src/components/Tree/src/Tree.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="tsx">
import type { ReplaceFields, Keys, CheckKeys, TreeActionType, TreeItem } from './types';
import type { ReplaceFields, Keys, CheckKeys, TreeActionType, TreeItem } from './typing';
import {
defineComponent,
Expand Down Expand Up @@ -30,7 +30,7 @@
import { basicProps } from './props';
import { CreateContextOptions } from '/@/components/ContextMenu';
import { CheckEvent } from './types';
import { CheckEvent } from './typing';
interface State {
expandedKeys: Keys;
Expand Down
9 changes: 8 additions & 1 deletion src/components/Tree/src/TreeHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@
import { useI18n } from '/@/hooks/web/useI18n';
import { useDebounceFn } from '@vueuse/core';
import { ToolbarEnum } from './enum';
enum ToolbarEnum {
SELECT_ALL,
UN_SELECT_ALL,
EXPAND_ALL,
UN_EXPAND_ALL,
CHECK_STRICTLY,
CHECK_UN_STRICTLY,
}
interface MenuInfo {
key: ToolbarEnum;
Expand Down
8 changes: 0 additions & 8 deletions src/components/Tree/src/enum.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/Tree/src/props.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PropType } from 'vue';
import type { ReplaceFields, ActionItem, Keys, CheckKeys, ContextMenuOptions } from './types';
import type { ReplaceFields, ActionItem, Keys, CheckKeys, ContextMenuOptions } from './typing';
import type { ContextMenuItem } from '/@/hooks/web/useContextMenu';
import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
import { propTypes } from '/@/utils/propTypes';
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/Tree/src/useTree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { InsertNodeParams, Keys, ReplaceFields } from './types';
import type { InsertNodeParams, Keys, ReplaceFields } from './typing';
import type { Ref, ComputedRef } from 'vue';
import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree';

Expand Down
5 changes: 4 additions & 1 deletion src/components/Upload/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { default as BasicUpload } from './src/BasicUpload.vue';
import { withInstall } from '/@/utils';
import basicUpload from './src/BasicUpload.vue';

export const BasicUpload = withInstall(basicUpload);
41 changes: 22 additions & 19 deletions src/components/Upload/src/BasicUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,41 @@
<Tooltip placement="bottom" v-if="showPreview">
<template #title>
{{ t('component.upload.uploaded') }}
<template v-if="fileListRef.length">
{{ fileListRef.length }}
<template v-if="fileList.length">
{{ fileList.length }}
</template>
</template>
<a-button @click="openPreviewModal">
<Icon icon="bi:eye" />
<template v-if="fileListRef.length && showPreviewNumber">
{{ fileListRef.length }}
<template v-if="fileList.length && showPreviewNumber">
{{ fileList.length }}
</template>
</a-button>
</Tooltip>
</a-button-group>

<UploadModal
v-bind="bindValue"
:previewFileList="fileListRef"
:previewFileList="fileList"
@register="registerUploadModal"
@change="handleChange"
@delete="handleDelete"
/>

<UploadPreviewModal
:value="fileListRef"
:value="fileList"
@register="registerPreviewModal"
@list-change="handlePreviewChange"
/>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, watch, unref, computed } from 'vue';
import UploadModal from './UploadModal.vue';
import UploadPreviewModal from './UploadPreviewModal.vue';
import Icon from '/@/components/Icon';
import { Icon } from '/@/components/Icon';
import { Tooltip } from 'ant-design-vue';
import { useModal } from '/@/components/Modal';
import { uploadContainerProps } from './props';
import { omit } from 'lodash-es';
import { useI18n } from '/@/hooks/web/useI18n';
Expand All @@ -52,7 +50,7 @@
name: 'BasicUpload',
components: { UploadModal, UploadPreviewModal, Icon, Tooltip },
props: uploadContainerProps,
emits: ['change'],
emits: ['change', 'delete'],
setup(props, { emit, attrs }) {
const { t } = useI18n();
Expand All @@ -62,12 +60,12 @@
// 预览modal
const [registerPreviewModal, { openModal: openPreviewModal }] = useModal();
const fileListRef = ref<string[]>([]);
const fileList = ref<string[]>([]);
const showPreview = computed(() => {
const { emptyHidePreview } = props;
if (!emptyHidePreview) return true;
return emptyHidePreview ? fileListRef.value.length > 0 : true;
return emptyHidePreview ? fileList.value.length > 0 : true;
});
const bindValue = computed(() => {
Expand All @@ -78,21 +76,25 @@
watch(
() => props.value,
(value = []) => {
fileListRef.value = value;
fileList.value = value;
},
{ immediate: true }
);
// 上传modal保存操作
function handleChange(urls: string[]) {
fileListRef.value = [...unref(fileListRef), ...(urls || [])];
emit('change', fileListRef.value);
fileList.value = [...unref(fileList), ...(urls || [])];
emit('change', fileList.value);
}
// 预览modal保存操作
function handlePreviewChange(urls: string[]) {
fileListRef.value = [...(urls || [])];
emit('change', fileListRef.value);
fileList.value = [...(urls || [])];
emit('change', fileList.value);
}
function handleDelete(record: Recordable) {
emit('delete', record);
}
return {
Expand All @@ -102,9 +104,10 @@
handlePreviewChange,
registerPreviewModal,
openPreviewModal,
fileListRef,
fileList,
showPreview,
bindValue,
handleDelete,
t,
};
},
Expand Down
31 changes: 0 additions & 31 deletions src/components/Upload/src/FileList.less

This file was deleted.

72 changes: 0 additions & 72 deletions src/components/Upload/src/FileList.tsx

This file was deleted.

104 changes: 104 additions & 0 deletions src/components/Upload/src/FileList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<script lang="tsx">
import { defineComponent, CSSProperties, watch, nextTick } from 'vue';
import { fileListProps } from './props';
import { isFunction } from '/@/utils/is';
import { useModalContext } from '/@/components/Modal/src/hooks/useModalContext';
export default defineComponent({
name: 'FileList',
props: fileListProps,
setup(props) {
const modalFn = useModalContext();
watch(
() => props.dataSource,
() => {
nextTick(() => {
modalFn?.redoModalHeight?.();
});
}
);
return () => {
const { columns, actionColumn, dataSource } = props;
const columnList = [...columns, actionColumn];
return (
<table class="file-table">
<colgroup>
{columnList.map((item) => {
const { width = 0, dataIndex } = item;
const style: CSSProperties = {
width: `${width}px`,
minWidth: `${width}px`,
};
return <col style={width ? style : {}} key={dataIndex} />;
})}
</colgroup>
<thead>
<tr class="file-table-tr">
{columnList.map((item) => {
const { title = '', align = 'center', dataIndex } = item;
return (
<th class={['file-table-th', align]} key={dataIndex}>
{title}
</th>
);
})}
</tr>
</thead>
<tbody>
{dataSource.map((record = {}, index) => {
return (
<tr class="file-table-tr" key={`${index + record.name || ''}`}>
{columnList.map((item) => {
const { dataIndex = '', customRender, align = 'center' } = item;
const render = customRender && isFunction(customRender);
return (
<td class={['file-table-td', align]} key={dataIndex}>
{render
? customRender?.({ text: record[dataIndex], record })
: record[dataIndex]}
</td>
);
})}
</tr>
);
})}
</tbody>
</table>
);
};
},
});
</script>
<style lang="less">
.file-table {
width: 100%;
border-collapse: collapse;
.center {
text-align: center;
}
.left {
text-align: left;
}
.right {
text-align: right;
}
&-th,
&-td {
padding: 12px 8px;
}
thead {
background-color: @background-color-light;
}
table,
td,
th {
border: 1px solid @border-color-base;
}
}
</style>
Loading

0 comments on commit 3f6920f

Please sign in to comment.