فهرست منبع

fix: 地图显示 location 标记

sheldon 2 روز پیش
والد
کامیت
cec742a8a0
3فایلهای تغییر یافته به همراه18 افزوده شده و 17 حذف شده
  1. 5 2
      src/components/component-list/components/address.ts
  2. 13 15
      src/components/widgets/widget-map/index.tsx
  3. BIN
      src/images/location.png

+ 5 - 2
src/components/component-list/components/address.ts

@@ -2,12 +2,14 @@ import { TComponentItem } from "@/types/agent";
 import { EComponentType } from "@/consts/enum";
 import { useComponentStore } from "@/store/componentStore";
 import Taro from "@tarojs/taro";
+import { useAgentStore } from "@/store/agentStore";
 
 // 编辑微官网地图组件
 
 export const useAddress = () => {
   const { setCurrentComponent, setInsertIndex, saveComponent } =
     useComponentStore();
+    const {agent, fetchAgent} = useAgentStore()
 
   const saveAddress = async (
     value: Taro.chooseLocation.SuccessCallbackResult,
@@ -44,10 +46,11 @@ export const useAddress = () => {
       address: value.address,
       latitude: value.latitude,
       longitude: value.longitude,
-      success(result: Taro.chooseLocation.SuccessCallbackResult) {
+      async success(result: Taro.chooseLocation.SuccessCallbackResult) {
         console.log(result);
 
-        saveAddress(result, c);
+        await saveAddress(result, c);
+        agent?.agentId && fetchAgent(agent?.agentId);
       },
     };
     Taro.chooseLocation(option);

+ 13 - 15
src/components/widgets/widget-map/index.tsx

@@ -1,6 +1,6 @@
 import { View, Map } from '@tarojs/components'
 import style from './index.module.less'
-import avatarDefault from "@/images/avatar-default.png";
+import locationImg from "@/images/location.png";
 import Taro from '@tarojs/taro';
 import { useState } from 'react';
 interface Props {
@@ -19,30 +19,28 @@ const Index: React.FC<Props> = ({children, latitude, longitude, name = '', addre
   const onError = (e)=> {
     console.log(e)
   }
-
    // 标记点配置
-   const [markers] = useState([
+   const markers = [
     {
       id: 1, // 必须唯一
       latitude: latitude,  // 纬度
       longitude: longitude, // 经度
-      iconPath: avatarDefault, // 本地图标路径
+      iconPath: locationImg, // 本地图标路径
       width: 30,  // 图标宽度(像素)
       height: 30, // 图标高度
       title: name, // 点击时显示的标题
+      callout: {
+        content: name,
+        color: '#333',
+        fontSize: 14,
+        borderRadius: 8,
+        bgColor: '#fff',
+        padding: 8,
+        display: 'ALWAYS', // 让 callout 始终显示
+      }
     }
-  ])
-
+  ]
 
-  // const handleClick = () => {
-  //   Taro.openLocation({
-  //     latitude,
-  //     longitude,
-  //     scale: 18,
-  //     name: name,
-  //     address: address,
-  //   })
-  // }
   return (
     <View className='flex flex-col gap-16 px-16'>
       <View className={`flex items-center gap-8`}>

BIN
src/images/location.png