修复上传组件

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`) return this.$u.toast(`不能超过${Math.ceil(this.size / 1024 / 1024)}MB`)
} }
uni.showLoading({title: '上传中'}) uni.showLoading({title: '上传中'})
let formData = new FormData()
formData.append('file', img)
if (this.manual) { if (this.manual) {
this.$emit('manual', img) this.$emit('manual', img)
uni.hideLoading() uni.hideLoading()
} else { } else {
this.$http.post(this.action, formData, { uni.uploadFile({
params: {type: this.type}, url: this.$instance.defaults.baseURL + '/admin/file/add',
}).then((res) => { filePath: img,
uni.hideLoading() name: 'file',
if (res?.data) { header: {
this.$emit('data', res.data) 'Content-Type': 'multipart/form-data',
this.$u.toast('上传成功!') Authorization: uni.getStorageSync('token'),
if (this.action == '/app/wxcp/upload/uploadFile') { },
this.$emit('update:mediaId', res.data?.media?.mediaId) success: response => {
this.$emit('update:fileId', res.data.file.id) uni.hideLoading()
this.fileList.push(res.data.file) const res = JSON.parse(response.data)
} else if (this.action == '/admin/file/add2') { if (res?.data) {
let info = res.data this.$emit('data', res.data)
this.$emit('update:fileId', info?.id) this.$u.toast('上传成功!')
this.fileList.push(res.data) if (this.action == '/app/wxcp/upload/uploadFile') {
} else if (this.action == '/admin/file/add-portrait') { this.$emit('update:mediaId', res.data?.media?.mediaId)
this.fileList.push({url: res.data?.split(";")?.[0], id: res.data?.split(";")?.[1]}) 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()
}) })
} }