fix: 图标上传不再手动设置 multipart Content-Type

避免缺少 boundary 导致后端读不到 icon_key;失败时展示具体 key。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-25 20:56:04 +08:00
parent ee9c3c2381
commit 975e37411e

View File

@@ -408,6 +408,10 @@ async function loadPindao() {
async function uploadIcon(file, iconKey) { async function uploadIcon(file, iconKey) {
if (!file?.raw) return if (!file?.raw) return
if (!iconKey) {
ElMessage.error('缺少 icon_key')
return
}
uploadingKey.value = iconKey uploadingKey.value = iconKey
try { try {
const fd = new FormData() const fd = new FormData()
@@ -415,17 +419,17 @@ async function uploadIcon(file, iconKey) {
fd.append('file', file.raw) fd.append('file', file.raw)
fd.append('icon_key', iconKey) fd.append('icon_key', iconKey)
fd.append('action', 'upload') fd.append('action', 'upload')
const res = await request.post(JITUAN_API.miniappIconManage, fd, { // 不要手动设 Content-Type否则缺 boundary后端可能读不到 icon_key
headers: { 'Content-Type': 'multipart/form-data' }, const res = await request.post(JITUAN_API.miniappIconManage, fd)
})
if (res.code === 0) { if (res.code === 0) {
ElMessage.success('上传成功') ElMessage.success('上传成功')
await loadIcons() await loadIcons()
} else { } else {
ElMessage.error(res.msg || '上传失败') ElMessage.error(res.msg || `上传失败(${iconKey})`)
} }
} catch { } catch (e) {
ElMessage.error('上传失败') const msg = e?.response?.data?.msg || e?.message || '上传失败'
ElMessage.error(`${msg} [${iconKey}]`)
} finally { } finally {
uploadingKey.value = '' uploadingKey.value = ''
} }