2023-09-26 20:41:49 +08:00
|
|
|
const mp = uni.requireNativePlugin('uniMP');
|
|
|
|
import {
|
2023-10-07 19:06:57 +08:00
|
|
|
uniMPgetLocation,
|
|
|
|
test
|
2023-09-26 20:41:49 +08:00
|
|
|
} from "@/utils/uniMPfunction.js"
|
|
|
|
|
|
|
|
export const initEvent = () => {
|
2023-10-07 19:06:57 +08:00
|
|
|
mp.onUniMPEventReceive(async (ret) => {
|
|
|
|
console.log('小程序事件: ', ret);
|
|
|
|
if (ret.event == 'closeApp') {
|
|
|
|
mp.closeUniMP(ret.fromAppid, (ret) => {
|
|
|
|
console.log('closeUniMP: ' + JSON.stringify(ret));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (ret.event == 'getLocation') {
|
|
|
|
try {
|
|
|
|
console.log('获取定位');
|
|
|
|
let res = await uniMPgetLocation();
|
|
|
|
console.log(res);
|
|
|
|
// plus.geolocation.getCurrentPosition(function(position) {
|
|
|
|
// console.log('经度:' + position.coords.longitude);
|
|
|
|
// console.log('纬度:' + position.coords.latitude);
|
|
|
|
// // that.markers[1].latitude = position.coords.longitude;
|
|
|
|
// // that.markers[1].longitude = position.coords.longitude;
|
|
|
|
// mp.sendUniMPEvent(
|
|
|
|
// ret.fromAppid,
|
|
|
|
// 'getLocation', {...position.coords},
|
|
|
|
// (ret) => {
|
|
|
|
// console.log('Host sendEvent: ' + JSON.stringify(ret));
|
|
|
|
// });
|
|
|
|
// }, function(error) {
|
|
|
|
// console.error('获取位置失败:', error.message);
|
|
|
|
// }, {provider:'gps'});
|
|
|
|
mp.sendUniMPEvent(
|
|
|
|
ret.fromAppid,
|
|
|
|
'getLocation', {
|
|
|
|
...res
|
|
|
|
},
|
|
|
|
(ret) => {
|
|
|
|
console.log('Host sendEvent: ' + JSON.stringify(ret));
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret.event == 'test') {
|
|
|
|
console.log('测试');
|
|
|
|
mp.sendUniMPEvent(
|
|
|
|
ret.fromAppid,
|
|
|
|
'test', {
|
|
|
|
'key': 'value',
|
|
|
|
'name': 'data'
|
|
|
|
},
|
|
|
|
(ret) => {
|
|
|
|
console.log('Host sendEvent: ' + JSON.stringify(ret));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (ret.event == 'log') {
|
|
|
|
console.log('收到小程序事件: ' + JSON.stringify(ret));
|
|
|
|
}
|
|
|
|
});
|
2023-09-26 20:41:49 +08:00
|
|
|
}
|