From 1bd03f5c2e7b9fa9cc80c4e673e18132da411333 Mon Sep 17 00:00:00 2001
From: jhzh <1628036192@qq.com>
Date: Wed, 12 Nov 2025 16:21:06 +0800
Subject: [PATCH] 1

---
 src/page/authentication/index.vue |   87 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 80 insertions(+), 7 deletions(-)

diff --git a/src/page/authentication/index.vue b/src/page/authentication/index.vue
index 4679065..92c7008 100644
--- a/src/page/authentication/index.vue
+++ b/src/page/authentication/index.vue
@@ -37,7 +37,7 @@
     <div class="form-group flex-between" :class="{ 'disabled': isSubmitting || isActive }">
       <label class="required-label">{{ $t('fsi1') }}</label>
 
-      <el-upload :with-credentials="true" class="avatar-uploader" :action="admin + 'user/upload.do'"
+      <el-upload :with-credentials="true" class="avatar-uploader" :action="admin + '/user/upload.do'"
         list-type="picture-card" name="upload_file" :show-file-list="false" :on-success="handleAvatarSuccess"
         :on-error="handleError" :before-upload="beforeAvatarUpload" :disabled="isActive">
         <img v-if="form.img1key" :src="form.img1key" class="id-img avatar" style="width: 100%; height: 100%" />
@@ -48,7 +48,7 @@
     <div class="form-group flex-between" :class="{ 'disabled': isSubmitting || isActive }">
       <label class="required-label">{{ $t('bsi1') }}</label>
 
-      <el-upload :with-credentials="true" class="avatar-uploader" :action="admin + 'user/upload.do'"
+      <el-upload :with-credentials="true" class="avatar-uploader" :action="admin + '/user/upload.do'"
         list-type="picture-card" name="upload_file" :show-file-list="false" :on-success="handleAvatarSuccess2"
         :on-error="handleError2" :before-upload="beforeAvatarUpload2" :disabled="isActive">
         <img v-if="form.img2key" :src="form.img2key" class="id-img avatar" style="width: 100%; height: 100%" />
@@ -89,6 +89,9 @@
         img2key: "",
       },
       imgStatus: false,
+      imgStatus2: false,
+      previousImg1key: '',
+      previousImg2key: '',
       admin: apiUrl.baseURL,
     }
   },
@@ -120,6 +123,15 @@
       } else if (!this.form.img2key) {
         Toast(this.$t("hj209"));
       } else {
+        // 验证图片地址是否为有效的网络地址
+        if (this.form.img1key && this.form.img1key.startsWith('blob:')) {
+          Toast('请等待图片上传完成');
+          return;
+        }
+        if (this.form.img2key && this.form.img2key.startsWith('blob:')) {
+          Toast('请等待图片上传完成');
+          return;
+        }
         // 显示确认弹窗
         this.toAuthentication();
       }
@@ -167,31 +179,92 @@
     },
     handleAvatarSuccess(res, file) {
       this.imgStatus = false;
-      this.form.img1key = res.data.url;
+      // 确保返回的是有效的网络图片地址,而不是临时 blob URL
+      if (res && res.data && res.data.url) {
+        // 验证 URL 是否为网络地址(不是 blob URL)
+        if (res.data.url.startsWith('http://') || res.data.url.startsWith('https://')) {
+          this.form.img1key = res.data.url;
+        } else {
+          // 如果返回的不是完整 URL,可能是相对路径,需要拼接 baseURL
+          this.form.img1key = this.admin.replace(/\/$/, '') + '/' + res.data.url.replace(/^\//, '');
+        }
+      } else {
+        // 如果响应格式不正确,恢复之前的值
+        if (this.previousImg1key) {
+          this.form.img1key = this.previousImg1key;
+        }
+        Toast(this.$t("hj209") || '图片上传失败,请重试');
+      }
     },
     beforeAvatarUpload(file) {
       this.imgStatus = true;
+      // 保存之前的图片地址,如果上传失败可以恢复
+      this.previousImg1key = this.form.img1key;
+      return true;
     },
     handleError() {
       this.imgStatus = false;
+      // 上传失败时,恢复之前的图片地址(如果有)
+      if (this.previousImg1key) {
+        this.form.img1key = this.previousImg1key;
+      } else {
+        // 如果没有之前的地址,清空并清理可能的临时 URL
+        if (this.form.img1key && this.form.img1key.startsWith('blob:')) {
+          URL.revokeObjectURL(this.form.img1key);
+          this.form.img1key = '';
+        }
+      }
+      Toast(this.$t("hj209") || '图片上传失败,请重试');
     },
     handleAvatarSuccess2(res, file) {
       this.imgStatus2 = false;
-      this.form.img2key = res.data.url; // URL.createObjectURL(file.raw);
+      // 确保返回的是有效的网络图片地址,而不是临时 blob URL
+      if (res && res.data && res.data.url) {
+        // 验证 URL 是否为网络地址(不是 blob URL)
+        if (res.data.url.startsWith('http://') || res.data.url.startsWith('https://')) {
+          this.form.img2key = res.data.url;
+        } else {
+          // 如果返回的不是完整 URL,可能是相对路径,需要拼接 baseURL
+          this.form.img2key = this.admin.replace(/\/$/, '') + '/' + res.data.url.replace(/^\//, '');
+        }
+      } else {
+        // 如果响应格式不正确,恢复之前的值
+        if (this.previousImg2key) {
+          this.form.img2key = this.previousImg2key;
+        }
+        Toast(this.$t("hj209") || '图片上传失败,请重试');
+      }
     },
     beforeAvatarUpload2(file) {
       this.imgStatus2 = true;
       const isLt10M = file.size / 1024 / 1024 < 10;
       if (!isLt10M) {
         this.$message.error(this.$t("hj205"));
+        this.imgStatus2 = false;
         return false;
-      } else {
-        this.form.img2key = URL.createObjectURL(file);
-        compress(file, function (val) { });
       }
+      // 保存之前的图片地址,如果上传失败可以恢复
+      this.previousImg2key = this.form.img2key;
+      // 不再设置临时 blob URL,等待上传成功后再设置
+      compress(file, function (val) { });
+      return true;
     },
     handleError2() {
       this.imgStatus2 = false;
+      // 上传失败时,恢复之前的图片地址(如果有)
+      if (this.previousImg2key) {
+        this.form.img2key = this.previousImg2key;
+      } else {
+        // 如果没有之前的地址,清空并清理可能的临时 URL
+        if (this.form.img2key && this.form.img2key.startsWith('blob:')) {
+          URL.revokeObjectURL(this.form.img2key);
+          this.form.img2key = '';
+        }
+      }
+      Toast(this.$t("hj209") || '图片上传失败,请重试');
+    },
+    goBack() {
+      this.$router.go(-1);
     },
   }
 }

--
Gitblit v1.9.3