diff --git a/src/api/system/file/index.ts b/src/api/system/file/index.ts index 38bdd42..2411108 100644 --- a/src/api/system/file/index.ts +++ b/src/api/system/file/index.ts @@ -63,22 +63,37 @@ export async function uploadFileByPath(filePath: string) { return } + const tenantId = Taro.getStorageSync('TenantId') || TenantId + + const header: Record = { + 'content-type': 'application/json', + TenantId: String(tenantId) + } + // 统一走同一个上传接口:既支持图片,也支持文档等文件(由后端决定白名单/大小限制) Taro.uploadFile({ url: 'https://server.websoft.top/api/oss/upload', filePath, name: 'file', - header: { - 'content-type': 'application/json', - TenantId - }, + header, success: (res) => { try { - const data = JSON.parse(res.data); + if ((res as any)?.statusCode && (res as any).statusCode !== 200) { + reject(new Error(`上传失败(HTTP ${(res as any).statusCode})`)) + return + } + const raw = (res as any)?.data + const data = typeof raw === 'string' ? JSON.parse(raw) : raw if (data.code === 0) { resolve(data.data) } else { - reject(new Error(data.message || '上传失败')) + let msg = String(data.message || '上传失败') + try { + msg = decodeURIComponent(escape(msg)) + } catch (_e) { + // ignore + } + reject(new Error(msg || '上传失败')) } } catch (_error) { reject(new Error('解析响应数据失败')) diff --git a/src/credit/order/add.tsx b/src/credit/order/add.tsx index 1c28cd8..a55fd2e 100644 --- a/src/credit/order/add.tsx +++ b/src/credit/order/add.tsx @@ -108,7 +108,7 @@ export default function CreditOrderAddPage() { Taro.showToast({ title: '上传成功', icon: 'success' }) } catch (e) { console.error('上传图片失败:', e) - Taro.showToast({ title: '上传失败,请重试', icon: 'none' }) + Taro.showToast({ title: String((e as any)?.message || '上传失败,请重试'), icon: 'none' }) } finally { setUploading(false) } @@ -151,7 +151,7 @@ export default function CreditOrderAddPage() { Taro.showToast({ title: '上传成功', icon: 'success' }) } catch (e) { console.error('上传文件失败:', e) - Taro.showToast({ title: '上传失败,请重试', icon: 'none' }) + Taro.showToast({ title: String((e as any)?.message || '上传失败,请重试'), icon: 'none' }) } finally { setUploading(false) }