From 87958d6d33603fa673cb7c8f5caf2394689959bf Mon Sep 17 00:00:00 2001
From: hcong <1050828145@qq.com>
Date: 星期四, 21 十一月 2024 11:00:43 +0800
Subject: [PATCH] 1. 图片选择组件移动到全局组件文件夹 2. 涉及到使用图片选择组件添加图片区域loading 3. 无用页面删除

---
 src/components/FYImageSelectDialog.vue |  103 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 72 insertions(+), 31 deletions(-)

diff --git a/src/components/FYImageSelectDialog.vue b/src/components/FYImageSelectDialog.vue
index 279ddca..6816f4c 100644
--- a/src/components/FYImageSelectDialog.vue
+++ b/src/components/FYImageSelectDialog.vue
@@ -1,9 +1,8 @@
 <template>
   <el-dialog
-    :title="title"
     :model-value="dialogVisible"
-    @opened="$emit('update:dialogVisible', true)"
-    @closed="$emit('update:dialogVisible', false)"
+    @opened="handleOpen"
+    @closed="handleClose"
     width="66%"
     destroy-on-close
   >
@@ -41,14 +40,15 @@
           class="imgs"
         >
           <el-image
+            v-loading="img.loading"
             v-for="(img, i) in typeImgMap.get(activeId)"
             :key="i"
             :class="[img.isSelect ? 'selected' : 'noActive', 'image']"
             fit="cover"
             :src="img.url"
             @click="onSelect(img, i)"
-            @load="onOneImgLoadSuccess"
-            @error="onOneImgLoadError"
+            @load="onOneImgLoadSuccess(img)"
+            @error="onOneImgLoadError(img)"
           />
         </el-scrollbar>
         <el-row v-else justify="space-between">
@@ -59,11 +59,9 @@
   </el-dialog>
 </template>
 <script setup>
-import { ref, watch, computed } from 'vue';
+import { ref, watch, computed, onMounted, onUnmounted } from 'vue';
 
 const props = defineProps({
-  // 鏍囬
-  title: String,
   dialogVisible: Boolean,
   /**
    * 鍥剧墖鍒嗙被
@@ -111,10 +109,12 @@
     loadedImgCount.value
   );
 });
-function onOneImgLoadError(e) {
+function onOneImgLoadError(img) {
+  img.loading = false
   loadedImgCount.value++;
 }
-function onOneImgLoadSuccess(e) {
+function onOneImgLoadSuccess(img) {
+  img.loading = false
   loadedImgCount.value++;
 }
 watch(
@@ -151,7 +151,28 @@
     img.isSelect = false;
   }
 }
-
+function handleOpen() {
+  // if (props.typeImgMap.get(activeId.value) == undefined) {
+  //     return;
+  //   }
+  //   props.typeImgMap.get(activeId.value).forEach((i) => {
+  //     if (i.isSelect == true) {
+  //       return;
+  //     }
+  //     props.defaultFile.forEach((imgItem) => {
+  //       if (imgItem.url == i.url) {
+  //         i.isSelect = true;
+  //         selectedImgUrlList.value.push(i);
+  //       }
+  //     });
+  //   });
+  emit('update:dialogVisible', true)
+}
+function handleClose() {
+  selectedImgUrlList.value.forEach(item => item.isSelect = false)
+  selectedImgUrlList.value = []
+  emit('update:dialogVisible', false)
+}
 function handleSubmit() {
   emit('submit', selectedImgUrlList.value);
   emit('update:dialogVisible', false);
@@ -171,27 +192,47 @@
   },
   { immediate: true }
 );
+// watch(
+//   () => props.defaultFile,
+//   (nV, oV) => {
+//     if (props.typeImgMap.get(activeId.value) == undefined) {
+//       return;
+//     }
+//     props.typeImgMap.get(activeId.value).forEach((i) => {
+//       if (i.isSelect == true) {
+//         return;
+//       }
+//       nV.forEach((imgItem) => {
+//         if (imgItem.url == i.url) {
+//           i.isSelect = true;
+//           selectedImgUrlList.value.push(i);
+//         }
+//       });
+//     });
+//   },
+//   { deep: true, immediate: true }
+// );
 
-watch(
-  () => props.typeImgMap,
-  (newMap, oldMap) => {
-    if (newMap.get(activeId.value) == undefined) {
-      return;
-    }
-    newMap.get(activeId.value).forEach((i) => {
-      if (i.isSelect == true) {
-        return;
-      }
-      props.defaultFile.forEach((imgItem) => {
-        if (imgItem.url == i.url) {
-          i.isSelect = true;
-          selectedImgUrlList.value.push(i);
-        }
-      });
-    });
-  },
-  { deep: true, immediate: true }
-);
+// watch(
+//   () => props.typeImgMap,
+//   (newMap, oldMap) => {
+//     if (newMap.get(activeId.value) == undefined) {
+//       return;
+//     }
+//     newMap.get(activeId.value).forEach((i) => {
+//       if (i.isSelect == true) {
+//         return;
+//       }
+//       props.defaultFile.forEach((imgItem) => {
+//         if (imgItem.url == i.url) {
+//           i.isSelect = true;
+//           selectedImgUrlList.value.push(i);
+//         }
+//       });
+//     });
+//   },
+//   { immediate: true }
+// );
 </script>
 <style scoped>
 .center {

--
Gitblit v1.9.3