فهرست منبع

取消上传修正

zhuli 1 روز پیش
والد
کامیت
52f4be0010

+ 3 - 1
src/api/upload.js

@@ -1,4 +1,5 @@
 import { useUserStore } from "@/stores/modules/user";
+import { useSimpleUploadOverlayStore } from "@/stores/modules/simpleUploadOverlay";
 import { ElMessage } from "element-plus";
 import { AI_UPLOAD_FILES_PUBLIC_BASE, BASE_AI_URL } from "@/utils/config";
 import { withSimpleUploadOverlay } from "@/utils/withSimpleUploadOverlay";
@@ -441,7 +442,8 @@ export async function uploadFilesToOss(files, _fileType, options = {}) {
 
     let uploadedUrls;
     if (skipSimpleUploadOverlay) {
-      uploadedUrls = await runUpload(null);
+      const overlaySignal = useSimpleUploadOverlayStore().getActiveAbortSignal?.();
+      uploadedUrls = await runUpload(overlaySignal ?? null);
     } else {
       uploadedUrls = await withSimpleUploadOverlay(signal => runUpload(signal));
     }

+ 5 - 5
src/components/Upload/Img.vue

@@ -174,11 +174,11 @@ const uploadSuccess = () => {
  * @description 图片上传错误
  * */
 const uploadError = () => {
-  ElNotification({
-    title: "温馨提示",
-    message: "图片上传失败,请您重新上传!",
-    type: "error"
-  });
+  // ElNotification({
+  //   title: "温馨提示",
+  //   message: "图片上传失败,请您重新上传!",
+  //   type: "error"
+  // });
 };
 </script>
 

+ 5 - 5
src/components/Upload/Imgs.vue

@@ -404,11 +404,11 @@ const handleImageLoad = (event: Event) => {
  * @description 图片上传错误
  * */
 const uploadError = () => {
-  ElNotification({
-    title: "温馨提示",
-    message: "上传失败,请您重新上传!",
-    type: "error"
-  });
+  // ElNotification({
+  //   title: "温馨提示",
+  //   message: "上传失败,请您重新上传!",
+  //   type: "error"
+  // });
 };
 
 /**

+ 1 - 2
src/components/popupLoading/index.vue

@@ -67,7 +67,7 @@ const props = defineProps({
   }
 });
 
-const emit = defineEmits(["cancel", "update:show"]);
+const emit = defineEmits(["cancel"]);
 
 const displayPercent = computed(() => {
   const n = Number(props.percent);
@@ -95,7 +95,6 @@ const dashOffset = computed(() => {
 
 function onCancel() {
   emit("cancel");
-  emit("update:show", false);
 }
 </script>
 

+ 9 - 1
src/stores/modules/simpleUploadOverlay.ts

@@ -1,5 +1,6 @@
 import { defineStore } from "pinia";
 import { ref } from "vue";
+import { ElMessage } from "element-plus";
 
 let progressTimer: ReturnType<typeof setInterval> | null = null;
 let activeController: AbortController | null = null;
@@ -47,6 +48,12 @@ export const useSimpleUploadOverlayStore = defineStore("simple-upload-overlay",
   function userCancel() {
     activeController?.abort();
     dismiss();
+    ElMessage.info("取消上传");
+  }
+
+  /** 供 skipSimpleUploadOverlay 的上传与 beginUpload 配套,把 fetch 绑到同一 AbortSignal */
+  function getActiveAbortSignal(): AbortSignal | undefined {
+    return activeController?.signal;
   }
 
   return {
@@ -57,6 +64,7 @@ export const useSimpleUploadOverlayStore = defineStore("simple-upload-overlay",
     beginUpload,
     bumpToComplete,
     dismiss,
-    userCancel
+    userCancel,
+    getActiveAbortSignal
   };
 });