소스 검색

fix(useUpload): 修复文件路径和大小获取逻辑错误

调整条件编译逻辑,确保在非微信小程序环境下也能正确获取文件路径和大小
feige996 10 달 전
부모
커밋
7bd338e07c
1개의 변경된 파일5개의 추가작업 그리고 5개의 파일을 삭제
  1. 5 5
      src/hooks/useUpload.ts

+ 5 - 5
src/hooks/useUpload.ts

@@ -37,19 +37,19 @@ export default function useUpload<T extends TfileType>(options: TOptions<T> = {}
       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) => {