Переглянути джерело

fix:修复注册页面连续上传图片没有被替换,不能回显的问题

yangyi 4 місяців тому
батько
коміт
b0eb9b8abc
2 змінених файлів з 14 додано та 3 видалено
  1. 8 1
      src/view/Login.vue
  2. 6 2
      src/view/Profile.vue

+ 8 - 1
src/view/Login.vue

@@ -108,8 +108,8 @@
                   v-model:file-list="cardFileList"
                   :auto-upload="false"
                   list-type="picture-card"
-                  :limit="1"
                   :on-preview="handlePreview"
+                  :on-change="onCardChange"
                 >
                   <el-icon><Plus /></el-icon>
                 </el-upload>
@@ -241,6 +241,13 @@ const handlePreview = (file: UploadFile) => {
   if (file.url) window.open(file.url)
 }
 
+const onCardChange = (_file: UploadFile, uploadFiles: UploadFile[]) => {
+  if (uploadFiles.length > 1) {
+    const last = uploadFiles[uploadFiles.length - 1]
+    cardFileList.value = [last]
+  }
+}
+
 const handleRegister = async () => {
   const valid = await registerFormRef.value?.validate().catch(() => false)
   if (!valid) return

+ 6 - 2
src/view/Profile.vue

@@ -77,7 +77,6 @@
             v-model:file-list="cardFileList"
             :auto-upload="false"
             list-type="picture-card"
-            :limit="1"
             :on-change="onCardChange"
             :before-upload="beforeCardUpload"
           >
@@ -137,7 +136,12 @@ const authStatusLabel = computed(() => {
   return map[userStore.state.authStatus] || userStore.state.authStatus
 })
 
-const onCardChange = (file: UploadFile) => {
+const onCardChange = (_file: UploadFile, uploadFiles: UploadFile[]) => {
+  if (uploadFiles.length > 1) {
+    const last = uploadFiles[uploadFiles.length - 1]
+    cardFileList.value = [last]
+  }
+  const file = uploadFiles.length > 1 ? uploadFiles[uploadFiles.length - 1] : _file
   if (file.raw) cardFile.value = file.raw as UploadRawFile
 }