mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
refactor(baInput):图片和文件上传组件请求上传接口时可以携带额外数据
This commit is contained in:
parent
a2e17afed0
commit
e61bc0b50b
@ -23,6 +23,7 @@ import { genFileId, ElButton } from 'element-plus'
|
||||
import type { UploadInstance, UploadRawFile, UploadFile } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import Editor from '/@/components/editor/index.vue'
|
||||
import _ from 'lodash'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'baInput',
|
||||
@ -176,6 +177,16 @@ export default defineComponent({
|
||||
})
|
||||
}
|
||||
|
||||
// 图片/文件上传时添加请求额外数据
|
||||
const formDataAppend = (fd: FormData, data: anyObj = {}) => {
|
||||
if (data && !_.isEmpty(data)) {
|
||||
for (const key in data) {
|
||||
fd.append(key, data[key])
|
||||
}
|
||||
}
|
||||
return fd
|
||||
}
|
||||
|
||||
const buildFun = new Map([
|
||||
['string', sntp],
|
||||
['number', sntp],
|
||||
@ -395,6 +406,7 @@ export default defineComponent({
|
||||
if (!file || !file.raw) return
|
||||
let fd = new FormData()
|
||||
fd.append('file', file.raw!)
|
||||
fd = formDataAppend(fd, props.attr.data)
|
||||
fileUpload(fd).then((res) => {
|
||||
if (res.code == 1) {
|
||||
state.lastFullUrl = res.data.file.full_url
|
||||
@ -529,6 +541,7 @@ export default defineComponent({
|
||||
if (!file || !file.raw) return
|
||||
let fd = new FormData()
|
||||
fd.append('file', file.raw!)
|
||||
fd = formDataAppend(fd, props.attr.data)
|
||||
fileUpload(fd).then((res) => {
|
||||
if (res.code == 1) {
|
||||
urlKey++
|
||||
@ -633,6 +646,7 @@ export default defineComponent({
|
||||
if (!file || !file.raw) return
|
||||
let fd = new FormData()
|
||||
fd.append('file', file.raw!)
|
||||
fd = formDataAppend(fd, props.attr.data)
|
||||
fileUpload(fd).then((res) => {
|
||||
if (res.code == 1) {
|
||||
lastFullUrl.value = res.data.file.full_url
|
||||
@ -754,6 +768,7 @@ export default defineComponent({
|
||||
if (!file || !file.raw) return
|
||||
let fd = new FormData()
|
||||
fd.append('file', file.raw!)
|
||||
fd = formDataAppend(fd, props.attr.data)
|
||||
fileUpload(fd).then((res) => {
|
||||
if (res.code == 1) {
|
||||
urlKey++
|
||||
|
Loading…
Reference in New Issue
Block a user