@@ -8,16 +8,16 @@ todo: 文件判断使用 serveWorker 优化性能
8
8
9
9
<template >
10
10
<div class =" upload-imgs-container" v-loading =" loading" >
11
- <template v-for =" (item , i ) in itemList " >
12
- <template v-if =" item .display " >
13
- <div class =" thumb-item" :key = " item.id " : style =" boxStyle" v-loading =" item.loading" >
11
+ <div v-for =" (item, i) in itemList" :key = " item.id " >
12
+ <div v-if =" item.display" >
13
+ <div class =" thumb-item" :style =" boxStyle" v-loading =" item.loading" >
14
14
<el-image
15
15
:fit =" fit"
16
16
:ref =" setImageRef"
17
17
:src =" item.display"
18
18
class =" thumb-item-img"
19
19
:previewSrcList =" srcList"
20
- style =" width : 100% ; height : 100% ; "
20
+ style =" width : 100% ; height : 100% "
21
21
>
22
22
</el-image >
23
23
<div class =" info" >
@@ -45,7 +45,7 @@ todo: 文件判断使用 serveWorker 优化性能
45
45
v-if =" preview"
46
46
class =" control-bottom-btn el-icon-view"
47
47
title =" 预览"
48
- style =" cursor : pointer ; "
48
+ style =" cursor : pointer "
49
49
@click.stop =" previewImg(item, i)"
50
50
></i >
51
51
<i
@@ -58,30 +58,29 @@ todo: 文件判断使用 serveWorker 优化性能
58
58
</div >
59
59
</div >
60
60
</div >
61
- </template >
62
- <template v-else >
61
+ </div >
62
+ <div v-else >
63
63
<div
64
64
class =" upload-item"
65
65
:class =" { disabled: disabled }"
66
- :key =" item.id"
67
66
:style =" boxStyle"
68
67
@click =" handleClick(item.id)"
69
68
@keydown =" handleKeydown($event, item.id)"
70
69
>
71
- <i class =" el-icon-plus" style =" font-size : 3em ; " ></i >
72
- <div v-html =" rulesTip.join('<br>')" style =" margin-top : 1em ; " ></div >
70
+ <i class =" el-icon-plus" style =" font-size : 3em " ></i >
71
+ <div v-html =" rulesTip.join('<br>')" style =" margin-top : 1em " ></div >
73
72
</div >
74
- </template >
75
- </template >
73
+ </div >
74
+ </div >
76
75
<input
77
- class =" upload-imgs__input"
78
- type =" file"
79
76
ref =" input"
80
- @change =" handleChange"
81
- :multiple =" multiple"
77
+ type =" file"
82
78
:accept =" accept"
79
+ :multiple =" multiple"
80
+ @change =" handleChange"
81
+ class =" upload-imgs__input"
82
+ aria-labelledby =" Upload images"
83
83
/>
84
- <!-- <el-image-viewer v-if="showViewer" @close="closeViewer" :initial-index="imageInitialIndex" :url-list="srcList" /> -->
85
84
</div >
86
85
</template >
87
86
@@ -180,7 +179,7 @@ function createItem(data = null, oldData = {}) {
180
179
item .src = ' '
181
180
item .imgId = ' '
182
181
item .display = data .localSrc || item .display
183
- item = Object . assign ({}, data, item)
182
+ item = { ... data, ... item }
184
183
return item
185
184
}
186
185
@@ -190,7 +189,7 @@ function createItem(data = null, oldData = {}) {
190
189
item .src = data .src || item .src
191
190
item .display = data .display || item .display
192
191
item .status = data .status || ' init'
193
- item = Object . assign ({}, data, item)
192
+ item = { ... data, ... item }
194
193
return item
195
194
}
196
195
@@ -442,7 +441,7 @@ export default {
442
441
if (basicRule .allowAnimated && basicRule .allowAnimated > 0 ) {
443
442
if (basicRule .allowAnimated === 1 ) {
444
443
tips .push (' 不允许上传动图' )
445
- } else if (basicRule .allowAnimated === 1 ) {
444
+ } else if (basicRule .allowAnimated === 2 ) {
446
445
tips .push (' 只允许上传动图' )
447
446
}
448
447
}
@@ -525,7 +524,7 @@ export default {
525
524
// 清除上次一的定时器
526
525
if (time && catchData .length < uploadLimit) {
527
526
clearTimeout (time)
528
- // 此时修改上一个 promise 状态为reslove
527
+ // 此时修改上一个 promise 状态为resolve
529
528
}
530
529
531
530
// 等待100ms
@@ -561,7 +560,7 @@ export default {
561
560
if (item .status === ' input' || ! item .file ) {
562
561
return
563
562
}
564
- // eslint-disable-next-line
563
+
565
564
item .loading = true
566
565
if (this .beforeUpload && typeof this .beforeUpload === ' function' ) {
567
566
if (typeof this .beforeUpload === ' function' ) {
@@ -856,26 +855,22 @@ export default {
856
855
* @param {File} file 图片文件
857
856
*/
858
857
const handleImg = async file => {
859
- try {
860
- // 获取图像信息
861
- const info = await this .getImgInfo (file)
862
- cache .push (info)
863
- // 验证图像信息
864
- await this .validateImg (info)
865
- return info
866
- } catch (err) {
867
- // 往外抛异常
868
- throw err
869
- }
858
+ // 获取图像信息
859
+ const info = await this .getImgInfo (file)
860
+ cache .push (info)
861
+ // 验证图像信息
862
+ await this .validateImg (info)
863
+ return info
870
864
}
865
+
871
866
const asyncList = []
872
867
for (let i = 0 ; i < files .length ; i += 1 ) {
873
868
asyncList .push (handleImg (files[i]))
874
869
}
875
870
try {
876
871
imgInfoList = await Promise .all (asyncList)
877
872
// 设置图片信息
878
- this .setImgInfo (imgInfoList, currentId )
873
+ this .setImgInfo (currentId, imgInfoList )
879
874
// 开启自动上传
880
875
if (autoUpload) {
881
876
this .itemList .forEach (ele => {
@@ -899,7 +894,7 @@ export default {
899
894
* @param {Array<LocalFileInfo>} imgInfoList 需要设置的图像数组
900
895
* @param {Number|String} id 操作项的 id
901
896
*/
902
- setImgInfo (imgInfoList = [], currentId ) {
897
+ setImgInfo (currentId , imgInfoList = []) {
903
898
const { max , itemList } = this
904
899
// 找到特定图像位置
905
900
const index = this .itemList .findIndex (item => item .id === currentId)
0 commit comments