修复上传组件

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

View File

@@ -119,38 +119,43 @@ 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.hideLoading()
if (res?.data) {
this.$emit('data', res.data)
this.$u.toast('上传成功!')
if (this.action == '/app/wxcp/upload/uploadFile') {
this.$emit('update:mediaId', res.data?.media?.mediaId)
this.$emit('update:fileId', res.data.file.id)
this.fileList.push(res.data.file)
} else if (this.action == '/admin/file/add2') {
let info = res.data
this.$emit('update:fileId', info?.id)
this.fileList.push(res.data)
} else if (this.action == '/admin/file/add-portrait') {
this.fileList.push({url: res.data?.split(";")?.[0], id: res.data?.split(";")?.[1]})
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('上传成功!')
if (this.action == '/app/wxcp/upload/uploadFile') {
this.$emit('update:mediaId', res.data?.media?.mediaId)
this.$emit('update:fileId', res.data.file.id)
this.fileList.push(res.data.file)
} else if (this.action == '/admin/file/add2') {
let info = res.data
this.$emit('update:fileId', info?.id)
this.fileList.push(res.data)
} else if (this.action == '/admin/file/add-portrait') {
this.fileList.push({url: res.data?.split(";")?.[0], id: res.data?.split(";")?.[1]})
}
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)
}
this.$emit("update:def", this.fileList)
this.$emit("list", this.fileList)
} else {
this.$u.toast(res.msg)
}
}).catch(err => {
this.$u.toast(err)
uni.hideLoading()
})
}