Showing
3 changed files
with
45 additions
and
14 deletions
... | ... | @@ -9,7 +9,8 @@ |
9 | 9 | import { useMessage } from '/@/hooks/web/useMessage'; |
10 | 10 | import { computed, ref, unref, useAttrs } from 'vue'; |
11 | 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 | 15 | export interface FileItem { |
15 | 16 | uid: string; |
... | ... | @@ -19,6 +20,7 @@ |
19 | 20 | url?: string; |
20 | 21 | } |
21 | 22 | |
23 | + const { prefixCls } = useDesign('api-upload'); | |
22 | 24 | const emit = defineEmits(['update:fileList', 'preview', 'download']); |
23 | 25 | |
24 | 26 | const attrs = useAttrs(); |
... | ... | @@ -42,6 +44,7 @@ |
42 | 44 | disabled?: boolean; |
43 | 45 | listType?: string; |
44 | 46 | multiple?: boolean; |
47 | + maxFileLimit?: number; | |
45 | 48 | showUploadList?: boolean | { showPreviewIcon?: boolean; showRemoveIcon?: boolean }; |
46 | 49 | transformFile?: (file: File) => string | Blob | Promise<string | Blob | File>; |
47 | 50 | api: (file: string | Blob | Promise<string | Blob | File>) => Promise<FileItem>; |
... | ... | @@ -75,7 +78,14 @@ |
75 | 78 | if (api && isFunction(api)) { |
76 | 79 | const data = await api(file); |
77 | 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 | 89 | return; |
80 | 90 | } |
81 | 91 | window.console.error( |
... | ... | @@ -124,6 +134,7 @@ |
124 | 134 | <template> |
125 | 135 | <Upload.Dragger |
126 | 136 | class="block" |
137 | + :class="prefixCls" | |
127 | 138 | :file-list="props.fileList" |
128 | 139 | :disabled="getDisabled" |
129 | 140 | :before-upload="handleBeforeUpload" |
... | ... | @@ -140,4 +151,19 @@ |
140 | 151 | </Upload.Dragger> |
141 | 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 | 1 | import { BasicColumn, FormSchema } from '/@/components/Table'; |
2 | - | |
2 | +import { PackageField } from './packageDetail.config'; | |
3 | 3 | export const columns: BasicColumn[] = [ |
4 | 4 | { |
5 | 5 | title: '创建时间', |
6 | - dataIndex: 'createTime', | |
6 | + dataIndex: PackageField.CREATE_TIME, | |
7 | 7 | width: 120, |
8 | 8 | }, |
9 | 9 | { |
10 | 10 | title: '标题', |
11 | - dataIndex: 'title', | |
11 | + dataIndex: PackageField.TITLE, | |
12 | 12 | width: 120, |
13 | 13 | }, |
14 | 14 | { |
15 | 15 | title: '版本', |
16 | - dataIndex: 'version', | |
16 | + dataIndex: PackageField.VERSION, | |
17 | 17 | width: 120, |
18 | 18 | }, |
19 | 19 | { |
20 | 20 | title: '版本标签', |
21 | - dataIndex: 'versionLabel', | |
21 | + dataIndex: PackageField.VERSION_LABEL, | |
22 | 22 | width: 120, |
23 | 23 | }, |
24 | 24 | { |
25 | 25 | title: '包类型', |
26 | - dataIndex: 'pkgType', | |
26 | + dataIndex: PackageField.PACKAGE_TYPE, | |
27 | 27 | width: 120, |
28 | 28 | }, |
29 | 29 | { |
30 | 30 | title: '直接URL', |
31 | - dataIndex: 'url', | |
31 | + dataIndex: PackageField.PACKAGE_EXTERNAL_URL, | |
32 | 32 | width: 120, |
33 | 33 | }, |
34 | 34 | { |
35 | 35 | title: '文件大小', |
36 | - dataIndex: 'fileSize', | |
36 | + dataIndex: PackageField.FILE_SIZE, | |
37 | 37 | width: 120, |
38 | 38 | }, |
39 | 39 | { |
40 | 40 | title: '校验和', |
41 | - dataIndex: 'vaildateTotal', | |
41 | + dataIndex: PackageField.CHECK_SUM, | |
42 | 42 | width: 120, |
43 | 43 | }, |
44 | 44 | ]; |
45 | 45 | |
46 | 46 | export const searchFormSchema: FormSchema[] = [ |
47 | 47 | { |
48 | - field: 'name', | |
48 | + field: PackageField.TITLE, | |
49 | 49 | label: '标题', |
50 | 50 | component: 'Input', |
51 | 51 | colProps: { span: 8 }, | ... | ... |
... | ... | @@ -13,6 +13,9 @@ export enum PackageField { |
13 | 13 | ALG = 'alg', |
14 | 14 | CHECK_SUM = 'checkSum', |
15 | 15 | DESCRIPTION = 'description', |
16 | + | |
17 | + CREATE_TIME = 'createTIme', | |
18 | + FILE_SIZE = 'fileSize', | |
16 | 19 | } |
17 | 20 | |
18 | 21 | export enum PackageUpdateType { |
... | ... | @@ -123,8 +126,10 @@ export const formSchema: FormSchema[] = [ |
123 | 126 | valueField: PackageField.PACKAGE_BINARY_FILE, |
124 | 127 | changeEvent: `update:${PackageField.PACKAGE_BINARY_FILE}`, |
125 | 128 | componentProps: { |
129 | + maxFileLimit: 1, | |
126 | 130 | api: (_file: File) => { |
127 | - return {}; | |
131 | + console.log({ _file }); | |
132 | + return { uid: _file.uid, name: _file.name }; | |
128 | 133 | }, |
129 | 134 | }, |
130 | 135 | }, | ... | ... |