mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-07-24 13:36:28 +00:00
feat: 支持图片上传
This commit is contained in:
@@ -67,14 +67,27 @@ export default {
|
|||||||
upload: {
|
upload: {
|
||||||
fieldName: 'file',
|
fieldName: 'file',
|
||||||
url: `${API_BASE_URL}/api/upload`,
|
url: `${API_BASE_URL}/api/upload`,
|
||||||
linkToImgUrl: `${API_BASE_URL}/api/upload/url`,
|
|
||||||
accept: 'image/*,video/*',
|
accept: 'image/*,video/*',
|
||||||
multiple: false,
|
multiple: false,
|
||||||
headers: { Authorization: `Bearer ${getToken()}` },
|
headers: { Authorization: `Bearer ${getToken()}` },
|
||||||
format(files, responseText) {
|
format(files, responseText) {
|
||||||
const res = JSON.parse(responseText)
|
const res = JSON.parse(responseText)
|
||||||
if (res.code === 0) return res.data.url
|
if (res.code === 0) {
|
||||||
throw new Error(res.msg || '上传失败')
|
return JSON.stringify({
|
||||||
|
code: 0,
|
||||||
|
msg: '',
|
||||||
|
data: {
|
||||||
|
errFiles: [],
|
||||||
|
succMap: { [files[0].name]: res.data.url }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return JSON.stringify({
|
||||||
|
code: 1,
|
||||||
|
msg: '上传失败',
|
||||||
|
data: { errFiles: files.map(f => f.name), succMap: {} }
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
toolbarConfig: { pin: true },
|
toolbarConfig: { pin: true },
|
||||||
@@ -98,4 +111,3 @@ export default {
|
|||||||
border: 1px solid #e2e2e2;
|
border: 1px solid #e2e2e2;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user