Quellcode durchsuchen

修改细节问题

快乐的梦鱼 vor 1 Monat
Ursprung
Commit
aa8d40f034

+ 4 - 4
src/api/CommonContent.ts

@@ -426,7 +426,7 @@ export class CommonContentApi extends AppServerRequestModule<DataModel> {
   /**
    * 上传文件到服务器
    */
-  async uploadFile(file: string, fileType?: "image" | "video" | "audio" | undefined, name = 'file', data?: any) {
+  async uploadFile(file: string, fileType?: "image" | "video" | "audio" | undefined, name = 'file', data?: any, receiveTask?: (result: UniApp.UploadTask) => void) {
     return new Promise<{
       fullurl: string,
       url: string
@@ -437,14 +437,12 @@ export class CommonContentApi extends AppServerRequestModule<DataModel> {
         data: data,
         header: {},
       }
-      console.log(url);
-      
       if (this.config.requestInceptor) {
         const { newReq, newUrl } = this.config.requestInceptor(url, req);
         url = newUrl;
         data = newReq;
       }
-      uni.uploadFile({
+      const task = uni.uploadFile({
         url: url,
         name,
         header: req.header,
@@ -461,6 +459,8 @@ export class CommonContentApi extends AppServerRequestModule<DataModel> {
           reject(result);
         },
       })
+      if (receiveTask)
+        receiveTask(task);
     })
   }
 }

+ 1 - 1
src/common/components/upload/AliOssUploadCo.ts

@@ -15,7 +15,7 @@ function generatePolicyAndSignature(key: string, accessKeySecret: string) {
     const policyText = {
       expiration: expiration,
       conditions: [
-        ["content-length-range", 0, 10485760 * 10], // 100MB限制
+        ["content-length-range", 0, 10485760 * 256], // 256MB限制
         ["starts-with", "$key", key.substring(0, key.lastIndexOf('/') + 1)]
       ]
     };

+ 8 - 2
src/common/components/upload/ImageUploadCo.ts

@@ -4,7 +4,13 @@ import type { UploaderAction } from "@/components/form/Uploader";
 export function useImageSimpleUploadCo(additionData?: Record<string, any>) {
   return (action: UploaderAction) => {
     action.onStart('正在上传');
-    CommonContent.uploadFile(action.item.filePath, 'image', 'file', additionData)
+    let task: UniApp.UploadTask | null = null;
+    CommonContent.uploadFile(action.item.filePath, 'image', 'file', additionData, (t) => {
+      task = t;
+      task.onProgressUpdate((res) => {
+        action.onProgress(res.progress);
+      });
+    })
       .then((res) => {
         action.onProgress(100);
         action.onFinish({
@@ -15,7 +21,7 @@ export function useImageSimpleUploadCo(additionData?: Record<string, any>) {
         action.onError?.(err);
       })
     return () => {
-      //取消上传.暂不处理
+      task?.abort();
     };
   }
 }