Quellcode durchsuchen

分享下载 图片增加loading

黄琪勇 vor 9 Monaten
Ursprung
Commit
5bd1419d76
1 geänderte Dateien mit 26 neuen und 29 gelöschten Zeilen
  1. 26 29
      src/views/creation/share-model/index.vue

+ 26 - 29
src/views/creation/share-model/index.vue

@@ -103,12 +103,9 @@ export default {
       clearTimeout(this._time)
     },
     async saveImg() {
-      this.$toast.loading({
-        message: "图片生成中...",
-        forbidClick: true,
-      });
       setTimeout(() => {
         this.saveLoading = false;
+        this.$toast.clear();
       }, 100);
       postMessage(
         {
@@ -165,33 +162,33 @@ export default {
         return;
       }
       this.saveLoading = true;
-      // 判断是否已经生成图片
-      if (this.image) {
-        if (type) {
-          this.onSaveWe(type);
-        } else {
+      if(type){
+        this.onSaveWe(type);
+      }else{
+        this.$toast.loading({
+          forbidClick: true,
+          message: "下载中",
+          duration:0
+        });
+        if (this.image) {
           this.saveImg();
-        }
-      } else {
-        const container = document.getElementById("shareContent");
-        html2canvas(container, {
-          allowTaint: true,
-          useCORS: true,
-          backgroundColor: null,
-        })
-          .then(async (canvas) => {
-            const url = canvas.toDataURL("image/png");
-            this.image = url;
-            if (type) {
-              this.onSaveWe(type);
-            } else {
-              this.saveImg();
-            }
+        } else {
+          const container = document.getElementById("shareContent");
+          html2canvas(container, {
+            allowTaint: true,
+            useCORS: true,
+            backgroundColor: null,
           })
-          .catch(() => {
-            this.toast.clear();
-            this.saveLoading = false;
-          });
+            .then(async (canvas) => {
+              const url = canvas.toDataURL("image/png");
+              this.image = url;
+                this.saveImg();
+            })
+            .catch(() => {
+              this.$toast.clear();
+              this.saveLoading = false;
+            });
+        }
       }
     },
     copyText(text) {