修复上传组件

This commit is contained in:
aixianling
2022-02-25 11:12:41 +08:00
parent b5d0a0a02c
commit 21be21c53a

View File

@@ -119,16 +119,21 @@ export default {
return this.$u.toast(`不能超过${Math.ceil(this.size / 1024 / 1024)}MB`)
}
uni.showLoading({title: '上传中'})
let formData = new FormData()
formData.append('file', img)
if (this.manual) {
this.$emit('manual', img)
uni.hideLoading()
} else {
this.$http.post(this.action, formData, {
params: {type: this.type},
}).then((res) => {
uni.uploadFile({
url: this.$instance.defaults.baseURL + '/admin/file/add',
filePath: img,
name: 'file',
header: {
'Content-Type': 'multipart/form-data',
Authorization: uni.getStorageSync('token'),
},
success: response => {
uni.hideLoading()
const res = JSON.parse(response.data)
if (res?.data) {
this.$emit('data', res.data)
this.$u.toast('上传成功!')
@@ -145,12 +150,12 @@ export default {
}
this.$emit("update:def", this.fileList)
this.$emit("list", this.fileList)
this.$emit('input', [...this.fileList])
this.$emit('change', [...this.fileList])
} else {
this.$u.toast(res.msg)
}
}).catch(err => {
this.$u.toast(err)
uni.hideLoading()
}
})
}