gaoluyang
2026-06-24 712aa51536236d43e87273e4ce45ac5691dffad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<script lang="ts" setup>
import type { WxLocationProps } from './types';
 
import { computed, onMounted, ref } from 'vue';
 
import { IconifyIcon } from '..\..\..\..\packages\icons\src';
 
import { Col, message, Row } from 'ant-design-vue';
 
import { getTradeConfig } from '#/api/mall/trade/config';
 
/** 微信消息 - 定位 */
defineOptions({ name: 'WxLocation' });
 
const props = withDefaults(defineProps<WxLocationProps>(), {
  qqMapKey: '', // QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
});
 
const fetchedQqMapKey = ref('');
const resolvedQqMapKey = computed(
  () => props.qqMapKey || fetchedQqMapKey.value || '',
);
 
const mapUrl = computed(() => {
  return `https://map.qq.com/?type=marker&isopeninfowin=1&markertype=1&pointx=${props.locationY}&pointy=${props.locationX}&name=${props.label}&ref=yudao`;
});
 
const mapImageUrl = computed(() => {
  return `https://apis.map.qq.com/ws/staticmap/v2/?zoom=10&markers=color:blue|label:A|${props.locationX},${props.locationY}&key=${resolvedQqMapKey.value}&size=250*180`;
});
 
async function fetchQqMapKey() {
  try {
    const data = await getTradeConfig();
    fetchedQqMapKey.value = data.tencentLbsKey ?? '';
    if (!fetchedQqMapKey.value) {
      message.warning('请先配置腾讯位置服务密钥');
    }
  } catch {
    message.error('获取腾讯位置服务密钥失败');
  }
}
 
onMounted(async () => {
  if (!props.qqMapKey) {
    await fetchQqMapKey();
  }
});
 
defineExpose({
  locationX: props.locationX,
  locationY: props.locationY,
  label: props.label,
  qqMapKey: resolvedQqMapKey,
});
</script>
 
<template>
  <div>
    <a :href="mapUrl" target="_blank" class="text-primary">
      <Col>
        <Row>
          <img :src="mapImageUrl" alt="地图位置" />
        </Row>
        <Row class="mt-2">
          <IconifyIcon icon="lucide:map-pin" class="mr-1" />
          {{ label }}
        </Row>
      </Col>
    </a>
  </div>
</template>