Skip to content

Commit 25e8a7e

Browse files
authored
Hotfix issue (#550)
* fix(upload images): optimize upload image component to fit Vue3 fix #537 * fix(upload image): Optimize upload image component to fit Vue3 fix #537 #536 #529
1 parent d948dc8 commit 25e8a7e

File tree

2 files changed

+31
-36
lines changed

2 files changed

+31
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "node script/plugin-get-config.js && vue-cli-service build",
88
"test:unit": "vue-cli-service test:unit",
99
"lint": "vue-cli-service lint",
10-
"commit": "git-cz",
10+
"commit": "git add . && git-cz",
1111
"plugin:init": "node script/plugin-init.js",
1212
"plugin:new": "node script/plugin-new.js",
1313
"plugin:reconfig": "node script/plugin-get-config.js"

src/component/base/upload-image/index.vue

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ todo: 文件判断使用 serveWorker 优化性能
88

99
<template>
1010
<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">
1414
<el-image
1515
:fit="fit"
1616
:ref="setImageRef"
1717
:src="item.display"
1818
class="thumb-item-img"
1919
:previewSrcList="srcList"
20-
style="width: 100%; height: 100%;"
20+
style="width: 100%; height: 100%"
2121
>
2222
</el-image>
2323
<div class="info">
@@ -45,7 +45,7 @@ todo: 文件判断使用 serveWorker 优化性能
4545
v-if="preview"
4646
class="control-bottom-btn el-icon-view"
4747
title="预览"
48-
style="cursor: pointer;"
48+
style="cursor: pointer"
4949
@click.stop="previewImg(item, i)"
5050
></i>
5151
<i
@@ -58,30 +58,29 @@ todo: 文件判断使用 serveWorker 优化性能
5858
</div>
5959
</div>
6060
</div>
61-
</template>
62-
<template v-else>
61+
</div>
62+
<div v-else>
6363
<div
6464
class="upload-item"
6565
:class="{ disabled: disabled }"
66-
:key="item.id"
6766
:style="boxStyle"
6867
@click="handleClick(item.id)"
6968
@keydown="handleKeydown($event, item.id)"
7069
>
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>
7372
</div>
74-
</template>
75-
</template>
73+
</div>
74+
</div>
7675
<input
77-
class="upload-imgs__input"
78-
type="file"
7976
ref="input"
80-
@change="handleChange"
81-
:multiple="multiple"
77+
type="file"
8278
:accept="accept"
79+
:multiple="multiple"
80+
@change="handleChange"
81+
class="upload-imgs__input"
82+
aria-labelledby="Upload images"
8383
/>
84-
<!-- <el-image-viewer v-if="showViewer" @close="closeViewer" :initial-index="imageInitialIndex" :url-list="srcList" /> -->
8584
</div>
8685
</template>
8786

@@ -180,7 +179,7 @@ function createItem(data = null, oldData = {}) {
180179
item.src = ''
181180
item.imgId = ''
182181
item.display = data.localSrc || item.display
183-
item = Object.assign({}, data, item)
182+
item = { ...data, ...item }
184183
return item
185184
}
186185
@@ -190,7 +189,7 @@ function createItem(data = null, oldData = {}) {
190189
item.src = data.src || item.src
191190
item.display = data.display || item.display
192191
item.status = data.status || 'init'
193-
item = Object.assign({}, data, item)
192+
item = { ...data, ...item }
194193
return item
195194
}
196195
@@ -442,7 +441,7 @@ export default {
442441
if (basicRule.allowAnimated && basicRule.allowAnimated > 0) {
443442
if (basicRule.allowAnimated === 1) {
444443
tips.push('不允许上传动图')
445-
} else if (basicRule.allowAnimated === 1) {
444+
} else if (basicRule.allowAnimated === 2) {
446445
tips.push('只允许上传动图')
447446
}
448447
}
@@ -525,7 +524,7 @@ export default {
525524
// 清除上次一的定时器
526525
if (time && catchData.length < uploadLimit) {
527526
clearTimeout(time)
528-
// 此时修改上一个 promise 状态为reslove
527+
// 此时修改上一个 promise 状态为resolve
529528
}
530529
531530
// 等待100ms
@@ -561,7 +560,7 @@ export default {
561560
if (item.status === 'input' || !item.file) {
562561
return
563562
}
564-
// eslint-disable-next-line
563+
565564
item.loading = true
566565
if (this.beforeUpload && typeof this.beforeUpload === 'function') {
567566
if (typeof this.beforeUpload === 'function') {
@@ -856,26 +855,22 @@ export default {
856855
* @param {File} file 图片文件
857856
*/
858857
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
870864
}
865+
871866
const asyncList = []
872867
for (let i = 0; i < files.length; i += 1) {
873868
asyncList.push(handleImg(files[i]))
874869
}
875870
try {
876871
imgInfoList = await Promise.all(asyncList)
877872
// 设置图片信息
878-
this.setImgInfo(imgInfoList, currentId)
873+
this.setImgInfo(currentId, imgInfoList)
879874
// 开启自动上传
880875
if (autoUpload) {
881876
this.itemList.forEach(ele => {
@@ -899,7 +894,7 @@ export default {
899894
* @param {Array<LocalFileInfo>} imgInfoList 需要设置的图像数组
900895
* @param {Number|String} id 操作项的 id
901896
*/
902-
setImgInfo(imgInfoList = [], currentId) {
897+
setImgInfo(currentId, imgInfoList = []) {
903898
const { max, itemList } = this
904899
// 找到特定图像位置
905900
const index = this.itemList.findIndex(item => item.id === currentId)

0 commit comments

Comments
 (0)