From f19e5267cc23b1c714dc746239864f33ed715dd9 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 05 十二月 2025 17:55:02 +0800
Subject: [PATCH] 完成地图制作任务功能初版

---
 src/components/map/SceneMap.vue |  379 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 260 insertions(+), 119 deletions(-)

diff --git a/src/components/map/SceneMap.vue b/src/components/map/SceneMap.vue
index 42dede6..bcb2076 100644
--- a/src/components/map/SceneMap.vue
+++ b/src/components/map/SceneMap.vue
@@ -1,7 +1,7 @@
 <template>
   <BaseMap></BaseMap>
   <div class="wrap p-events-none">
-    <el-row class="p-events-none">
+    <el-row class="p-events-none top-left-wrap">
       <FYOptionScene
         class="p-events-auto"
         label=""
@@ -14,67 +14,95 @@
       </div>
     </el-row>
     <el-row
-      class="p-events-none left-wrap"
-      align="bottom"
+      class="p-events-none bottom-left-wrap"
+      align="middle"
       :style="leftCardWrapStyle"
     >
-      <div
-        ref="refLeftCard"
-        v-show="leftCardShow"
-        class="card-left p-events-auto"
-      >
-        <div><el-text size="large">鍦烘櫙鍒楄〃</el-text></div>
-        <el-scrollbar height="400px" class="scrollbar">
-          <el-row
-            v-for="s in selectedSceneList"
-            :key="s.guid"
-            justify="space-between"
-            class="p-v-4 scene-item"
-          >
-            <el-text truncated style="width: 250px">
-              {{ s.index + '銆�' + s.name }}
-            </el-text>
-            <el-space>
-              <el-icon
-                :color="
-                  s._checked ? 'rgb(121, 187, 255)' : 'rgb(200, 201, 204)'
-                "
-                @click="locateTo(s)"
-              >
-                <LocationInformation />
-              </el-icon>
-              <el-icon
-                class="cursor-p"
-                :color="
-                  s._visible ? 'rgb(121, 187, 255)' : 'rgb(200, 201, 204)'
-                "
-                @click="handleVisibleChange(s)"
-              >
-                <View />
-              </el-icon>
-            </el-space>
+      <div class="card-left" ref="refLeftCard">
+        <div v-show="leftCardShow" class="p-events-auto">
+          <el-row ref="refLeftCardTitle" class="p-8" justify="space-between">
+            <el-text size="large">鍦烘櫙鍒楄〃</el-text>
+            <el-input
+              v-model="filterText"
+              icon="Search"
+              style="width: 250px"
+              placeholder="杈撳叆鍏抽敭瀛楋紝鎸夊洖杞﹂敭鎼滅储"
+              clearable
+            />
+            <!-- <el-badge
+              ref="sampleBadgeRef"
+              :value="1"
+              type="success"
+              :offset="[-2, 2]"
+            >
+              <img
+                style="width: 30px; height: 30px"
+                :src="sceneIcon(1)"
+                alt="宸ュ湴"
+              />
+              <template #content="{ value }">
+                <div class="custom-content">
+                  <el-icon :size="8"><Select /></el-icon>
+                </div>
+              </template>
+            </el-badge> -->
           </el-row>
-        </el-scrollbar>
+          <el-scrollbar :height="scrollHeight" class="scrollbar">
+            <el-row
+              v-for="s in filteredSceneList"
+              :key="s.guid"
+              justify="space-between"
+              class="p-v-4 scene-item"
+            >
+              <el-text truncated style="width: 100%">
+                {{ s.index + '. ' + s.name }}
+              </el-text>
+              <el-row justify="space-between" style="margin-top: 4px">
+                <el-space>
+                  <el-tag type="info" effect="plain" size="small">
+                    {{ s.type }}
+                  </el-tag>
+                  <el-tag
+                    :type="s.extension1 == '0' ? 'info' : 'success'"
+                    size="small"
+                  >
+                    {{ onlineFormat(s.extension1) }}
+                  </el-tag>
+                </el-space>
+              </el-row>
+              <el-space>
+                <el-icon
+                  class="cursor-p"
+                  :color="
+                    s._checked ? 'rgb(121, 187, 255)' : 'rgb(200, 201, 204)'
+                  "
+                  @click="locateTo(s)"
+                >
+                  <LocationInformation />
+                </el-icon>
+                <el-icon
+                  class="cursor-p"
+                  :color="
+                    s._visible ? 'rgb(121, 187, 255)' : 'rgb(200, 201, 204)'
+                  "
+                  @click="handleVisibleChange(s)"
+                >
+                  <View />
+                </el-icon>
+              </el-space>
+            </el-row>
+          </el-scrollbar>
+        </div>
       </div>
       <el-button
         class="close-btn-right p-events-auto"
-        type="primary"
-        plain
+        type="success"
         size="small"
         :icon="leftCardShow ? 'ArrowLeft' : 'ArrowRight'"
         @click="leftCardShow = !leftCardShow"
       ></el-button>
     </el-row>
   </div>
-
-  <!-- <el-row class="right-wrap">
-    <el-col :span="4">
-      <el-button>close</el-button>
-    </el-col>
-    <el-col :span="20">
-      
-    </el-col>
-  </el-row> -->
 </template>
 <script setup>
 import { ref, watch, computed, onMounted } from 'vue';
@@ -82,34 +110,88 @@
 import marks from '@/utils/map/marks';
 import mapUtil from '@/utils/map/util';
 import { sceneIcon } from '@/assets/scene-icon';
+
+const startHtml = `<div class="el-badge">`;
+const endHtml = `<sup
+      class="el-badge__content el-badge__content--success is-fixed"
+      style="margin-top: 2px; margin-right: 2px"
+    >
+      <div class="custom-content">
+        <i class="el-icon"  style="font-size: 8px">
+          <svg
+            xmlns="http://www.w3.org/2000/svg"
+            viewBox="0 0 1024 1024"
+          >
+            <path
+              fill="currentColor"
+              d="M77.248 415.04a64 64 0 0 1 90.496 0l226.304 226.304L846.528 188.8a64 64 0 1 1 90.56 90.496l-543.04 543.04-316.8-316.8a64 64 0 0 1 0-90.496"
+            ></path>
+          </svg>
+        </i>
+      </div>
+    </sup>
+  </div>`;
+//
+const markContentHtml = (sceneType, checked) => {
+  const imgHtml = `<img
+      style="width: 30px; height: 30px"
+      src="${sceneIcon(sceneType)}"
+    />`;
+  if (checked) {
+    return startHtml + imgHtml + endHtml;
+  } else {
+    return imgHtml;
+  }
+};
+
 const props = defineProps({
+  // 閫変腑鐨勫満鏅�
+  modelValue: {
+    type: Array,
+    default: () => []
+  },
   // 鍦烘櫙鐐逛綅淇℃伅
   data: Array
 });
 
+const emits = defineEmits(['update:modelValue']);
+
 onMounted(() => {
-  // refLeftCard.value.offsetHeight;
-  // leftCardWrapStyle.value = {
-  //   height: refLeftCard.value.offsetHeight + 'px'
-  // };
+  setTimeout(() => {
+    scrollHeight.value =
+      refLeftCard.value.offsetHeight -
+      refLeftCardTitle.value.offsetHeight +
+      'px';
+  }, 500);
 });
 
 const refLeftCard = ref();
+const refLeftCardTitle = ref();
+
 const leftCardShow = ref(true);
 const leftCardWrapStyle = ref();
+const scrollHeight = ref('400px');
 
 let allMarkViews = [];
 let markViewList = [];
 
 const scenetype = ref();
 
-const selectedSceneList = computed(() => {
-  return props.data.filter((v) => {
+// 閫変腑鐨勫満鏅�
+const selectedSceneList = ref(props.modelValue);
+
+const allSceneList = computed(() => props.data);
+const filterText = ref('');
+// 鏍规嵁鍦烘櫙绫诲瀷绛涢�夊満鏅垪琛�
+const filteredSceneList = computed(() => {
+  return allSceneList.value.filter((v) => {
     v._visible = true;
     return (
-      scenetype.value == undefined ||
-      scenetype.value.value == null ||
-      v.typeid + '' == scenetype.value.value
+      (scenetype.value == undefined ||
+        scenetype.value.value == null ||
+        v.typeid + '' == scenetype.value.value) &&
+      (v.name.indexOf(filterText.value) != -1 ||
+        v.index + '' == filterText.value)
     );
   });
 });
@@ -118,7 +200,6 @@
   () => props.data,
   (nV, oV) => {
     if (nV != oV) {
-      clearSceneMarks();
       createSceneMarks();
       filterMarkViews(true);
     }
@@ -128,10 +209,32 @@
 
 watch(scenetype, (nV, oV) => {
   if (nV != oV) {
-    clearSceneMarks();
     filterMarkViews(true);
   }
 });
+
+// 鐩戝惉澶栭儴閫変腑鎴栫Щ闄ゅ満鏅彉鍖�
+watch(
+  () => props.modelValue,
+  (nV, oV) => {
+    if (nV != oV) {
+      // 澶栭儴閫変腑鍦烘櫙鍙樺寲鏃讹紝鏇存柊鍐呴儴閫変腑鍦烘櫙鍒楄〃
+      selectedSceneList.value = nV;
+      // 澶栭儴閫変腑鍦烘櫙鍙樺寲鏃讹紝鏇存柊鍦板浘鏍囨敞鍐呭
+      allMarkViews.forEach((mv) => {
+        const scene = mv.getExtData();
+        const findOne = selectedSceneList.value.some((s) => {
+          return s.guid == scene.guid;
+        });
+        if (findOne) {
+          changeSceneMark(mv, true);
+        } else {
+          changeSceneMark(mv, false);
+        }
+      });
+    }
+  }
+);
 
 function handleVisibleChange(scene) {
   const mv = markViewList.find((v) => {
@@ -150,10 +253,12 @@
     return scene.guid == v.getExtData().guid;
   });
   if (mv) {
-    mapUtil.setFitView(mv);
+    // mapUtil.setFitView(mv);
+    mapUtil.setCenter(mv.getPosition());
   }
 }
 
+// 鍒涘缓鍦烘櫙鍦板浘鏍囨敞锛屾坊鍔犻紶鏍囦簨浠跺拰鐐瑰嚮浜嬩欢
 function createSceneMarks() {
   onMapMounted(() => {
     allMarkViews = [];
@@ -161,42 +266,16 @@
       // 鍒涘缓鍦烘櫙鍦板浘鏍囨敞
       const mark = marks.createMarker({
         position: [d.longitude, d.latitude],
-        img: sceneIcon(d.typeid),
-        label: '',
+        // img: sceneIcon(d.typeid),
+        content: markContentHtml(d.typeid),
+        label: d.index,
+        title: d.name,
         extData: d
       });
-      var timeout;
-      // 娣诲姞鐐瑰嚮浜嬩欢
-      mark.on('mouseover', (ev) => {
-        if (timeout) {
-          clearTimeout(timeout);
-        }
-        const _mark = ev.target;
-        const _extData = _mark.getExtData();
-        ev.target.setLabel({
-          content: _extData.name
-        });
-        timeout = setTimeout(() => {
-          ev.target.setLabel({
-            content: ''
-          });
-        }, 2000);
-        // if (_extData._show) {
-        //   ev.target.setLabel({
-        //     content: ''
-        //     // direction: 'bottom'
-        //   });
-        //   _extData._show = false;
-        //   ev.target.setExtData(_extData);
-        // } else {
-        //   ev.target.setLabel({
-        //     content: _extData.name
-        //     // direction: 'bottom'
-        //   });
-        //   _extData._show = true;
-        //   ev.target.setExtData(_extData);
-        // }
-      });
+      // 榧犳爣浜嬩欢
+      // onMouseOverListener(mark);
+      onClickListener(mark);
+
       allMarkViews.push(mark);
     });
   });
@@ -210,6 +289,7 @@
     if (markViewList.length > 0) {
       map.remove(markViewList);
     }
+    // 1. 绛涢�夊満鏅被鍨�
     if (scenetype.value == undefined) {
       markViewList = allMarkViews;
     } else {
@@ -220,32 +300,74 @@
         );
       });
     }
-    markViewList = markViewList.filter((v) => {
-      const _index = selectedSceneList.value.findIndex((s) => {
-        return s.guid == v.getExtData().guid && s._visible;
-      });
-      return _index != -1;
-    });
     map.add(markViewList);
     if (setFitView) {
       setTimeout(() => {
         map.setFitView(markViewList);
-        // const list = markViewList.map((v) => {
-        //   const _extData = v.getExtData();
-        //   return [_extData.longitude, _extData.latitude];
-        // });
-        // mapUtil.setBound(list);
       }, 1000);
     }
   });
 }
 
-function clearSceneMarks() {
-  onMapMounted(() => {
-    if (markViewList.length > 0) {
-      map.remove(markViewList);
+function onlineFormat(s) {
+  if (s == '0') {
+    return '涓嬬嚎';
+  } else {
+    return '涓婄嚎';
+  }
+}
+
+/** 鍦板浘鍦烘櫙鏍囪榧犳爣浜嬩欢 *********************************************/
+const onMouseOverListener = (mark) => {
+  let timeout;
+  // 娣诲姞鐐瑰嚮浜嬩欢
+  mark.on('mouseover', (ev) => {
+    if (timeout) {
+      clearTimeout(timeout);
     }
+    const _mark = ev.target;
+    const _extData = _mark.getExtData();
+    _mark.setLabel({
+      content: _extData.name
+    });
+    timeout = setTimeout(() => {
+      _mark.setLabel({
+        content: ''
+      });
+    }, 2000);
   });
+};
+const onClickListener = (mark) => {
+  mark.on('click', (ev) => {
+    const _mark = ev.target;
+    const extData = _mark.getExtData();
+    const index = selectedSceneList.value.indexOf(extData);
+    if (index == -1) {
+      selectedSceneList.value.push(extData);
+      changeSceneMark(_mark, true);
+    } else {
+      selectedSceneList.value.splice(index, 1);
+      changeSceneMark(_mark, false);
+    }
+    emits('update:modelValue', selectedSceneList.value);
+  });
+};
+/********************************************************************/
+
+/**
+ * 鏍规嵁閫変腑鐘舵�佷慨鏀瑰湴鍥炬爣璁扮殑鏍峰紡
+ * @param {AMap.Marker} mark 鍦板浘鏍囪
+ * @param checked
+ */
+function changeSceneMark(mark, checked) {
+  const scene = mark.getExtData();
+  if (checked && !scene._checked) {
+    scene._checked = true;
+    mark.setContent(markContentHtml(scene.typeid, true));
+  } else if (!checked && scene._checked) {
+    scene._checked = false;
+    mark.setContent(markContentHtml(scene.typeid, false));
+  }
 }
 </script>
 <style scoped>
@@ -256,28 +378,36 @@
   width: 100%;
   height: 100%;
 }
-.left-wrap {
+.top-left-wrap {
   position: absolute;
-  left: 0;
+  left: 0px;
+  top: 1px;
+}
+.bottom-left-wrap {
+  position: absolute;
+  left: 0px;
   bottom: 1px;
 }
 
 .card-left {
-  background-color: white;
-  /* border-radius: 4px; */
-  width: 316px;
-  /* box-shadow: var(--el-box-shadow); */
+  background-color: rgba(255, 255, 255, 0.8);
+  border-radius: 4px;
+  /* width: 350px; */
+  height: 50vh;
+  box-shadow: var(--el-box-shadow);
   z-index: 0;
+  /* padding: 8px; */
 }
 
 .scrollbar {
   padding-right: 8px;
-  /* width: 300px; */
+  width: 350px;
 }
 
 .close-btn-right {
-  margin-left: -3px;
+  /* margin-left: -3px; */
   height: 60px;
+  width: 20px;
 }
 
 .p-events-auto {
@@ -290,5 +420,16 @@
 
 .scene-item {
   /* background-color: aliceblue; */
+  padding: 8px;
+  border-radius: 8px;
+  border: 1px solid var(--el-border-color);
+  box-shadow: var(--el-box-shadow-lighter);
+  margin-bottom: 6px;
+}
+
+.custom-content {
+  display: flex;
+  align-items: center;
+  justify-content: center;
 }
 </style>

--
Gitblit v1.9.3