fix 80645
This commit is contained in:
+32
-17
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="upload-comp">
|
<div class="upload-comp">
|
||||||
<div class="upload-box">
|
<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>
|
<van-button type="primary" plain>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<van-icon class="iconfont" class-prefix="icon" name="shangchuan" />
|
<van-icon class="iconfont" class-prefix="icon" name="shangchuan" />
|
||||||
@@ -83,24 +83,39 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleUpload (event) {
|
async handleUpload (event) {
|
||||||
const e = window.event || event
|
const e = window.event || event
|
||||||
const file = e.target.files[0]
|
const fileList = e.target.files || []
|
||||||
/* 进行相关校验 */
|
for (let i = 0; i < fileList.length; i++) {
|
||||||
const checkResult = this.beforeUpload(file)
|
const file = fileList[i]
|
||||||
if (!checkResult) {
|
/* 进行相关校验 */
|
||||||
return
|
const checkResult = this.beforeUpload(file)
|
||||||
}
|
if (!checkResult) {
|
||||||
const formData = new FormData()
|
return
|
||||||
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 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) {
|
beforeUpload (file) {
|
||||||
|
|||||||
Reference in New Issue
Block a user