@idooel/components 0.0.2-beta.12 → 0.0.2-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -98
- package/dist/@idooel/components.esm.js +1061 -253
- package/dist/@idooel/components.umd.js +1064 -256
- package/jsconfig.json +7 -7
- package/package.json +61 -61
- package/packages/alert/index.js +4 -4
- package/packages/alert/src/index.vue +45 -45
- package/packages/batch-export/index.js +4 -4
- package/packages/batch-export/src/index.vue +104 -104
- package/packages/business-components/modal-fsm/index.js +4 -4
- package/packages/business-components/modal-fsm/src/index.vue +163 -163
- package/packages/business-components/modal-import/index.js +4 -4
- package/packages/business-components/modal-import/src/index.vue +201 -139
- package/packages/business-components/modal-timeline/index.js +4 -4
- package/packages/business-components/modal-timeline/src/index.vue +77 -77
- package/packages/business-components/tabs-sub-center/index.js +4 -4
- package/packages/business-components/tabs-sub-center/src/index.vue +116 -116
- package/packages/button/index.js +4 -4
- package/packages/button/src/index.vue +65 -65
- package/packages/checkbox/index.js +4 -4
- package/packages/checkbox/src/index.vue +52 -52
- package/packages/composite-components/button-group/index.js +4 -4
- package/packages/composite-components/button-group/src/index.vue +151 -151
- package/packages/composite-components/form-attachment/src/index.vue +14 -14
- package/packages/composite-components/form-img-crop/index.js +4 -4
- package/packages/composite-components/form-img-crop/src/index.vue +131 -131
- package/packages/composite-components/modal-confirm/index.js +4 -4
- package/packages/composite-components/modal-confirm/src/index.vue +103 -103
- package/packages/composite-components/modal-form/index.js +4 -4
- package/packages/composite-components/modal-form/src/index.vue +230 -230
- package/packages/composite-components/modal-img-crop/index.js +4 -4
- package/packages/composite-components/modal-img-crop/src/index.vue +298 -298
- package/packages/composite-components/modal-table/index.js +4 -4
- package/packages/composite-components/modal-table/src/index.vue +155 -155
- package/packages/composite-components/modal-tree/index.js +4 -4
- package/packages/composite-components/modal-tree/src/index.vue +75 -75
- package/packages/composite-components/search-area/index.js +4 -4
- package/packages/composite-components/search-area/src/index.vue +238 -237
- package/packages/composite-components/search-area/src/label.vue +35 -35
- package/packages/composite-components/select-entity-modal-table/index.js +4 -4
- package/packages/composite-components/select-entity-modal-table/src/index.vue +171 -171
- package/packages/date/index.js +4 -4
- package/packages/date/src/index.vue +112 -112
- package/packages/date-range/index.js +4 -4
- package/packages/date-range/src/index.vue +47 -47
- package/packages/form/index.js +4 -4
- package/packages/form/src/index.vue +319 -319
- package/packages/icon/index.js +4 -4
- package/packages/icon/src/index.vue +31 -31
- package/packages/index.js +156 -153
- package/packages/input/index.js +4 -4
- package/packages/input/src/index.vue +35 -35
- package/packages/input-number/index.js +4 -4
- package/packages/input-number/src/index.vue +23 -23
- package/packages/loading/index.js +4 -4
- package/packages/loading/src/index.vue +36 -36
- package/packages/meta/provider.js +4 -0
- package/packages/modal/index.js +4 -4
- package/packages/modal/src/index.vue +184 -184
- package/packages/models/form-group-model/index.js +4 -4
- package/packages/models/form-group-model/src/index.vue +273 -273
- package/packages/models/form-model/index.js +4 -4
- package/packages/models/form-model/src/index.vue +236 -236
- package/packages/models/step-model/index.js +4 -4
- package/packages/models/step-model/src/index.vue +224 -224
- package/packages/models/tree-table-model/index.js +4 -4
- package/packages/models/tree-table-model/src/index.vue +806 -764
- package/packages/radio/index.js +4 -4
- package/packages/radio/src/index.vue +56 -56
- package/packages/select/index.js +4 -4
- package/packages/select/src/index.vue +105 -105
- package/packages/select-entity/index.js +4 -4
- package/packages/select-entity/src/index.vue +119 -119
- package/packages/table/index.js +4 -4
- package/packages/table/src/action.vue +172 -172
- package/packages/table/src/index.vue +339 -319
- package/packages/tabs/index.js +4 -4
- package/packages/tabs/src/index.vue +55 -55
- package/packages/text/index.js +4 -4
- package/packages/text/src/index.vue +47 -47
- package/packages/text-editor/index.js +4 -4
- package/packages/text-editor/src/index.vue +72 -72
- package/packages/textarea/index.js +4 -4
- package/packages/textarea/src/index.vue +57 -57
- package/packages/theme/form.scss +21 -21
- package/packages/theme/index.scss +43 -43
- package/packages/theme/overrid.scss +7 -7
- package/packages/theme/styleClass.scss +2 -2
- package/packages/theme/variables.scss +55 -55
- package/packages/timeline/index.js +4 -4
- package/packages/timeline/src/index.vue +257 -257
- package/packages/tpl/index.js +4 -4
- package/packages/tpl/src/index.vue +55 -55
- package/packages/tree/index.js +4 -4
- package/packages/tree/src/TreeNode.vue +29 -29
- package/packages/tree/src/index.vue +101 -101
- package/packages/tree-select/index.js +4 -4
- package/packages/tree-select/src/index.vue +142 -142
- package/packages/upload/index.js +4 -4
- package/packages/upload/src/index.vue +998 -996
- package/packages/utils/index.js +66 -62
- package/packages/utils/runtime-context/dataPoolAPI.js +501 -0
- package/packages/utils/runtime-context/globalDataPool.js +279 -0
- package/packages/utils/runtime-context/index.js +76 -0
- package/packages/utils/runtime-context/modelSchema.js +174 -0
- package/scripts/rollup.config.js +42 -42
- package/scripts/rollup.esm.config.js +11 -11
- package/scripts/rollup.umd.config.js +17 -17
- package/vitest.config.js +17 -17
- package/packages/utils/dataPool.js +0 -22
- package/packages/utils/treeTableDataPoolManager.js +0 -85
|
@@ -1,997 +1,999 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="ele-upload__wrapper">
|
|
3
|
-
<FileUpload
|
|
4
|
-
class="ele-upload__inner"
|
|
5
|
-
v-show="isShowUploadContainer"
|
|
6
|
-
v-model="files"
|
|
7
|
-
:ref="uploadRef"
|
|
8
|
-
:drop="drop"
|
|
9
|
-
:chunk-enabled="chunkEnabled"
|
|
10
|
-
:chunk="chunkConfig"
|
|
11
|
-
:accept="accept"
|
|
12
|
-
:size="fileSizeLimit"
|
|
13
|
-
:post-action="postAction"
|
|
14
|
-
:multiple="multiple"
|
|
15
|
-
:headers="headers"
|
|
16
|
-
:maximum="getMaximum"
|
|
17
|
-
:data="uploadParams"
|
|
18
|
-
@input-file="onWatchInputFiles"
|
|
19
|
-
@input="onWatchFiles"
|
|
20
|
-
style="width: 100%;">
|
|
21
|
-
<section class="ele-upload__area">
|
|
22
|
-
<div class="ele-upload__area--icon">
|
|
23
|
-
<template v-if="iconIsZhWrod">
|
|
24
|
-
{{ icon }}
|
|
25
|
-
</template>
|
|
26
|
-
<template v-else>
|
|
27
|
-
<ele-icon :type="icon"></ele-icon>
|
|
28
|
-
</template>
|
|
29
|
-
</div>
|
|
30
|
-
<div class="ele-upload__area--text">
|
|
31
|
-
<div class="ele-upload__message" v-if="message" v-html="message"></div>
|
|
32
|
-
<div class="ele-upload__message" v-else>单击或拖动文件到该区域以上传</div>
|
|
33
|
-
<div class="ele-upload__ext" v-if="ext" v-html="ext"></div>
|
|
34
|
-
<div class="ele-upload__ext" v-else>文件小于{{ size }}M</div>
|
|
35
|
-
</div>
|
|
36
|
-
</section>
|
|
37
|
-
</FileUpload>
|
|
38
|
-
<section class="ele-files__wrapper">
|
|
39
|
-
<!-- 显示正在上传的文件(有进度条) -->
|
|
40
|
-
<div class="ele-file__item" v-for="(file, idx) in uploadingFiles" :key="`uploading-${idx}`">
|
|
41
|
-
<div class="ele-file__suffix--icon">
|
|
42
|
-
<ele-icon :type="fileSuffixIcon[file.suffix] ? fileSuffixIcon[file.suffix].name : 'icon-file'"></ele-icon>
|
|
43
|
-
</div>
|
|
44
|
-
<div class="ele-file__name">
|
|
45
|
-
<div class="ele-file__inner">{{ file.name }}</div>
|
|
46
|
-
<div v-if="file.progress !== undefined" class="ele-uplpad__progress">
|
|
47
|
-
<a-progress :strokeWidth="2" :percent="Number(file.progress)" size="small" />
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
<div class="ele-file__delete" v-if="file.success || file.error">
|
|
51
|
-
<span class="ele-file__size">{{ (file.size / byteConversion).toFixed(2) }}M</span>
|
|
52
|
-
<span class="ele-file__delete--icon" @click="handleClickDelete(file)">
|
|
53
|
-
<ele-icon type="delete"></ele-icon>
|
|
54
|
-
</span>
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
|
|
58
|
-
<!-- 显示已上传完成的文件 -->
|
|
59
|
-
<div class="ele-file__item" v-for="(file, idx) in completedFiles" :key="`completed-${idx}`">
|
|
60
|
-
<div class="ele-file__suffix--icon">
|
|
61
|
-
<ele-icon :type="fileSuffixIcon[file.suffix] ? fileSuffixIcon[file.suffix].name : 'icon-file'"></ele-icon>
|
|
62
|
-
</div>
|
|
63
|
-
<div class="ele-file__name">
|
|
64
|
-
<div class="ele-file__inner" @click="handleClickDownload(file)">{{ file.name }}</div>
|
|
65
|
-
</div>
|
|
66
|
-
<div class="ele-file__delete">
|
|
67
|
-
<span class="ele-file__size">{{ (file.size / byteConversion).toFixed(2) }}M</span>
|
|
68
|
-
<span class="ele-file__delete--icon" @click="handleClickDelete(file)">
|
|
69
|
-
<ele-icon type="delete"></ele-icon>
|
|
70
|
-
</span>
|
|
71
|
-
</div>
|
|
72
|
-
</div>
|
|
73
|
-
</section>
|
|
74
|
-
</div>
|
|
75
|
-
</template>
|
|
76
|
-
|
|
77
|
-
<script>
|
|
78
|
-
import FileUpload from 'vue-upload-component'
|
|
79
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
80
|
-
import { route, net, type } from '@idooel/shared'
|
|
81
|
-
|
|
82
|
-
// 常量定义
|
|
83
|
-
const CONSTANTS = {
|
|
84
|
-
DEFAULT_URL: 'zuul/api-file/workbench/file',
|
|
85
|
-
DEFAULT_ICON: '上传',
|
|
86
|
-
DEFAULT_SIZE: 100,
|
|
87
|
-
DEFAULT_MESSAGE: '单击或拖动文件到该区域以上传',
|
|
88
|
-
DEFAULT_MAXIMUM: 20,
|
|
89
|
-
BYTE_CONVERSION: 1024 * 1024,
|
|
90
|
-
CHUNK_MIN_SIZE: 3 * 1024 * 1024,
|
|
91
|
-
CHUNK_MAX_ACTIVE: 3,
|
|
92
|
-
CHUNK_MAX_RETRIES: 5,
|
|
93
|
-
SAVE_INTERVAL: 2000
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 文件后缀图标映射
|
|
97
|
-
const FILE_SUFFIX_ICONS = {
|
|
98
|
-
'doc': { name: 'icon-doc' },
|
|
99
|
-
'html': { name: 'icon-html' },
|
|
100
|
-
'mp4': { name: 'icon-mp' },
|
|
101
|
-
'pdf': { name: 'icon-pdf' },
|
|
102
|
-
'ppt': { name: 'icon-ppt' },
|
|
103
|
-
'psd': { name: 'icon-psd' },
|
|
104
|
-
'rtf': { name: 'icon-rtf' },
|
|
105
|
-
'txt': { name: 'icon-txt' },
|
|
106
|
-
'vis': { name: 'icon-vis' },
|
|
107
|
-
'xls': { name: 'icon-xls' },
|
|
108
|
-
'xml': { name: 'icon-xml' },
|
|
109
|
-
'zip': { name: 'icon-zip' },
|
|
110
|
-
'jpg': { name: 'icon-img' },
|
|
111
|
-
'mp3': { name: 'icon-mp1' }
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export default {
|
|
115
|
-
name: 'ele-upload',
|
|
116
|
-
components: {
|
|
117
|
-
FileUpload
|
|
118
|
-
},
|
|
119
|
-
model: {
|
|
120
|
-
prop: 'value',
|
|
121
|
-
event: 'change'
|
|
122
|
-
},
|
|
123
|
-
props: {
|
|
124
|
-
url: {
|
|
125
|
-
type: String,
|
|
126
|
-
default: CONSTANTS.DEFAULT_URL
|
|
127
|
-
},
|
|
128
|
-
icon: {
|
|
129
|
-
type: String,
|
|
130
|
-
default: CONSTANTS.DEFAULT_ICON
|
|
131
|
-
},
|
|
132
|
-
size: {
|
|
133
|
-
type: Number,
|
|
134
|
-
default: CONSTANTS.DEFAULT_SIZE
|
|
135
|
-
},
|
|
136
|
-
message: {
|
|
137
|
-
type: String,
|
|
138
|
-
default: CONSTANTS.DEFAULT_MESSAGE
|
|
139
|
-
},
|
|
140
|
-
ext: {
|
|
141
|
-
type: String
|
|
142
|
-
},
|
|
143
|
-
extensions: {
|
|
144
|
-
type: String
|
|
145
|
-
},
|
|
146
|
-
accept: {
|
|
147
|
-
type: String
|
|
148
|
-
},
|
|
149
|
-
maximum: {
|
|
150
|
-
type: Number,
|
|
151
|
-
default: CONSTANTS.DEFAULT_MAXIMUM
|
|
152
|
-
},
|
|
153
|
-
multiple: {
|
|
154
|
-
type: Boolean,
|
|
155
|
-
default: false
|
|
156
|
-
},
|
|
157
|
-
drop: {
|
|
158
|
-
type: Boolean,
|
|
159
|
-
default: true
|
|
160
|
-
},
|
|
161
|
-
value: {
|
|
162
|
-
type: [String, Array]
|
|
163
|
-
},
|
|
164
|
-
querys: {
|
|
165
|
-
type: Object,
|
|
166
|
-
default: () => ({
|
|
167
|
-
_csrf: localStorage.getItem('token')
|
|
168
|
-
})
|
|
169
|
-
},
|
|
170
|
-
headers: {
|
|
171
|
-
type: Object,
|
|
172
|
-
default: () => ({
|
|
173
|
-
'X-XSRF-TOKEN': localStorage.getItem('token')
|
|
174
|
-
})
|
|
175
|
-
},
|
|
176
|
-
byteConversion: {
|
|
177
|
-
type: Number,
|
|
178
|
-
default: CONSTANTS.BYTE_CONVERSION
|
|
179
|
-
},
|
|
180
|
-
chunkEnabled: {
|
|
181
|
-
type: Boolean,
|
|
182
|
-
default: true
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
data() {
|
|
186
|
-
return {
|
|
187
|
-
// 文件状态管理
|
|
188
|
-
files: [], // vue-upload-component 管理的文件
|
|
189
|
-
buildedFiles: [], // 已构建完成的文件列表
|
|
190
|
-
|
|
191
|
-
// 上传状态管理
|
|
192
|
-
saveToServerAsyncPageTimer: null,
|
|
193
|
-
uploadRefId: null,
|
|
194
|
-
// 多选且外部无值时,预先生成 groupId,确保首次上传参数完整
|
|
195
|
-
groupId: (this.multiple && !this.value) ? uuidv4() : null
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.
|
|
212
|
-
} else {
|
|
213
|
-
this.
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (this.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
await this.
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
console.log('
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
console.
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
console.log('
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
console.log('
|
|
586
|
-
console.log('
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
*
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
this.
|
|
729
|
-
} else if (
|
|
730
|
-
this.
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
console.log('
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
console.log('
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
console.log('
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
*
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
console.log('
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
1
|
+
<template>
|
|
2
|
+
<div class="ele-upload__wrapper">
|
|
3
|
+
<FileUpload
|
|
4
|
+
class="ele-upload__inner"
|
|
5
|
+
v-show="isShowUploadContainer"
|
|
6
|
+
v-model="files"
|
|
7
|
+
:ref="uploadRef"
|
|
8
|
+
:drop="drop"
|
|
9
|
+
:chunk-enabled="chunkEnabled"
|
|
10
|
+
:chunk="chunkConfig"
|
|
11
|
+
:accept="accept"
|
|
12
|
+
:size="fileSizeLimit"
|
|
13
|
+
:post-action="postAction"
|
|
14
|
+
:multiple="multiple"
|
|
15
|
+
:headers="headers"
|
|
16
|
+
:maximum="getMaximum"
|
|
17
|
+
:data="uploadParams"
|
|
18
|
+
@input-file="onWatchInputFiles"
|
|
19
|
+
@input="onWatchFiles"
|
|
20
|
+
style="width: 100%;">
|
|
21
|
+
<section class="ele-upload__area">
|
|
22
|
+
<div class="ele-upload__area--icon">
|
|
23
|
+
<template v-if="iconIsZhWrod">
|
|
24
|
+
{{ icon }}
|
|
25
|
+
</template>
|
|
26
|
+
<template v-else>
|
|
27
|
+
<ele-icon :type="icon"></ele-icon>
|
|
28
|
+
</template>
|
|
29
|
+
</div>
|
|
30
|
+
<div class="ele-upload__area--text">
|
|
31
|
+
<div class="ele-upload__message" v-if="message" v-html="message"></div>
|
|
32
|
+
<div class="ele-upload__message" v-else>单击或拖动文件到该区域以上传</div>
|
|
33
|
+
<div class="ele-upload__ext" v-if="ext" v-html="ext"></div>
|
|
34
|
+
<div class="ele-upload__ext" v-else>文件小于{{ size }}M</div>
|
|
35
|
+
</div>
|
|
36
|
+
</section>
|
|
37
|
+
</FileUpload>
|
|
38
|
+
<section class="ele-files__wrapper">
|
|
39
|
+
<!-- 显示正在上传的文件(有进度条) -->
|
|
40
|
+
<div class="ele-file__item" v-for="(file, idx) in uploadingFiles" :key="`uploading-${idx}`">
|
|
41
|
+
<div class="ele-file__suffix--icon">
|
|
42
|
+
<ele-icon :type="fileSuffixIcon[file.suffix] ? fileSuffixIcon[file.suffix].name : 'icon-file'"></ele-icon>
|
|
43
|
+
</div>
|
|
44
|
+
<div class="ele-file__name">
|
|
45
|
+
<div class="ele-file__inner">{{ file.name }}</div>
|
|
46
|
+
<div v-if="file.progress !== undefined" class="ele-uplpad__progress">
|
|
47
|
+
<a-progress :strokeWidth="2" :percent="Number(file.progress)" size="small" />
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
<div class="ele-file__delete" v-if="file.success || file.error">
|
|
51
|
+
<span class="ele-file__size">{{ (file.size / byteConversion).toFixed(2) }}M</span>
|
|
52
|
+
<span class="ele-file__delete--icon" @click="handleClickDelete(file)">
|
|
53
|
+
<ele-icon type="delete"></ele-icon>
|
|
54
|
+
</span>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
<!-- 显示已上传完成的文件 -->
|
|
59
|
+
<div class="ele-file__item" v-for="(file, idx) in completedFiles" :key="`completed-${idx}`">
|
|
60
|
+
<div class="ele-file__suffix--icon">
|
|
61
|
+
<ele-icon :type="fileSuffixIcon[file.suffix] ? fileSuffixIcon[file.suffix].name : 'icon-file'"></ele-icon>
|
|
62
|
+
</div>
|
|
63
|
+
<div class="ele-file__name">
|
|
64
|
+
<div class="ele-file__inner" @click="handleClickDownload(file)">{{ file.name }}</div>
|
|
65
|
+
</div>
|
|
66
|
+
<div class="ele-file__delete">
|
|
67
|
+
<span class="ele-file__size">{{ (file.size / byteConversion).toFixed(2) }}M</span>
|
|
68
|
+
<span class="ele-file__delete--icon" @click="handleClickDelete(file)">
|
|
69
|
+
<ele-icon type="delete"></ele-icon>
|
|
70
|
+
</span>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</section>
|
|
74
|
+
</div>
|
|
75
|
+
</template>
|
|
76
|
+
|
|
77
|
+
<script>
|
|
78
|
+
import FileUpload from 'vue-upload-component'
|
|
79
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
80
|
+
import { route, net, type } from '@idooel/shared'
|
|
81
|
+
|
|
82
|
+
// 常量定义
|
|
83
|
+
const CONSTANTS = {
|
|
84
|
+
DEFAULT_URL: 'zuul/api-file/workbench/file',
|
|
85
|
+
DEFAULT_ICON: '上传',
|
|
86
|
+
DEFAULT_SIZE: 100,
|
|
87
|
+
DEFAULT_MESSAGE: '单击或拖动文件到该区域以上传',
|
|
88
|
+
DEFAULT_MAXIMUM: 20,
|
|
89
|
+
BYTE_CONVERSION: 1024 * 1024,
|
|
90
|
+
CHUNK_MIN_SIZE: 3 * 1024 * 1024,
|
|
91
|
+
CHUNK_MAX_ACTIVE: 3,
|
|
92
|
+
CHUNK_MAX_RETRIES: 5,
|
|
93
|
+
SAVE_INTERVAL: 2000
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 文件后缀图标映射
|
|
97
|
+
const FILE_SUFFIX_ICONS = {
|
|
98
|
+
'doc': { name: 'icon-doc' },
|
|
99
|
+
'html': { name: 'icon-html' },
|
|
100
|
+
'mp4': { name: 'icon-mp' },
|
|
101
|
+
'pdf': { name: 'icon-pdf' },
|
|
102
|
+
'ppt': { name: 'icon-ppt' },
|
|
103
|
+
'psd': { name: 'icon-psd' },
|
|
104
|
+
'rtf': { name: 'icon-rtf' },
|
|
105
|
+
'txt': { name: 'icon-txt' },
|
|
106
|
+
'vis': { name: 'icon-vis' },
|
|
107
|
+
'xls': { name: 'icon-xls' },
|
|
108
|
+
'xml': { name: 'icon-xml' },
|
|
109
|
+
'zip': { name: 'icon-zip' },
|
|
110
|
+
'jpg': { name: 'icon-img' },
|
|
111
|
+
'mp3': { name: 'icon-mp1' }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default {
|
|
115
|
+
name: 'ele-upload',
|
|
116
|
+
components: {
|
|
117
|
+
FileUpload
|
|
118
|
+
},
|
|
119
|
+
model: {
|
|
120
|
+
prop: 'value',
|
|
121
|
+
event: 'change'
|
|
122
|
+
},
|
|
123
|
+
props: {
|
|
124
|
+
url: {
|
|
125
|
+
type: String,
|
|
126
|
+
default: CONSTANTS.DEFAULT_URL
|
|
127
|
+
},
|
|
128
|
+
icon: {
|
|
129
|
+
type: String,
|
|
130
|
+
default: CONSTANTS.DEFAULT_ICON
|
|
131
|
+
},
|
|
132
|
+
size: {
|
|
133
|
+
type: Number,
|
|
134
|
+
default: CONSTANTS.DEFAULT_SIZE
|
|
135
|
+
},
|
|
136
|
+
message: {
|
|
137
|
+
type: String,
|
|
138
|
+
default: CONSTANTS.DEFAULT_MESSAGE
|
|
139
|
+
},
|
|
140
|
+
ext: {
|
|
141
|
+
type: String
|
|
142
|
+
},
|
|
143
|
+
extensions: {
|
|
144
|
+
type: String
|
|
145
|
+
},
|
|
146
|
+
accept: {
|
|
147
|
+
type: String
|
|
148
|
+
},
|
|
149
|
+
maximum: {
|
|
150
|
+
type: Number,
|
|
151
|
+
default: CONSTANTS.DEFAULT_MAXIMUM
|
|
152
|
+
},
|
|
153
|
+
multiple: {
|
|
154
|
+
type: Boolean,
|
|
155
|
+
default: false
|
|
156
|
+
},
|
|
157
|
+
drop: {
|
|
158
|
+
type: Boolean,
|
|
159
|
+
default: true
|
|
160
|
+
},
|
|
161
|
+
value: {
|
|
162
|
+
type: [String, Array]
|
|
163
|
+
},
|
|
164
|
+
querys: {
|
|
165
|
+
type: Object,
|
|
166
|
+
default: () => ({
|
|
167
|
+
_csrf: localStorage.getItem('token')
|
|
168
|
+
})
|
|
169
|
+
},
|
|
170
|
+
headers: {
|
|
171
|
+
type: Object,
|
|
172
|
+
default: () => ({
|
|
173
|
+
'X-XSRF-TOKEN': localStorage.getItem('token')
|
|
174
|
+
})
|
|
175
|
+
},
|
|
176
|
+
byteConversion: {
|
|
177
|
+
type: Number,
|
|
178
|
+
default: CONSTANTS.BYTE_CONVERSION
|
|
179
|
+
},
|
|
180
|
+
chunkEnabled: {
|
|
181
|
+
type: Boolean,
|
|
182
|
+
default: true
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
data() {
|
|
186
|
+
return {
|
|
187
|
+
// 文件状态管理
|
|
188
|
+
files: [], // vue-upload-component 管理的文件
|
|
189
|
+
buildedFiles: [], // 已构建完成的文件列表
|
|
190
|
+
|
|
191
|
+
// 上传状态管理
|
|
192
|
+
saveToServerAsyncPageTimer: null,
|
|
193
|
+
uploadRefId: null,
|
|
194
|
+
// 多选且外部无值时,预先生成 groupId,确保首次上传参数完整
|
|
195
|
+
groupId: (this.multiple && !this.value) ? uuidv4() : null,
|
|
196
|
+
//TODO
|
|
197
|
+
iconIsZhWrod: false
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
created() {
|
|
201
|
+
// 多文件模式下,如果没有外部 groupId,则生成一个
|
|
202
|
+
if (this.multiple && !this.value) {
|
|
203
|
+
this.groupId = uuidv4()
|
|
204
|
+
console.log('Created with new groupId:', this.groupId)
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
watch: {
|
|
208
|
+
value: {
|
|
209
|
+
async handler(value) {
|
|
210
|
+
if (type.isEmpty(value)) {
|
|
211
|
+
this.resetFiles()
|
|
212
|
+
} else if (this.multiple) {
|
|
213
|
+
this.handleMultipleFileValue(value)
|
|
214
|
+
} else {
|
|
215
|
+
this.handleSingleFileValue()
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
immediate: true
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
computed: {
|
|
222
|
+
// ==================== 基础配置 ====================
|
|
223
|
+
prefixPath() {
|
|
224
|
+
return window.prefixPath
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
uploadRef() {
|
|
228
|
+
if (!this.uploadRefId) {
|
|
229
|
+
this.uploadRefId = `uploadRef_${uuidv4()}`
|
|
230
|
+
}
|
|
231
|
+
return this.uploadRefId
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
iconIsZhWord() {
|
|
235
|
+
return type.isZhWord(this.icon)
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
// ==================== 上传配置 ====================
|
|
239
|
+
uploadParams() {
|
|
240
|
+
return this.multiple ? { groupID: this.groupId } : {}
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
fileSizeLimit() {
|
|
244
|
+
return this.size * this.byteConversion
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
postAction() {
|
|
248
|
+
const queryString = route.toQueryString(this.querys)
|
|
249
|
+
return `${this.prefixPath}${this.url}?${queryString}`
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
chunkConfig() {
|
|
253
|
+
return {
|
|
254
|
+
action: `${this.prefixPath}zuul/api-file/workbench/file/temp/chunk/vue`,
|
|
255
|
+
headers: { ...this.headers },
|
|
256
|
+
minSize: CONSTANTS.CHUNK_MIN_SIZE,
|
|
257
|
+
maxActive: CONSTANTS.CHUNK_MAX_ACTIVE,
|
|
258
|
+
maxRetries: CONSTANTS.CHUNK_MAX_RETRIES,
|
|
259
|
+
startBody: { override: true, path: '/cw' },
|
|
260
|
+
uploadBody: { override: true, path: '/cw' },
|
|
261
|
+
finishBody: { override: true, path: '/cw' }
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
getMaximum() {
|
|
266
|
+
return this.multiple ? this.maximum : 1
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
// ==================== 文件状态 ====================
|
|
270
|
+
uploadingFiles() {
|
|
271
|
+
// 筛选条件:有进度信息 且 (未成功 或 成功但还没有fileID的切片上传文件)
|
|
272
|
+
// 这样可以确保切片上传完成但异步保存未完成的文件继续显示,避免闪烁
|
|
273
|
+
return this.files.filter(file => {
|
|
274
|
+
if (file.progress === undefined) return false
|
|
275
|
+
if (!file.success) return true
|
|
276
|
+
|
|
277
|
+
// 检查文件是否已经有 fileID(可能在 file.fileID 或 file.response.data.fileID)
|
|
278
|
+
const hasFileID = file.fileID || (file.response && file.response.data && file.response.data.fileID)
|
|
279
|
+
|
|
280
|
+
// 切片上传成功但还没有完成异步保存(没有fileID)的文件继续显示
|
|
281
|
+
// 普通上传成功且已有 fileID 的文件不显示(会在 completedFiles 中显示)
|
|
282
|
+
return file.success && !hasFileID
|
|
283
|
+
})
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
completedFiles() {
|
|
287
|
+
return this.buildedFiles.filter(file => file.fileID)
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
totalFiles() {
|
|
291
|
+
return this.uploadingFiles.length + this.completedFiles.length
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
isFileUploadSuccessed() {
|
|
295
|
+
const currentUploadingFiles = this.files.filter(file => file.response !== undefined)
|
|
296
|
+
if (currentUploadingFiles.length === 0) {
|
|
297
|
+
return this.buildedFiles.length > 0
|
|
298
|
+
}
|
|
299
|
+
return currentUploadingFiles.every(file => file.success)
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
isShowUploadContainer() {
|
|
303
|
+
const maxFiles = this.multiple ? this.maximum : 1
|
|
304
|
+
return this.totalFiles < maxFiles
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
// ==================== 文件信息 ====================
|
|
308
|
+
fileSuffixIcon() {
|
|
309
|
+
return FILE_SUFFIX_ICONS
|
|
310
|
+
},
|
|
311
|
+
|
|
312
|
+
fileIds() {
|
|
313
|
+
if (this.multiple) {
|
|
314
|
+
return this.groupId
|
|
315
|
+
} else {
|
|
316
|
+
const fileIds = this.buildedFiles.map(file => file.fileID)
|
|
317
|
+
return fileIds[0]
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
fileResponseData() {
|
|
322
|
+
return this.multiple ? this.buildedFiles : this.buildedFiles[0]
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
methods: {
|
|
326
|
+
// ==================== 文件管理 ====================
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 从多个数组中移除文件
|
|
330
|
+
*/
|
|
331
|
+
removeFromArrays(file, arrays, key = 'fileID') {
|
|
332
|
+
return arrays.map(arr =>
|
|
333
|
+
arr.filter(item => {
|
|
334
|
+
// 如果 fileID 都存在且相等,则移除
|
|
335
|
+
if (item[key] && file[key] && item[key] === file[key]) {
|
|
336
|
+
return false
|
|
337
|
+
}
|
|
338
|
+
// 如果 id 都存在且相等,则移除
|
|
339
|
+
if (item.id && file.id && item.id === file.id) {
|
|
340
|
+
return false
|
|
341
|
+
}
|
|
342
|
+
// 如果文件名相同,也考虑移除(额外的安全检查)
|
|
343
|
+
if (item.name && file.name && item.name === file.name && item[key] === file[key]) {
|
|
344
|
+
return false
|
|
345
|
+
}
|
|
346
|
+
// 否则保留
|
|
347
|
+
return true
|
|
348
|
+
})
|
|
349
|
+
)
|
|
350
|
+
},
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* 检查文件是否为新文件
|
|
354
|
+
*/
|
|
355
|
+
isNewFile(newFile, existingFiles, key = 'fileID') {
|
|
356
|
+
return newFile[key] && !existingFiles.some(existing => existing[key] === newFile[key])
|
|
357
|
+
},
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* 合并文件数据
|
|
361
|
+
*/
|
|
362
|
+
mergeFileData(uploadFile) {
|
|
363
|
+
return {
|
|
364
|
+
...uploadFile.response.data,
|
|
365
|
+
...uploadFile
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* 初始化文件列表
|
|
371
|
+
*/
|
|
372
|
+
async initializeFiles() {
|
|
373
|
+
if (!this.value) return
|
|
374
|
+
|
|
375
|
+
if (this.multiple) {
|
|
376
|
+
await this.fetchFilesWithGroupId()
|
|
377
|
+
} else {
|
|
378
|
+
await this.fetchFileWithFileId()
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* 获取多文件组
|
|
384
|
+
*/
|
|
385
|
+
async fetchFilesWithGroupId() {
|
|
386
|
+
try {
|
|
387
|
+
const response = await net.get(`/api-file/workbench/file/group/${this.value}`)
|
|
388
|
+
const data = response.data || []
|
|
389
|
+
|
|
390
|
+
// 只有在没有现有文件时才设置初始文件列表
|
|
391
|
+
if (this.buildedFiles.length === 0) {
|
|
392
|
+
this.buildedFiles = data
|
|
393
|
+
console.log('Initial files loaded:', this.buildedFiles.length)
|
|
394
|
+
} else {
|
|
395
|
+
console.log('Keep existing files, skip initial load')
|
|
396
|
+
}
|
|
397
|
+
} catch (error) {
|
|
398
|
+
console.log('fetchFilesWithGroupId error:', error)
|
|
399
|
+
console.log('Keep current files, do not clear due to API error')
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* 获取单文件
|
|
405
|
+
*/
|
|
406
|
+
async fetchFileWithFileId() {
|
|
407
|
+
try {
|
|
408
|
+
const response = await net.get(`/api-file/file/${this.value}`)
|
|
409
|
+
const data = response.data
|
|
410
|
+
this.buildedFiles = [data]
|
|
411
|
+
this.files = [data]
|
|
412
|
+
} catch (error) {
|
|
413
|
+
console.log('fetchFileWithFileId error:', error)
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* 调用服务器删除文件 API
|
|
419
|
+
*/
|
|
420
|
+
async deleteFiles (ids) {
|
|
421
|
+
if (!ids) {
|
|
422
|
+
console.warn('No fileID provided for deletion')
|
|
423
|
+
return
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (type.isArray(ids)) {
|
|
427
|
+
ids = ids.join(',')
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
try {
|
|
431
|
+
await net.remove(`/api-file/workbench/file?ids=${ids}`)
|
|
432
|
+
console.log('File deleted from server:', ids)
|
|
433
|
+
} catch (error) {
|
|
434
|
+
console.error('Failed to delete file from server:', error)
|
|
435
|
+
throw error // 重新抛出错误,让调用方处理
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* 处理文件删除
|
|
441
|
+
*/
|
|
442
|
+
async handleClickDelete(file) {
|
|
443
|
+
const { fileID, name } = file
|
|
444
|
+
console.log('Deleting file:', { name, fileID })
|
|
445
|
+
|
|
446
|
+
// 先从上传组件中移除文件
|
|
447
|
+
if (this.$refs[this.uploadRef]) {
|
|
448
|
+
this.$refs[this.uploadRef].remove(file)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// 从所有数组中移除文件
|
|
452
|
+
[this.files, this.buildedFiles] = this.removeFromArrays(file, [this.files, this.buildedFiles])
|
|
453
|
+
|
|
454
|
+
console.log('After deletion - files:', this.files.length, 'buildedFiles:', this.buildedFiles.length)
|
|
455
|
+
|
|
456
|
+
// 如果有 fileID,调用服务器删除 API
|
|
457
|
+
if (fileID) {
|
|
458
|
+
try {
|
|
459
|
+
await this.deleteFiles(fileID)
|
|
460
|
+
} catch (error) {
|
|
461
|
+
console.error('Failed to delete file from server:', error)
|
|
462
|
+
// 可以选择提示用户或回滚操作
|
|
463
|
+
// 这里仅记录错误,不影响前端显示
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// 多文件模式下,如果删除最后一个文件,重置 groupId
|
|
468
|
+
if (this.multiple && this.buildedFiles.length === 0) {
|
|
469
|
+
this.groupId = null
|
|
470
|
+
console.log('Reset groupId after deleting last file')
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// 触发 change 事件
|
|
474
|
+
this.$emit('change', this.fileIds)
|
|
475
|
+
},
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* 处理文件下载
|
|
479
|
+
*/
|
|
480
|
+
handleClickDownload(file) {
|
|
481
|
+
const { fileID: fileId } = file
|
|
482
|
+
window.open(`/api-file/workbench/file/stream/${fileId}?origin=true`)
|
|
483
|
+
},
|
|
484
|
+
// ==================== 上传处理 ====================
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* 处理文件上传状态变化
|
|
488
|
+
*/
|
|
489
|
+
onWatchFiles(files) {
|
|
490
|
+
console.log('onWatchFiles called with files:', files.length)
|
|
491
|
+
console.log('Current buildedFiles:', this.buildedFiles.length)
|
|
492
|
+
|
|
493
|
+
// 更新文件状态
|
|
494
|
+
this.files = files
|
|
495
|
+
|
|
496
|
+
// 处理已上传成功的文件
|
|
497
|
+
this.processUploadedFiles(files)
|
|
498
|
+
|
|
499
|
+
// 检查上传是否完成
|
|
500
|
+
if (this.isFileUploadSuccessed) {
|
|
501
|
+
this.$emit('change', this.fileIds)
|
|
502
|
+
this.$emit('on-success', this.fileResponseData)
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* 处理已上传成功的文件
|
|
508
|
+
*/
|
|
509
|
+
processUploadedFiles(files) {
|
|
510
|
+
// 处理所有有响应的文件(包括正在上传和已完成的)
|
|
511
|
+
const uploadedFiles = files.filter(file => file.response)
|
|
512
|
+
const newBuildedFiles = uploadedFiles.map(file => this.mergeFileData(file))
|
|
513
|
+
|
|
514
|
+
if (this.multiple) {
|
|
515
|
+
this.processMultipleFiles(newBuildedFiles)
|
|
516
|
+
} else {
|
|
517
|
+
// 单文件模式:只保留最新的文件
|
|
518
|
+
this.buildedFiles = newBuildedFiles
|
|
519
|
+
|
|
520
|
+
// 从 files 数组中移除已完成的文件(普通上传),避免重复显示
|
|
521
|
+
if (newBuildedFiles.length > 0 && newBuildedFiles[0].fileID) {
|
|
522
|
+
this.$nextTick(() => {
|
|
523
|
+
this.files = this.files.filter(file => {
|
|
524
|
+
const fileID = file.fileID || (file.response && file.response.data && file.response.data.fileID)
|
|
525
|
+
return fileID !== newBuildedFiles[0].fileID
|
|
526
|
+
})
|
|
527
|
+
console.log('Removed completed file from upload list (single mode)')
|
|
528
|
+
})
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
this.logFileStatus()
|
|
533
|
+
},
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* 处理多文件模式
|
|
537
|
+
*/
|
|
538
|
+
processMultipleFiles(newBuildedFiles) {
|
|
539
|
+
// 获取已存在的文件ID集合
|
|
540
|
+
const existingFileIds = new Set(this.buildedFiles.map(f => f.fileID).filter(id => id))
|
|
541
|
+
|
|
542
|
+
// 过滤出真正的新文件
|
|
543
|
+
const trulyNewFiles = newBuildedFiles.filter(newFile =>
|
|
544
|
+
this.isNewFile(newFile, this.buildedFiles)
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
console.log('Existing fileIDs:', Array.from(existingFileIds))
|
|
548
|
+
console.log('New uploaded files:', newBuildedFiles.map(f => ({ name: f.name, fileID: f.fileID })))
|
|
549
|
+
console.log('Truly new files:', trulyNewFiles.map(f => ({ name: f.name, fileID: f.fileID })))
|
|
550
|
+
|
|
551
|
+
// 将新文件追加到现有文件列表
|
|
552
|
+
if (trulyNewFiles.length > 0) {
|
|
553
|
+
this.buildedFiles = [...this.buildedFiles, ...trulyNewFiles]
|
|
554
|
+
console.log('Added new files, total buildedFiles:', this.buildedFiles.length)
|
|
555
|
+
|
|
556
|
+
// 从 files 数组中移除已完成的文件(普通上传),避免重复显示
|
|
557
|
+
this.$nextTick(() => {
|
|
558
|
+
const completedFileIDs = new Set(trulyNewFiles.map(f => f.fileID))
|
|
559
|
+
this.files = this.files.filter(file => {
|
|
560
|
+
const fileID = file.fileID || (file.response && file.response.data && file.response.data.fileID)
|
|
561
|
+
return !completedFileIDs.has(fileID)
|
|
562
|
+
})
|
|
563
|
+
console.log('Removed completed files from upload list')
|
|
564
|
+
})
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// 更新现有文件的状态(包括新添加的文件)
|
|
568
|
+
this.updateExistingFiles(newBuildedFiles)
|
|
569
|
+
},
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* 更新现有文件状态
|
|
573
|
+
*/
|
|
574
|
+
updateExistingFiles(newBuildedFiles) {
|
|
575
|
+
this.buildedFiles = this.buildedFiles.map(existingFile => {
|
|
576
|
+
const updatedFile = newBuildedFiles.find(newFile => newFile.fileID === existingFile.fileID)
|
|
577
|
+
return updatedFile ? { ...existingFile, ...updatedFile } : existingFile
|
|
578
|
+
})
|
|
579
|
+
},
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* 记录文件状态日志
|
|
583
|
+
*/
|
|
584
|
+
logFileStatus() {
|
|
585
|
+
console.log('Final buildedFiles:', this.buildedFiles.length)
|
|
586
|
+
console.log('buildedFiles details:', this.buildedFiles.map(f => ({ name: f.name, fileID: f.fileID, success: f.success })))
|
|
587
|
+
console.log('Uploading files:', this.uploadingFiles.length)
|
|
588
|
+
console.log('Completed files:', this.completedFiles.length)
|
|
589
|
+
},
|
|
590
|
+
// ==================== 异步处理 ====================
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* 异步保存文件到服务器
|
|
594
|
+
* @param {FormData} payloads - 上传参数
|
|
595
|
+
* @param {Object} uploadingFile - 正在上传的文件对象(可选)
|
|
596
|
+
*/
|
|
597
|
+
async saveToServerAsyncPage(payloads = {}, uploadingFile = null) {
|
|
598
|
+
try {
|
|
599
|
+
const response = await net.post('zuul/api-file/workbench/file/temp/saveToServerAsyncPage', payloads, {
|
|
600
|
+
headers: {
|
|
601
|
+
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
|
602
|
+
}
|
|
603
|
+
})
|
|
604
|
+
|
|
605
|
+
const { data } = response
|
|
606
|
+
if (data !== 'saveToServerAsyncPage') {
|
|
607
|
+
clearInterval(this.saveToServerAsyncPageTimer)
|
|
608
|
+
console.log('Chunk upload async save completed, file data:', data)
|
|
609
|
+
|
|
610
|
+
const { fileID, groupID, name } = data
|
|
611
|
+
|
|
612
|
+
// 根据上传模式处理文件信息
|
|
613
|
+
if (this.multiple) {
|
|
614
|
+
// 多文件模式:更新 groupID 并追加文件到列表
|
|
615
|
+
if (groupID) {
|
|
616
|
+
this.groupId = groupID
|
|
617
|
+
console.log('Updated groupId from server:', groupID)
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// 检查文件是否已存在,避免重复添加
|
|
621
|
+
const fileExists = this.buildedFiles.some(file => file.fileID === fileID)
|
|
622
|
+
if (!fileExists && fileID) {
|
|
623
|
+
// 将服务器返回的完整文件信息追加到文件列表
|
|
624
|
+
// 添加必要的显示属性
|
|
625
|
+
const fileData = {
|
|
626
|
+
...data,
|
|
627
|
+
success: true // 标记为上传成功
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// 先添加到已完成列表
|
|
631
|
+
this.buildedFiles.push(fileData)
|
|
632
|
+
console.log('File added to list:', name, 'Total files:', this.buildedFiles.length)
|
|
633
|
+
|
|
634
|
+
// 使用 nextTick 确保视图更新后再移除上传列表中的文件,避免闪烁
|
|
635
|
+
this.$nextTick(() => {
|
|
636
|
+
// 从上传列表中精确移除对应的文件
|
|
637
|
+
if (uploadingFile) {
|
|
638
|
+
// 如果有文件对象引用,直接移除该文件
|
|
639
|
+
this.files = this.files.filter(file => file.id !== uploadingFile.id)
|
|
640
|
+
console.log('Removed uploading file by id:', uploadingFile.id)
|
|
641
|
+
} else {
|
|
642
|
+
// 否则根据文件名移除
|
|
643
|
+
this.files = this.files.filter(file => file.name !== name)
|
|
644
|
+
console.log('Removed uploading file by name:', name)
|
|
645
|
+
}
|
|
646
|
+
})
|
|
647
|
+
|
|
648
|
+
// 触发 change 事件通知父组件
|
|
649
|
+
this.$emit('change', this.fileIds)
|
|
650
|
+
this.$emit('on-success', this.fileResponseData)
|
|
651
|
+
} else {
|
|
652
|
+
console.log('File already exists or invalid fileID, skip adding')
|
|
653
|
+
}
|
|
654
|
+
} else {
|
|
655
|
+
// 单文件模式:替换文件列表
|
|
656
|
+
if (fileID) {
|
|
657
|
+
const fileData = {
|
|
658
|
+
...data,
|
|
659
|
+
success: true // 标记为上传成功
|
|
660
|
+
}
|
|
661
|
+
this.buildedFiles = [fileData]
|
|
662
|
+
this.files = [] // 清空上传列表
|
|
663
|
+
console.log('Single file updated:', name)
|
|
664
|
+
|
|
665
|
+
// 触发 change 事件通知父组件更新 value
|
|
666
|
+
this.$emit('change', fileID)
|
|
667
|
+
this.$emit('on-success', data)
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
} catch (error) {
|
|
672
|
+
console.error('saveToServerAsyncPage error:', error)
|
|
673
|
+
clearInterval(this.saveToServerAsyncPageTimer)
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
|
|
677
|
+
// ==================== 文件验证 ====================
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* 验证文件类型
|
|
681
|
+
*/
|
|
682
|
+
validateFileType(file) {
|
|
683
|
+
if (!file || !file.name) {
|
|
684
|
+
console.log('文件或文件名不存在')
|
|
685
|
+
return false
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
const fileExt = this.getFileExtension(file.name)
|
|
689
|
+
console.log('文件扩展名:', fileExt)
|
|
690
|
+
|
|
691
|
+
if (this.extensions) {
|
|
692
|
+
const allowedExts = this.getAllowedExtensions()
|
|
693
|
+
console.log('允许的扩展名:', allowedExts)
|
|
694
|
+
|
|
695
|
+
if (!allowedExts.includes(fileExt)) {
|
|
696
|
+
console.log('扩展名不在允许列表中')
|
|
697
|
+
this.$message.error(`不支持的文件类型 "${fileExt}",请上传 ${this.extensions} 格式的文件`)
|
|
698
|
+
return false
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
console.log('文件类型验证通过')
|
|
703
|
+
return true
|
|
704
|
+
},
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* 获取文件扩展名
|
|
708
|
+
*/
|
|
709
|
+
getFileExtension(fileName) {
|
|
710
|
+
return fileName.toLowerCase().substring(fileName.lastIndexOf('.'))
|
|
711
|
+
},
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* 获取允许的扩展名列表
|
|
715
|
+
*/
|
|
716
|
+
getAllowedExtensions() {
|
|
717
|
+
return this.extensions.toLowerCase()
|
|
718
|
+
.split(',')
|
|
719
|
+
.map(ext => ext.trim().startsWith('.') ? ext.trim() : `.${ext.trim()}`)
|
|
720
|
+
},
|
|
721
|
+
// ==================== 事件处理 ====================
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* 处理文件输入事件
|
|
725
|
+
*/
|
|
726
|
+
onWatchInputFiles(newFile, oldFile) {
|
|
727
|
+
if (newFile && !oldFile) {
|
|
728
|
+
this.handleFileAdd(newFile)
|
|
729
|
+
} else if (newFile && oldFile) {
|
|
730
|
+
this.handleFileUpdate(newFile)
|
|
731
|
+
} else if (!newFile && oldFile) {
|
|
732
|
+
this.handleFileDelete()
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// 激活上传组件
|
|
736
|
+
this.activateUploadComponent(newFile, oldFile)
|
|
737
|
+
},
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* 生成唯一的随机数
|
|
741
|
+
*/
|
|
742
|
+
generateUniqueRandom() {
|
|
743
|
+
// 使用 crypto.getRandomValues 生成更安全的随机数
|
|
744
|
+
if (window.crypto && window.crypto.getRandomValues) {
|
|
745
|
+
const array = new Uint32Array(1)
|
|
746
|
+
window.crypto.getRandomValues(array)
|
|
747
|
+
return array[0].toString()
|
|
748
|
+
}
|
|
749
|
+
// 降级方案:使用 Math.random 结合时间戳
|
|
750
|
+
return Math.random().toString(36).substr(2, 9) + Date.now().toString(36)
|
|
751
|
+
},
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* 处理文件添加
|
|
755
|
+
*/
|
|
756
|
+
handleFileAdd(newFile) {
|
|
757
|
+
// 为每个文件生成唯一的随机数
|
|
758
|
+
const uniqueRandom = this.generateUniqueRandom()
|
|
759
|
+
newFile.postAction = newFile.postAction + '&_t=' + uniqueRandom
|
|
760
|
+
console.log('add file:', newFile)
|
|
761
|
+
console.log('extensions:', this.extensions)
|
|
762
|
+
console.log('accept:', this.accept)
|
|
763
|
+
|
|
764
|
+
// 生成或使用 groupId
|
|
765
|
+
this.ensureGroupId()
|
|
766
|
+
|
|
767
|
+
// 验证文件类型
|
|
768
|
+
if (!this.validateFileType(newFile)) {
|
|
769
|
+
this.removeInvalidFile(newFile)
|
|
770
|
+
return
|
|
771
|
+
}
|
|
772
|
+
console.log('文件类型验证通过,继续上传')
|
|
773
|
+
},
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* 处理文件更新
|
|
777
|
+
*/
|
|
778
|
+
handleFileUpdate(newFile) {
|
|
779
|
+
console.log('update', newFile)
|
|
780
|
+
const { success, active, chunk, response } = newFile
|
|
781
|
+
|
|
782
|
+
if (chunk && success && !active) {
|
|
783
|
+
console.log('chunk end')
|
|
784
|
+
this.handleChunkComplete(response, newFile)
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* 处理文件删除
|
|
790
|
+
*/
|
|
791
|
+
handleFileDelete() {
|
|
792
|
+
console.log('delete')
|
|
793
|
+
},
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* 确保 groupId 存在
|
|
797
|
+
*/
|
|
798
|
+
ensureGroupId() {
|
|
799
|
+
console.log('onWatchInputFiles - multiple:', this.multiple, 'current groupId:', this.groupId)
|
|
800
|
+
|
|
801
|
+
if (this.multiple && !this.groupId) {
|
|
802
|
+
this.groupId = uuidv4()
|
|
803
|
+
console.log('Generated new groupId:', this.groupId)
|
|
804
|
+
} else if (this.multiple && this.groupId) {
|
|
805
|
+
console.log('Using existing groupId:', this.groupId)
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* 移除无效文件
|
|
811
|
+
*/
|
|
812
|
+
removeInvalidFile(file) {
|
|
813
|
+
console.log('文件类型验证失败,尝试移除文件')
|
|
814
|
+
console.log('uploadRef:', this.uploadRef)
|
|
815
|
+
console.log('$refs:', this.$refs)
|
|
816
|
+
|
|
817
|
+
if (this.$refs[this.uploadRef]) {
|
|
818
|
+
this.$refs[this.uploadRef].remove(file)
|
|
819
|
+
} else {
|
|
820
|
+
console.error('无法找到 uploadRef 引用')
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* 处理分片上传完成
|
|
826
|
+
* @param {Object} response - 上传响应
|
|
827
|
+
* @param {Object} uploadingFile - 正在上传的文件对象(可选)
|
|
828
|
+
*/
|
|
829
|
+
handleChunkComplete(response, uploadingFile = null) {
|
|
830
|
+
const { data: { file, type } } = response
|
|
831
|
+
const payloads = {
|
|
832
|
+
filePath: file.match(/\/cw(.*)/) ? file.match(/\/cw(.*)/)[0] : void 0,
|
|
833
|
+
asyncID: uuidv4(),
|
|
834
|
+
groupID: this.groupId,
|
|
835
|
+
isDeleteOrigin: false,
|
|
836
|
+
toImage: type === 'pdf',
|
|
837
|
+
unzip: type === 'zip',
|
|
838
|
+
_csrf: localStorage.getItem('token')
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
const formData = new FormData()
|
|
842
|
+
|
|
843
|
+
Object.keys(payloads).forEach(key => {
|
|
844
|
+
formData.append(key, payloads[key])
|
|
845
|
+
})
|
|
846
|
+
|
|
847
|
+
// 将上传文件对象传递给异步保存方法
|
|
848
|
+
this.saveToServerAsyncPageTimer = setInterval(() => {
|
|
849
|
+
this.saveToServerAsyncPage(formData, uploadingFile)
|
|
850
|
+
}, CONSTANTS.SAVE_INTERVAL)
|
|
851
|
+
},
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* 激活上传组件
|
|
855
|
+
*/
|
|
856
|
+
activateUploadComponent(newFile, oldFile) {
|
|
857
|
+
if (Boolean(newFile) !== Boolean(oldFile) || oldFile.error !== newFile.error) {
|
|
858
|
+
if (!this.$refs[this.uploadRef].active) {
|
|
859
|
+
this.$refs[this.uploadRef].active = true
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
},
|
|
863
|
+
|
|
864
|
+
// ==================== 值变化处理 ====================
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* 重置文件状态
|
|
868
|
+
*/
|
|
869
|
+
resetFiles() {
|
|
870
|
+
this.files = []
|
|
871
|
+
this.buildedFiles = []
|
|
872
|
+
// 多选模式下保留或生成 groupId,避免首次上传为空
|
|
873
|
+
if (this.multiple) {
|
|
874
|
+
if (!this.groupId) {
|
|
875
|
+
this.groupId = uuidv4()
|
|
876
|
+
console.log('Generated groupId in resetFiles:', this.groupId)
|
|
877
|
+
} else {
|
|
878
|
+
console.log('Preserve existing groupId in resetFiles:', this.groupId)
|
|
879
|
+
}
|
|
880
|
+
} else {
|
|
881
|
+
this.groupId = null
|
|
882
|
+
console.log('Reset groupId to null (single mode)')
|
|
883
|
+
}
|
|
884
|
+
},
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* 处理多文件模式的值变化
|
|
888
|
+
*/
|
|
889
|
+
async handleMultipleFileValue(value) {
|
|
890
|
+
// multiple - value 就是 groupId
|
|
891
|
+
// 只有当 groupId 发生变化时才重新获取文件列表(初始化回显)
|
|
892
|
+
if (this.groupId !== value) {
|
|
893
|
+
this.groupId = value
|
|
894
|
+
console.log('Set groupId from external value:', this.groupId)
|
|
895
|
+
await this.fetchFilesWithGroupId()
|
|
896
|
+
} else {
|
|
897
|
+
console.log('GroupId unchanged, skip fetchFilesWithGroupId')
|
|
898
|
+
}
|
|
899
|
+
},
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* 处理单文件模式的值变化
|
|
903
|
+
*/
|
|
904
|
+
async handleSingleFileValue() {
|
|
905
|
+
await this.fetchFileWithFileId()
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
</script>
|
|
910
|
+
|
|
911
|
+
<style lang="scss" scoped>
|
|
912
|
+
::v-deep .ele-upload__inner {
|
|
913
|
+
opacity: 1 !important;
|
|
914
|
+
cursor: pointer;
|
|
915
|
+
border: 1px dashed var(--idooel-form-title-border-color);
|
|
916
|
+
background: var(--idooel-form-upload-bg-color) !important;
|
|
917
|
+
&:hover {
|
|
918
|
+
border-color: var(--idooel-form-upload-border-hover-color);
|
|
919
|
+
}
|
|
920
|
+
border-radius: var(--idooel-form-border-radius);
|
|
921
|
+
}
|
|
922
|
+
.ele-upload__wrapper {
|
|
923
|
+
width: 100%;
|
|
924
|
+
.ele-upload__area {
|
|
925
|
+
padding: 16px;
|
|
926
|
+
width: 100%;
|
|
927
|
+
height: 80px;
|
|
928
|
+
display: flex;
|
|
929
|
+
flex-direction: row;
|
|
930
|
+
.ele-upload__area--icon {
|
|
931
|
+
color: var(--idooel-primary-color);
|
|
932
|
+
display: flex;
|
|
933
|
+
flex-direction: row;
|
|
934
|
+
align-items: center;
|
|
935
|
+
font-size: 16x;
|
|
936
|
+
.anticon-cloud-upload {
|
|
937
|
+
font-size: 48px;
|
|
938
|
+
color: var(--idooel-primary-color);
|
|
939
|
+
}
|
|
940
|
+
.anticon {
|
|
941
|
+
font-size: 48px;
|
|
942
|
+
color: var(--idooel-primary-color);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
.ele-upload__area--text {
|
|
946
|
+
margin-left: 16px;
|
|
947
|
+
.ele-upload__message {
|
|
948
|
+
font-size: 16px;
|
|
949
|
+
color: var(--idoole-black-088);
|
|
950
|
+
text-align: left;
|
|
951
|
+
}
|
|
952
|
+
.ele-upload__ext {
|
|
953
|
+
text-align: left;
|
|
954
|
+
font-size: 14px;
|
|
955
|
+
color: var(--idoole-black-06);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
.ele-files__wrapper {
|
|
960
|
+
.ele-file__item {
|
|
961
|
+
width: 100%;
|
|
962
|
+
margin-top: 8px;
|
|
963
|
+
padding: 8px 12px;
|
|
964
|
+
border-radius: var(--idooel-form-border-radius);
|
|
965
|
+
background: var(--idooel-form-upload-bg-color);
|
|
966
|
+
display: flex;
|
|
967
|
+
flex-direction: row;
|
|
968
|
+
align-items: center;
|
|
969
|
+
.ele-file__suffix--icon {
|
|
970
|
+
display: flex;
|
|
971
|
+
align-items: center;
|
|
972
|
+
justify-content: center;
|
|
973
|
+
width: 24px;
|
|
974
|
+
height: 24px;
|
|
975
|
+
}
|
|
976
|
+
.ele-file__name {
|
|
977
|
+
flex: 1;
|
|
978
|
+
text-align: left;
|
|
979
|
+
white-space: nowrap;
|
|
980
|
+
overflow: hidden;
|
|
981
|
+
font-size: 14px;
|
|
982
|
+
margin-left: 8px;
|
|
983
|
+
cursor: pointer;
|
|
984
|
+
.ele-file__inner {
|
|
985
|
+
overflow: hidden;
|
|
986
|
+
text-overflow: ellipsis;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
.ele-file__delete {
|
|
990
|
+
margin-left: 8px;
|
|
991
|
+
.ele-file__delete--icon {
|
|
992
|
+
margin-left: 8px;
|
|
993
|
+
cursor: pointer;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
997
999
|
</style>
|