fix: resolve todo
This commit is contained in:
@@ -1,33 +1,57 @@
|
||||
<script lang="ts" setup>
|
||||
import type { WxLocationProps } from './types';
|
||||
|
||||
import { computed } from 'vue';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Col, Row } from 'ant-design-vue';
|
||||
import { Col, message, Row } from 'ant-design-vue';
|
||||
|
||||
import { getTradeConfig } from '#/api/mall/trade/config';
|
||||
|
||||
/** 微信消息 - 定位 */
|
||||
defineOptions({ name: 'WxLocation' });
|
||||
|
||||
// TODO @dylan:apps/web-antd/src/views/mall/trade/delivery/pickUpStore/modules/form.vue 参考这个,从后端拿 key 哈;参考 apps/web-ele/src/views/mp/components/wx-location/wx-location.vue
|
||||
const props = withDefaults(defineProps<WxLocationProps>(), {
|
||||
qqMapKey: 'TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E', // QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
|
||||
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=${props.qqMapKey}&size=250*180`;
|
||||
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: props.qqMapKey,
|
||||
qqMapKey: resolvedQqMapKey,
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user