43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const mp = uni.requireNativePlugin('uniMP');
|
|
import {
|
|
uniMPgetLocation,
|
|
test
|
|
} from "@/utils/uniMPfunction.js"
|
|
|
|
export const initEvent = () => {
|
|
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);
|
|
// mp.sendUniMPEvent(ret.fromAppid, 'getLocation', res, (e) => {
|
|
// console.log('发送成功', e);
|
|
// })
|
|
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));
|
|
});
|
|
}
|
|
});
|
|
} |