From 55bd7fb6365909a0cbcf0957333c7876bd791bb9 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期四, 21 十一月 2024 16:35:12 +0800
Subject: [PATCH] 问题整改界面 1. 优化各项状态展示效果 2. 新增左侧关键字筛选功能

---
 src/components/FYImageSelectDialog.vue |  126 ++++++++++++++++++++++++++++++++---------
 1 files changed, 98 insertions(+), 28 deletions(-)

diff --git a/src/components/FYImageSelectDialog.vue b/src/components/FYImageSelectDialog.vue
index 8eb1bc6..e12c42f 100644
--- a/src/components/FYImageSelectDialog.vue
+++ b/src/components/FYImageSelectDialog.vue
@@ -1,8 +1,8 @@
 <template>
   <el-dialog
     :model-value="dialogVisible"
-    @opened="$emit('update:dialogVisible', true)"
-    @closed="$emit('update:dialogVisible', false)"
+    @opened="handleOpen"
+    @closed="handleClose"
     width="66%"
     destroy-on-close
   >
@@ -40,13 +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"
-            lazy
             @click="onSelect(img, i)"
+            @load="onOneImgLoadSuccess(img)"
+            @error="onOneImgLoadError(img)"
           />
         </el-scrollbar>
         <el-row v-else justify="space-between">
@@ -57,7 +59,7 @@
   </el-dialog>
 </template>
 <script setup>
-import { ref, watch } from 'vue';
+import { ref, watch, computed, onMounted, onUnmounted } from 'vue';
 
 const props = defineProps({
   dialogVisible: Boolean,
@@ -95,6 +97,34 @@
 // const typeImgMap = ref(new Map());
 const selectedImgUrlList = ref([]);
 
+let loadedImgCount = ref(0);
+// 鍔犺浇鐘舵��
+const loading = computed(() => {
+  if (activeId.value == '') {
+    return false;
+  }
+  // 淇濊瘉鏈�寮�濮嬫槸鍔犺浇鐘舵�侊紝涓夊垎涔嬩竴鍔犺浇涔嬪悗鍋滄灞曠ず鍔犺浇鐘舵��
+  return !(
+    props.typeImgMap.get(activeId.value).length / 3 <=
+    loadedImgCount.value
+  );
+});
+function onOneImgLoadError(img) {
+  img.loading = false
+  loadedImgCount.value++;
+}
+function onOneImgLoadSuccess(img) {
+  img.loading = false
+  loadedImgCount.value++;
+}
+watch(
+  () => activeId.value,
+  (nV, oV) => {
+    loadedImgCount.value = 0;
+  },
+  { immediate: true }
+);
+
 function onSelect(img, i) {
   if (props.readonly) {
     return;
@@ -121,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);
@@ -141,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);
-        }
-      });
-    });
-  },
-  { 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 {
@@ -175,12 +246,12 @@
 
 .main {
   margin: 0 auto; /* 浣跨埗鍏冪礌灞呬腑 */
-  height: 100%;
+  height: 72vh;
   width: 100%;
 }
 
 .imgs {
-  height: 50vh;
+  height: 60vh;
   width: 100%;
   min-height: 100px !important;
   /* border-style:solid;
@@ -251,7 +322,6 @@
 }
 
 ::v-deep .el-dialog__body {
-  height: 60vh;
   padding: 10px calc(var(--el-dialog-padding-primary) + 10px) !important;
 }
 </style>

--
Gitblit v1.9.3