@idooel/components 0.0.2-beta.3 → 0.0.2-beta.31

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.
Files changed (113) hide show
  1. package/README.md +98 -98
  2. package/dist/@idooel/components.esm.js +3599 -1574
  3. package/dist/@idooel/components.umd.js +3653 -1629
  4. package/jsconfig.json +7 -7
  5. package/package.json +64 -50
  6. package/packages/alert/index.js +4 -4
  7. package/packages/alert/src/index.vue +45 -45
  8. package/packages/batch-export/index.js +4 -4
  9. package/packages/batch-export/src/index.vue +104 -104
  10. package/packages/business-components/modal-fsm/index.js +4 -4
  11. package/packages/business-components/modal-fsm/src/index.vue +163 -163
  12. package/packages/business-components/modal-import/index.js +4 -4
  13. package/packages/business-components/modal-import/src/index.vue +222 -139
  14. package/packages/business-components/modal-timeline/index.js +4 -4
  15. package/packages/business-components/modal-timeline/src/index.vue +77 -77
  16. package/packages/business-components/tabs-sub-center/index.js +4 -4
  17. package/packages/business-components/tabs-sub-center/src/index.vue +116 -116
  18. package/packages/button/index.js +4 -4
  19. package/packages/button/src/index.vue +65 -65
  20. package/packages/checkbox/index.js +4 -4
  21. package/packages/checkbox/src/index.vue +52 -52
  22. package/packages/composite-components/button-group/index.js +4 -4
  23. package/packages/composite-components/button-group/src/index.vue +151 -151
  24. package/packages/composite-components/form-attachment/src/index.vue +14 -14
  25. package/packages/composite-components/form-img-crop/index.js +4 -4
  26. package/packages/composite-components/form-img-crop/src/index.vue +131 -131
  27. package/packages/composite-components/modal-confirm/index.js +4 -4
  28. package/packages/composite-components/modal-confirm/src/index.vue +103 -103
  29. package/packages/composite-components/modal-form/index.js +4 -4
  30. package/packages/composite-components/modal-form/src/index.vue +230 -230
  31. package/packages/composite-components/modal-img-crop/index.js +4 -4
  32. package/packages/composite-components/modal-img-crop/src/index.vue +298 -298
  33. package/packages/composite-components/modal-table/index.js +4 -4
  34. package/packages/composite-components/modal-table/src/index.vue +155 -155
  35. package/packages/composite-components/modal-tree/index.js +4 -4
  36. package/packages/composite-components/modal-tree/src/index.vue +75 -75
  37. package/packages/composite-components/search-area/index.js +4 -4
  38. package/packages/composite-components/search-area/src/index.vue +239 -237
  39. package/packages/composite-components/search-area/src/label.vue +35 -35
  40. package/packages/composite-components/select-entity-modal-table/index.js +4 -4
  41. package/packages/composite-components/select-entity-modal-table/src/index.vue +171 -171
  42. package/packages/date/index.js +4 -4
  43. package/packages/date/src/index.vue +112 -112
  44. package/packages/date-range/index.js +4 -4
  45. package/packages/date-range/src/index.vue +47 -47
  46. package/packages/form/index.js +4 -4
  47. package/packages/form/src/index.vue +393 -319
  48. package/packages/icon/index.js +4 -4
  49. package/packages/icon/src/index.vue +31 -31
  50. package/packages/index.js +159 -153
  51. package/packages/input/index.js +4 -4
  52. package/packages/input/src/index.vue +35 -35
  53. package/packages/input-number/index.js +4 -4
  54. package/packages/input-number/src/index.vue +23 -23
  55. package/packages/loading/index.js +4 -4
  56. package/packages/loading/src/index.vue +36 -36
  57. package/packages/meta/provider.js +4 -0
  58. package/packages/modal/index.js +4 -4
  59. package/packages/modal/src/index.vue +184 -184
  60. package/packages/models/form-group-model/index.js +4 -4
  61. package/packages/models/form-group-model/src/index.vue +271 -273
  62. package/packages/models/form-model/index.js +4 -4
  63. package/packages/models/form-model/src/index.vue +236 -232
  64. package/packages/models/step-model/index.js +4 -4
  65. package/packages/models/step-model/src/index.vue +224 -224
  66. package/packages/models/tree-table-model/README.md +0 -0
  67. package/packages/models/tree-table-model/index.js +4 -4
  68. package/packages/models/tree-table-model/src/index.vue +963 -689
  69. package/packages/pagination/index.js +5 -0
  70. package/packages/pagination/src/index.vue +372 -0
  71. package/packages/radio/index.js +4 -4
  72. package/packages/radio/src/index.vue +56 -56
  73. package/packages/select/index.js +4 -4
  74. package/packages/select/src/index.vue +113 -105
  75. package/packages/select-entity/index.js +4 -4
  76. package/packages/select-entity/src/index.vue +119 -119
  77. package/packages/table/index.js +4 -4
  78. package/packages/table/src/action.vue +176 -172
  79. package/packages/table/src/index.vue +605 -319
  80. package/packages/tabs/index.js +4 -4
  81. package/packages/tabs/src/index.vue +55 -55
  82. package/packages/text/index.js +4 -4
  83. package/packages/text/src/index.vue +47 -47
  84. package/packages/text-editor/index.js +4 -4
  85. package/packages/text-editor/src/index.vue +72 -72
  86. package/packages/textarea/index.js +4 -4
  87. package/packages/textarea/src/index.vue +57 -57
  88. package/packages/theme/form.scss +21 -21
  89. package/packages/theme/index.scss +43 -43
  90. package/packages/theme/overrid.scss +7 -7
  91. package/packages/theme/styleClass.scss +2 -2
  92. package/packages/theme/variables.scss +55 -55
  93. package/packages/timeline/index.js +4 -4
  94. package/packages/timeline/src/index.vue +257 -257
  95. package/packages/tpl/index.js +4 -4
  96. package/packages/tpl/src/index.vue +55 -55
  97. package/packages/tree/index.js +4 -4
  98. package/packages/tree/src/TreeNode.vue +29 -29
  99. package/packages/tree/src/index.vue +101 -101
  100. package/packages/tree-select/index.js +4 -4
  101. package/packages/tree-select/src/index.vue +142 -142
  102. package/packages/upload/index.js +4 -4
  103. package/packages/upload/src/index.vue +998 -494
  104. package/packages/utils/README.md +172 -0
  105. package/packages/utils/index.js +66 -62
  106. package/packages/utils/runtime-context/dataPoolAPI.js +501 -0
  107. package/packages/utils/runtime-context/globalDataPool.js +279 -0
  108. package/packages/utils/runtime-context/index.js +76 -0
  109. package/packages/utils/runtime-context/modelSchema.js +174 -0
  110. package/scripts/rollup.config.js +42 -42
  111. package/scripts/rollup.esm.config.js +11 -11
  112. package/scripts/rollup.umd.config.js +17 -14
  113. package/vitest.config.js +17 -0
@@ -1,495 +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
- @input-file="onWatchInputFiles"
18
- @input="onWatchFiles"
19
- style="width: 100%;">
20
- <section class="ele-upload__area">
21
- <div class="ele-upload__area--icon">
22
- <template v-if="iconIsZhWrod">
23
- {{ icon }}
24
- </template>
25
- <template v-else>
26
- <ele-icon :type="icon"></ele-icon>
27
- </template>
28
- </div>
29
- <div class="ele-upload__area--text">
30
- <div class="ele-upload__message" v-if="message" v-html="message"></div>
31
- <div class="ele-upload__message" v-else>单击或拖动文件到该区域以上传</div>
32
- <div class="ele-upload__ext" v-if="ext" v-html="ext"></div>
33
- <div class="ele-upload__ext" v-else>文件小于{{ size }}M</div>
34
- </div>
35
- </section>
36
- </FileUpload>
37
- <section class="ele-files__wrapper">
38
- <div class="ele-file__item" v-for="(file, idx) in buildedFiles" :key="idx">
39
- <div class="ele-file__suffix--icon">
40
- <ele-icon :type="fileSuffixIcon[file.suffix] ? fileSuffixIcon[file.suffix].name : 'icon-file'"></ele-icon>
41
- </div>
42
- <div class="ele-file__name">
43
- <div class="ele-file__inner" @click="handleClickDownload(file)">{{ file.name }}</div>
44
- <div v-if="(!file.success && file.progress)" class="ele-uplpad__progress">
45
- <a-progress :strokeWidth="2" :percent="Number(file.progress)" size="small" />
46
- </div>
47
- </div>
48
- <div class="ele-file__delete" v-if="file.success || file.error || !file.response">
49
- <span class="ele-file__size">{{ (file.size / byteConversion).toFixed(2) }}M</span>
50
- <span class="ele-file__delete--icon" @click="handleClickDelete(file)">
51
- <ele-icon type="delete"></ele-icon>
52
- </span>
53
- </div>
54
- </div>
55
- </section>
56
- </div>
57
- </template>
58
-
59
- <script>
60
- import FileUpload from 'vue-upload-component'
61
- import { v4 as uuidv4 } from 'uuid'
62
- import { route, net, type } from '@idooel/shared'
63
- // import { message } from 'ant-design-vue'
64
- export default {
65
- name: 'ele-upload',
66
- components: {
67
- FileUpload
68
- },
69
- model: {
70
- prop: 'value',
71
- event: 'change'
72
- },
73
- props: {
74
- url: {
75
- type: String,
76
- //TODO
77
- default: `zuul/api-file/workbench/file`
78
- },
79
- icon: {
80
- type: String,
81
- default: '上传'
82
- },
83
- size: {
84
- type: Number,
85
- default: 100
86
- },
87
- message: {
88
- type: String,
89
- default: '单击或拖动文件到该区域以上传'
90
- },
91
- ext: {
92
- type: String
93
- },
94
- extensions: {
95
- type: String
96
- },
97
- accept: {
98
- type: String
99
- },
100
- maximum: {
101
- type: Number,
102
- default: 10
103
- },
104
- multiple: {
105
- type: Boolean,
106
- default: false
107
- },
108
- drop: {
109
- type: Boolean,
110
- default: true
111
- },
112
- value: {
113
- type: [String, Array]
114
- },
115
- querys: {
116
- type: Object,
117
- default: () => ({
118
- _csrf: localStorage.getItem('token'),
119
- _t: new Date().valueOf()
120
- })
121
- },
122
- headers: {
123
- type: Object,
124
- default: () => ({
125
- 'X-XSRF-TOKEN': localStorage.getItem('token')
126
- })
127
- },
128
- byteConversion: {
129
- type: Number,
130
- default: 1024 * 1024
131
- },
132
- chunkEnabled: {
133
- type: Boolean,
134
- default: true
135
- }
136
- },
137
- data() {
138
- return {
139
- files: [],
140
- buildedFiles: [],
141
- saveToServerAsyncPageTimer: null,
142
- uploadRefId: null
143
- }
144
- },
145
- watch: {
146
- value: {
147
- async handler (value) {
148
- if (type.isArray(value)) {
149
- // multiple
150
- } else if (type.isEmpty(value)) {
151
- this.files = []
152
- this.buildedFiles = []
153
- } else {
154
- // single
155
- this.fetchFileWithFileId()
156
- }
157
- },
158
- immediate: true
159
- }
160
- },
161
- computed: {
162
- prefixPath () {
163
- return window.prefixPath
164
- },
165
- iconIsZhWrod () {
166
- return type.isZhWord(this.icon)
167
- },
168
- getPayloads () {
169
- return {
170
- override: false
171
- }
172
- },
173
- chunkConfig () {
174
- return {
175
- action: `${this.prefixPath}zuul/api-file/workbench/file/temp/chunk/vue`,
176
- headers: {
177
- ...this.headers
178
- },
179
- minSize: 3 * this.byteConversion,
180
- maxActive: 3,
181
- maxRetries: 5,
182
- startBody: {
183
- override: true,
184
- path: '/cw'
185
- },
186
- uploadBody: {
187
- override: true,
188
- path: '/cw'
189
- },
190
- finishBody: {
191
- override: true,
192
- path: '/cw'
193
- }
194
- }
195
- },
196
- isFileUploadSuccessed () {
197
- return this.files.every(file => file.success)
198
- },
199
- isShowUploadContainer () {
200
- if (this.multiple) {
201
- if (this.isFileUploadSuccessed && this.buildedFiles.length >= this.maximum) {
202
- return false
203
- } else {
204
- return true
205
- }
206
- } else {
207
- const [file = {}] = this.buildedFiles
208
- if (this.buildedFiles.length < 1) {
209
- return true
210
- }
211
- if ((this.isFileUploadSuccessed && this.buildedFiles.length >= 1) || !file.response) {
212
- return false
213
- } else {
214
- return true
215
- }
216
- }
217
- },
218
- getMaximum () {
219
- return this.multiple ? this.maximum : 1
220
- },
221
- fileSizeLimit () {
222
- return this.size * this.byteConversion
223
- },
224
- postAction () {
225
- const ret = route.toQueryString(this.querys)
226
- return `${this.prefixPath}${this.url}?${ret}`
227
- },
228
- uploadRef () {
229
- if (!this.uploadRefId) {
230
- this.uploadRefId = `uploadRef_${uuidv4()}`
231
- }
232
- return this.uploadRefId
233
- },
234
- fileSuffixIcon () {
235
- return {
236
- 'doc': { name: 'icon-doc' },
237
- 'html': { name: 'icon-html' },
238
- 'mp4': { name: 'icon-mp' },
239
- 'pdf': { name: 'icon-pdf' },
240
- 'ppt': { name: 'icon-ppt' },
241
- 'psd': { name: 'icon-psd' },
242
- 'rtf': { name: 'icon-rtf' },
243
- 'txt': { name: 'icon-txt' },
244
- 'vis': { name: 'icon-vis' },
245
- 'xls': { name: 'icon-xls' },
246
- 'xml': { name: 'icon-xml' },
247
- 'zip': { name: 'icon-zip' },
248
- 'jpg': { name: 'icon-img' },
249
- 'mp3': { name: 'icon-mp1' },
250
- }
251
- },
252
- fileIds () {
253
- const fileIds = this.buildedFiles.map(file => {
254
- return file.fileID
255
- })
256
- return this.multiple ? fileIds : fileIds[0]
257
- },
258
- fileResponseData () {
259
- return this.multiple ? this.buildedFiles : this.buildedFiles[0]
260
- }
261
- },
262
- methods: {
263
- async fetchFileWithFileId () {
264
- if (!this.value) return
265
- await net.get(
266
- `/api-file/file/${this.value}`
267
- ).then(resp => {
268
- const { data } = resp
269
- this.buildedFiles = [data]
270
- this.files = [data]
271
- })
272
- },
273
- handleClickDownload (file) {
274
- const { fileID: fileId } = file
275
- window.open(`/api-file/workbench/file/stream/${fileId}?origin=true`)
276
- },
277
- handleClickDelete (file) {
278
- this.$refs[this.uploadRef].remove(file)
279
- const { fileID } = file
280
- this.files = this.files.filter(file => file.fileID !== fileID)
281
- this.buildedFiles = this.buildedFiles.filter(file => file.fileID !== fileID)
282
- this.$emit('change', this.fileIds)
283
- },
284
- onWatchFiles (files) {
285
- this.files = files
286
- this.buildedFiles = this.files.map(file => {
287
- return {
288
- ...file.response.data,
289
- ...file
290
- }
291
- })
292
- if (this.isFileUploadSuccessed) {
293
- this.$emit('change', this.fileIds)
294
- this.$emit('on-success', this.fileResponseData)
295
- }
296
- },
297
- async saveToServerAsyncPage (payloads = {}) {
298
- net.post('zuul/api-file/workbench/file/temp/saveToServerAsyncPage', payloads, {
299
- headers: {
300
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
301
- }
302
- }).then(resp =>{
303
- const { data } = resp
304
- if (data !== 'saveToServerAsyncPage') {
305
- clearInterval(this.saveToServerAsyncPageTimer)
306
- }
307
- })
308
- // const ret = await net.post({
309
- // url: 'zuul/api-file/workbench/file/temp/saveToServerAsyncPage',
310
- // method: 'POST',
311
- // data: { ...payloads }
312
- // }).then(resp => {
313
- // const { data: { data, code, message } } = resp
314
- // if (code !== '2000') {
315
- // this.$Message.error(message)
316
- // return
317
- // }
318
- // if (data !== 'saveToServerAsyncPage') {
319
- // clearInterval(timer)
320
- // const { fileID, size } = data
321
- // this.$emit('on-success', { ...data, fileId: fileID })
322
- // this.$Message.success('同步成功')
323
- // return { fileId: fileID, size }
324
- // }
325
- // })
326
- // return ret
327
- },
328
- // 验证文件类型
329
- validateFileType(file) {
330
- if (!file || !file.name) {
331
- console.log('文件或文件名不存在')
332
- return false
333
- }
334
-
335
- const fileName = file.name.toLowerCase()
336
- const fileExt = fileName.substring(fileName.lastIndexOf('.'))
337
- console.log('文件扩展名:', fileExt)
338
-
339
- // 只检查 extensions,accept vue-upload-component 处理
340
- if (this.extensions) {
341
- const allowedExts = this.extensions.toLowerCase()
342
- .split(',')
343
- .map(ext => ext.trim().startsWith('.') ? ext.trim() : `.${ext.trim()}`)
344
- console.log('允许的扩展名:', allowedExts)
345
-
346
- if (!allowedExts.includes(fileExt)) {
347
- console.log('扩展名不在允许列表中')
348
- this.$message.error(`不支持的文件类型 "${fileExt}",请上传 ${this.extensions} 格式的文件`)
349
- return false
350
- }
351
- }
352
-
353
- console.log('文件类型验证通过')
354
- return true
355
- },
356
- onWatchInputFiles (newFile, oldFile) {
357
- if (newFile && !oldFile) {
358
- // add file
359
- console.log('add file:', newFile)
360
- console.log('extensions:', this.extensions)
361
- console.log('accept:', this.accept)
362
-
363
- // 验证文件类型
364
- if (!this.validateFileType(newFile)) {
365
- // 如果验证失败,移除文件
366
- console.log('文件类型验证失败,尝试移除文件')
367
- console.log('uploadRef:', this.uploadRef)
368
- console.log('$refs:', this.$refs)
369
- if (this.$refs[this.uploadRef]) {
370
- this.$refs[this.uploadRef].remove(newFile)
371
- } else {
372
- console.error('无法找到 uploadRef 引用')
373
- }
374
- return
375
- }
376
- console.log('文件类型验证通过,继续上传')
377
- // 不要在这里 return,让文件继续走原有的上传逻辑
378
- }
379
- if (newFile && oldFile) {
380
- // update file
381
- console.log('update', newFile)
382
- const { success, active, chunk, response } = newFile
383
- if (chunk && success && !active) {
384
- console.log('chunk end')
385
- const { data: { file, type } } = response
386
- const payloads = {
387
- filePath: file.match(/\/cw(.*)/) ? file.match(/\/cw(.*)/)[0] : void 0,
388
- asyncID: uuidv4(),
389
- isDeleteOrigin: false,
390
- toImage: type === 'pdf' ? true : false,
391
- unzip: type === 'zip' ? true : false,
392
- _csrf: localStorage.getItem('token')
393
- }
394
- this.saveToServerAsyncPageTimer = setInterval(() => {
395
- this.saveToServerAsyncPage(payloads)
396
- }, 2000)
397
- }
398
- }
399
- if (!newFile && oldFile) {
400
- // delete file
401
- console.log('delete')
402
- }
403
- if (Boolean(newFile) !== Boolean(oldFile) || oldFile.error !== newFile.error) {
404
- if (!this.$refs[this.uploadRef].active) {
405
- this.$refs[this.uploadRef].active = true
406
- }
407
- }
408
- }
409
- }
410
- }
411
- </script>
412
-
413
- <style lang="scss" scoped>
414
- ::v-deep .ele-upload__inner {
415
- opacity: 1 !important;
416
- cursor: pointer;
417
- border: 1px dashed var(--idooel-form-title-border-color);
418
- background: var(--idooel-form-upload-bg-color) !important;
419
- &:hover {
420
- border-color: var(--idooel-form-upload-border-hover-color);
421
- }
422
- border-radius: var(--idooel-form-border-radius);
423
- }
424
- .ele-upload__wrapper {
425
- width: 100%;
426
- .ele-upload__area {
427
- padding: 16px;
428
- width: 100%;
429
- height: 80px;
430
- display: flex;
431
- flex-direction: row;
432
- .ele-upload__area--icon {
433
- color: var(--idooel-primary-color);
434
- display: flex;
435
- flex-direction: row;
436
- align-items: center;
437
- font-size: 16x;
438
- .anticon-cloud-upload {
439
- font-size: 48px;
440
- color: var(--idooel-primary-color);
441
- }
442
- .anticon {
443
- font-size: 48px;
444
- color: var(--idooel-primary-color);
445
- }
446
- }
447
- .ele-upload__area--text {
448
- margin-left: 16px;
449
- .ele-upload__message {
450
- font-size: 16px;
451
- color: var(--idoole-black-088);
452
- text-align: left;
453
- }
454
- .ele-upload__ext {
455
- text-align: left;
456
- font-size: 14px;
457
- color: var(--idoole-black-06);
458
- }
459
- }
460
- }
461
- .ele-files__wrapper {
462
- .ele-file__item {
463
- width: 100%;
464
- margin-top: 8px;
465
- padding: 8px 12px;
466
- border-radius: var(--idooel-form-border-radius);
467
- background: var(--idooel-form-upload-bg-color);
468
- display: flex;
469
- flex-direction: row;
470
- align-items: center;
471
- .ele-file__suffix--icon {}
472
- .ele-file__name {
473
- flex: 1;
474
- text-align: left;
475
- white-space: nowrap;
476
- overflow: hidden;
477
- font-size: 14px;
478
- margin-left: 8px;
479
- cursor: pointer;
480
- .ele-file__inner {
481
- overflow: hidden;
482
- text-overflow: ellipsis;
483
- }
484
- }
485
- .ele-file__delete {
486
- margin-left: 8px;
487
- .ele-file__delete--icon {
488
- margin-left: 8px;
489
- cursor: pointer;
490
- }
491
- }
492
- }
493
- }
494
- }
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
+ }
495
999
  </style>