Browse Source

文件上传失败提示

wuhb 2 tháng trước cách đây
mục cha
commit
40ca636d0b
1 tập tin đã thay đổi với 22 bổ sung17 xóa
  1. 22 17
      utils/upload.uts

+ 22 - 17
utils/upload.uts

@@ -84,23 +84,28 @@ export const uploadFile = (filePath: string, businessType: string): Promise<Uplo
                         const result = JSON.parse(resData) as UTSJSONObject
                         // 获取第一个文件信息
                         const fileInfo = result as UTSJSONObject
-                        const fileName = fileInfo['fileName'] as string
-                        
-                        // 构建完整的 URL
-                        const url = getFileViewUrl(fileName)
-                        
-                        // 返回 UploadResponse
-                        const uploadResult: UploadResponse = {
-                            url: url,
-                            fileId: fileName,
-                            fileName: fileName,
-                            filePath: filePath,
-                            fileSize: 0,
-                            fileExt: '',
-                            businessType: businessType
-                        }
-                        
-                        resolve(uploadResult)
+						let code = fileInfo["code"] as number | null;
+						let msg = fileInfo["msg"] as string | null;
+						if (code == 200) {
+							const fileName = fileInfo['fileName'] as string
+							// 构建完整的 URL
+							const url = getFileViewUrl(fileName)
+							// 返回 UploadResponse
+							const uploadResult: UploadResponse = {
+							    url: url,
+							    fileId: fileName,
+							    fileName: fileName,
+							    filePath: filePath,
+							    fileSize: 0,
+							    fileExt: '',
+							    businessType: businessType
+							}
+							resolve(uploadResult)
+						}else{
+							const errorMsg = msg != null ? msg : "请求失败";
+							console.error('响应数据解析失败:', errorMsg)
+							reject(new Error(errorMsg))
+						}
                     } catch (e: any) {
                         console.error('响应数据解析失败:', e)
                         reject(new Error('响应数据解析失败'))