From 7bd338e07c31f61b35b465789d618f4a37e1113e Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Sat, 21 Jun 2025 10:29:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(useUpload):=20=E4=BF=AE=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=E5=92=8C=E5=A4=A7=E5=B0=8F=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整条件编译逻辑,确保在非微信小程序环境下也能正确获取文件路径和大小 --- src/hooks/useUpload.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hooks/useUpload.ts b/src/hooks/useUpload.ts index a3edb3b..c9accca 100644 --- a/src/hooks/useUpload.ts +++ b/src/hooks/useUpload.ts @@ -37,19 +37,19 @@ export default function useUpload(options: TOptions = {} count: 1, success: (res: any) => { console.log('File selected successfully:', res) - // h5中res:{errMsg: "chooseImage:ok", tempFilePaths: "blob:http://localhost:9000/f74ab6b8-a14d-4cb6-a10d-fcf4511a0de5", tempFiles: [File]} + // App or h5中res:{errMsg: "chooseImage:ok", tempFilePaths: "blob:http://localhost:9000/f74ab6b8-a14d-4cb6-a10d-fcf4511a0de5", tempFiles: [File]} // h5的File有一下字段:{name: "girl.jpeg", size: 48976, type: "image/jpeg"} // 小程序中res:{errMsg: "chooseImage:ok", tempFiles: [{fileType: "image", size: 48976, tempFilePath: "http://tmp/5iG1WpIxTaJf3ece38692a337dc06df7eb69ecb49c6b.jpeg"}]} let tempFilePath = '' let size = 0 - // #ifdef H5 - tempFilePath = res.tempFilePaths[0] - size = res.tempFiles[0].size - // #endif // #ifdef MP-WEIXIN tempFilePath = res.tempFiles[0].tempFilePath size = res.tempFiles[0].size // #endif + // #ifndef MP-WEIXIN + tempFilePath = res.tempFilePaths[0] + size = res.tempFiles[0].size + // #endif handleFileChoose({ tempFilePath, size }) }, fail: (err: any) => {