Commit 1c7d1fd721224531b6c908ae32f4ac589b858e6c

Authored by ww
1 parent c6bfc535

perf: ApiUpload component

@@ -9,7 +9,8 @@ @@ -9,7 +9,8 @@
9 import { useMessage } from '/@/hooks/web/useMessage'; 9 import { useMessage } from '/@/hooks/web/useMessage';
10 import { computed, ref, unref, useAttrs } from 'vue'; 10 import { computed, ref, unref, useAttrs } from 'vue';
11 import { cloneDeep } from 'lodash-es'; 11 import { cloneDeep } from 'lodash-es';
12 - import { isFunction, isObject } from '/@/utils/is'; 12 + import { isFunction, isNumber, isObject } from '/@/utils/is';
  13 + import { useDesign } from '/@/hooks/web/useDesign';
13 14
14 export interface FileItem { 15 export interface FileItem {
15 uid: string; 16 uid: string;
@@ -19,6 +20,7 @@ @@ -19,6 +20,7 @@
19 url?: string; 20 url?: string;
20 } 21 }
21 22
  23 + const { prefixCls } = useDesign('api-upload');
22 const emit = defineEmits(['update:fileList', 'preview', 'download']); 24 const emit = defineEmits(['update:fileList', 'preview', 'download']);
23 25
24 const attrs = useAttrs(); 26 const attrs = useAttrs();
@@ -42,6 +44,7 @@ @@ -42,6 +44,7 @@
42 disabled?: boolean; 44 disabled?: boolean;
43 listType?: string; 45 listType?: string;
44 multiple?: boolean; 46 multiple?: boolean;
  47 + maxFileLimit?: number;
45 showUploadList?: boolean | { showPreviewIcon?: boolean; showRemoveIcon?: boolean }; 48 showUploadList?: boolean | { showPreviewIcon?: boolean; showRemoveIcon?: boolean };
46 transformFile?: (file: File) => string | Blob | Promise<string | Blob | File>; 49 transformFile?: (file: File) => string | Blob | Promise<string | Blob | File>;
47 api: (file: string | Blob | Promise<string | Blob | File>) => Promise<FileItem>; 50 api: (file: string | Blob | Promise<string | Blob | File>) => Promise<FileItem>;
@@ -75,7 +78,14 @@ @@ -75,7 +78,14 @@
75 if (api && isFunction(api)) { 78 if (api && isFunction(api)) {
76 const data = await api(file); 79 const data = await api(file);
77 if (isObject(data) && Reflect.has(data, 'uid') && Reflect.has(data, 'name')) { 80 if (isObject(data) && Reflect.has(data, 'uid') && Reflect.has(data, 'name')) {
78 - emit('update:fileList', cloneDeep([...props.fileList, data])); 81 + const { fileList, maxFileLimit } = props;
  82 + let _fileList = cloneDeep(fileList);
  83 +
  84 + if (isNumber(maxFileLimit) && _fileList.length === maxFileLimit) {
  85 + _fileList.splice(0, 1);
  86 + }
  87 +
  88 + emit('update:fileList', cloneDeep([..._fileList, data]));
79 return; 89 return;
80 } 90 }
81 window.console.error( 91 window.console.error(
@@ -124,6 +134,7 @@ @@ -124,6 +134,7 @@
124 <template> 134 <template>
125 <Upload.Dragger 135 <Upload.Dragger
126 class="block" 136 class="block"
  137 + :class="prefixCls"
127 :file-list="props.fileList" 138 :file-list="props.fileList"
128 :disabled="getDisabled" 139 :disabled="getDisabled"
129 :before-upload="handleBeforeUpload" 140 :before-upload="handleBeforeUpload"
@@ -140,4 +151,19 @@ @@ -140,4 +151,19 @@
140 </Upload.Dragger> 151 </Upload.Dragger>
141 </template> 152 </template>
142 153
143 -<style></style> 154 +<style lang="less">
  155 + @basic-form: ~'@{namespace}-basic-form';
  156 + @prefix-cls: ~'@{namespace}-api-upload';
  157 +
  158 + .@{basic-form} {
  159 + // .ant-form-item-control-input-content > div > div {
  160 + // width: 100% !important;
  161 + // }
  162 +
  163 + .@{prefix-cls} {
  164 + .ant-upload-list-item-name {
  165 + width: calc(100% - 22px);
  166 + }
  167 + }
  168 + }
  169 +</style>
1 import { BasicColumn, FormSchema } from '/@/components/Table'; 1 import { BasicColumn, FormSchema } from '/@/components/Table';
2 - 2 +import { PackageField } from './packageDetail.config';
3 export const columns: BasicColumn[] = [ 3 export const columns: BasicColumn[] = [
4 { 4 {
5 title: '创建时间', 5 title: '创建时间',
6 - dataIndex: 'createTime', 6 + dataIndex: PackageField.CREATE_TIME,
7 width: 120, 7 width: 120,
8 }, 8 },
9 { 9 {
10 title: '标题', 10 title: '标题',
11 - dataIndex: 'title', 11 + dataIndex: PackageField.TITLE,
12 width: 120, 12 width: 120,
13 }, 13 },
14 { 14 {
15 title: '版本', 15 title: '版本',
16 - dataIndex: 'version', 16 + dataIndex: PackageField.VERSION,
17 width: 120, 17 width: 120,
18 }, 18 },
19 { 19 {
20 title: '版本标签', 20 title: '版本标签',
21 - dataIndex: 'versionLabel', 21 + dataIndex: PackageField.VERSION_LABEL,
22 width: 120, 22 width: 120,
23 }, 23 },
24 { 24 {
25 title: '包类型', 25 title: '包类型',
26 - dataIndex: 'pkgType', 26 + dataIndex: PackageField.PACKAGE_TYPE,
27 width: 120, 27 width: 120,
28 }, 28 },
29 { 29 {
30 title: '直接URL', 30 title: '直接URL',
31 - dataIndex: 'url', 31 + dataIndex: PackageField.PACKAGE_EXTERNAL_URL,
32 width: 120, 32 width: 120,
33 }, 33 },
34 { 34 {
35 title: '文件大小', 35 title: '文件大小',
36 - dataIndex: 'fileSize', 36 + dataIndex: PackageField.FILE_SIZE,
37 width: 120, 37 width: 120,
38 }, 38 },
39 { 39 {
40 title: '校验和', 40 title: '校验和',
41 - dataIndex: 'vaildateTotal', 41 + dataIndex: PackageField.CHECK_SUM,
42 width: 120, 42 width: 120,
43 }, 43 },
44 ]; 44 ];
45 45
46 export const searchFormSchema: FormSchema[] = [ 46 export const searchFormSchema: FormSchema[] = [
47 { 47 {
48 - field: 'name', 48 + field: PackageField.TITLE,
49 label: '标题', 49 label: '标题',
50 component: 'Input', 50 component: 'Input',
51 colProps: { span: 8 }, 51 colProps: { span: 8 },
@@ -13,6 +13,9 @@ export enum PackageField { @@ -13,6 +13,9 @@ export enum PackageField {
13 ALG = 'alg', 13 ALG = 'alg',
14 CHECK_SUM = 'checkSum', 14 CHECK_SUM = 'checkSum',
15 DESCRIPTION = 'description', 15 DESCRIPTION = 'description',
  16 +
  17 + CREATE_TIME = 'createTIme',
  18 + FILE_SIZE = 'fileSize',
16 } 19 }
17 20
18 export enum PackageUpdateType { 21 export enum PackageUpdateType {
@@ -123,8 +126,10 @@ export const formSchema: FormSchema[] = [ @@ -123,8 +126,10 @@ export const formSchema: FormSchema[] = [
123 valueField: PackageField.PACKAGE_BINARY_FILE, 126 valueField: PackageField.PACKAGE_BINARY_FILE,
124 changeEvent: `update:${PackageField.PACKAGE_BINARY_FILE}`, 127 changeEvent: `update:${PackageField.PACKAGE_BINARY_FILE}`,
125 componentProps: { 128 componentProps: {
  129 + maxFileLimit: 1,
126 api: (_file: File) => { 130 api: (_file: File) => {
127 - return {}; 131 + console.log({ _file });
  132 + return { uid: _file.uid, name: _file.name };
128 }, 133 },
129 }, 134 },
130 }, 135 },