fix 80645
This commit is contained in:
+32
-17
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="upload-comp">
|
||||
<div class="upload-box">
|
||||
<input type="file" class="upload-box-input" @change="handleUpload" />
|
||||
<input type="file" class="upload-box-input" @change="handleUpload" multiple="multiple" />
|
||||
<van-button type="primary" plain>
|
||||
<template #icon>
|
||||
<van-icon class="iconfont" class-prefix="icon" name="shangchuan" />
|
||||
@@ -83,24 +83,39 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleUpload (event) {
|
||||
async handleUpload (event) {
|
||||
const e = window.event || event
|
||||
const file = e.target.files[0]
|
||||
/* 进行相关校验 */
|
||||
const checkResult = this.beforeUpload(file)
|
||||
if (!checkResult) {
|
||||
return
|
||||
}
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
formData.append('biz', 'temp')
|
||||
uploadFile(formData).then(res => {
|
||||
if (res.success) {
|
||||
this.fileList.push(res.result)
|
||||
this.$emit('change', this.fileList.map(item => item.id).join(','))
|
||||
} else {
|
||||
this.$message(res.message)
|
||||
const fileList = e.target.files || []
|
||||
for (let i = 0; i < fileList.length; i++) {
|
||||
const file = fileList[i]
|
||||
/* 进行相关校验 */
|
||||
const checkResult = this.beforeUpload(file)
|
||||
if (!checkResult) {
|
||||
return
|
||||
}
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
formData.append('biz', 'temp')
|
||||
const result = await this.uploadFileApi(formData)
|
||||
if (result) {
|
||||
this.fileList.push(result)
|
||||
}
|
||||
}
|
||||
this.$emit('change', this.fileList.map(item => item.id).join(','))
|
||||
},
|
||||
uploadFileApi (formData) {
|
||||
return new Promise(resolve => {
|
||||
let result
|
||||
uploadFile(formData).then(res => {
|
||||
if (res.success) {
|
||||
result = res.result
|
||||
} else {
|
||||
this.$message(res.message)
|
||||
result = false
|
||||
}
|
||||
}).finally(() => {
|
||||
resolve(result)
|
||||
})
|
||||
})
|
||||
},
|
||||
beforeUpload (file) {
|
||||
|
||||
Reference in New Issue
Block a user