|
...
|
...
|
@@ -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> |
...
|
...
|
|