Commit c961b4ef authored by 彭佳妮(贵阳日报)'s avatar 彭佳妮(贵阳日报)
parents 53bb941d e956c401
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
<view class="shop-map-phone"> <view class="shop-map-phone">
<image <image
mode="aspectFill" mode="aspectFill"
@click="selectMapApp" @click="openMapApp(shopInfo)"
class="img1" class="img1"
src="@/static/shop/map.png" src="@/static/shop/map.png"
></image> ></image>
...@@ -284,9 +284,7 @@ import { ...@@ -284,9 +284,7 @@ import {
addImgUrlPrefixToImages, addImgUrlPrefixToImages,
getDistance, getDistance,
addImgUrlPrefix, addImgUrlPrefix,
openAmap, navigationSelect,
openBaiduMap,
openTencentMap,
} from '@/utils/common'; } from '@/utils/common';
const imgUrl = import.meta.env.VITE_APP_IMG_URL; const imgUrl = import.meta.env.VITE_APP_IMG_URL;
const current = ref(0); const current = ref(0);
...@@ -403,26 +401,31 @@ function getLocationFn() { ...@@ -403,26 +401,31 @@ function getLocationFn() {
/** /**
* 跳转地图 * 跳转地图
*/ */
function selectMapApp() {
xma.showActionSheet({ function openMapApp(info) {
itemList: ['高德地图', '百度地图', '腾讯地图'], console.log('info', info);
uni.showActionSheet({
itemList: ['高德地图', '百度地图'],
success: (res) => { success: (res) => {
const latitude = 39.90960456049752; // 示例纬度 const item = {
const longitude = 116.3972282409668; // 示例经度 shopAddress: info.shopAddress,
const name = '测试'; // 目标地点名称 latitude: info.location.lat,
longitude: info.location.lon,
name: '',
};
console.log('item', item);
switch (res.tapIndex) { switch (res.tapIndex) {
case 0: case 0:
// 打开高德地图 // 打开高德地图
openAmap(latitude, longitude, name); item.name = '高德地图';
navigationSelect(item);
break; break;
case 1: case 1:
item.name = '百度地图';
// 打开百度地图 // 打开百度地图
openBaiduMap(latitude, longitude); navigationSelect(item);
break;
case 2:
// 打开腾讯地图
openTencentMap(latitude, longitude, name);
break; break;
default: default:
break; break;
......
...@@ -73,30 +73,55 @@ export function debounce(func, wait) { ...@@ -73,30 +73,55 @@ export function debounce(func, wait) {
}, wait); }, wait);
}; };
} }
/**
* 跳转地图
* @param {*} param0
*/
export function navigationSelect(item) {
console.log(item);
const { osName } = uni.getSystemInfoSync();
const { name, latitude, longitude, shopAddress } = item;
const to = {
name: shopAddress,
longitude,
latitude,
};
const getMapScheme = (to) => {
const u = navigator.userAgent;
const isAndroid = osName === 'android';
export function openMapApp(url, packageName, appName) { const andriodBaidu = (to) => {
plus.runtime.openURL(url, function (e) { return `bdapp://map/direction?destination=name:${to.name}|latlng:${to.latitude},${to.longitude}&coord_type=gcj02&mode=driving&src=andr.jianghu.jianhao`;
xma.showModal({ };
title: '提示',
content: `${appName} 未安装,是否前往应用市场下载?`,
success: function (res) {
if (res.confirm) {
plus.runtime.openURL(`market://details?id=${packageName}`);
}
},
});
});
}
export function openAmap(latitude, longitude, name) { const iOSBaidu = (to) => {
const url = `amapuri://poi?sourceApplication=uniapp&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`; return `baidumap://map/direction?destination=name:${to.name}|latlng:${to.latitude},${to.longitude}&coord_type=gcj02&mode=driving&src=ios.jianghu.jianhao`;
openMapApp(url, 'com.autonavi.minimap', '高德地图'); };
}
export function openBaiduMap(latitude, longitude) { const andriodGaode = (to) => {
const url = `baidumap://map/geocoder?location=${latitude},${longitude}`; return `amapuri://route/plan/?sourceApplication=mhc&dlat=${to.latitude}&dlon=${to.longitude}&dname=${to.name}&dev=0&t=0`;
openMapApp(url, 'com.baidu.BaiduMap', '百度地图'); };
}
export function openTencentMap(latitude, longitude, name) { const iOSGaode = (to) => {
const url = `qqmap://map/marker?marker=coord:${latitude},${longitude};title:${name}&referer=uniapp`; return `iosamap://path?sourceApplication=mhc&dlat=${to.latitude}&dlon=${to.longitude}&dname=${to.name}&dev=0&t=0`;
openMapApp(url, 'com.tencent.map', '腾讯地图'); };
if (item.name === '百度地图') {
if (isAndroid) {
return andriodBaidu(to);
} else {
return iOSBaidu(to);
}
} else if (item.name === '高德地图') {
if (isAndroid) {
return andriodGaode(to);
} else {
return iOSGaode(to);
}
}
};
const a = document.createElement('a');
document.body.appendChild(a);
a.href = getMapScheme(to);
a.click();
href.value = getMapScheme(to);
} }
...@@ -41,7 +41,7 @@ export default defineConfig({ ...@@ -41,7 +41,7 @@ export default defineConfig({
// 代理配置 // 代理配置
proxy: { proxy: {
'/api': { '/api': {
target: 'http://test.rhhzkj.com:8080', target: 'http://192.168.0.147:9999',
changeOrigin: true, changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''), rewrite: (path) => path.replace(/^\/api/, ''),
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment