new_shop_app/utils/uniMPevent.js

86 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2024-02-26 13:35:08 +08:00
const mp = uni.requireNativePlugin('uniMP');
import {
2024-04-02 16:37:05 +08:00
uniMPgetLocation,
test
2024-02-26 13:35:08 +08:00
} from "@/utils/uniMPfunction.js"
2024-04-24 18:00:36 +08:00
2024-04-29 23:05:04 +08:00
export const initEvent = (data) => {
2024-04-02 16:37:05 +08:00
mp.onUniMPEventReceive(async (ret) => {
2024-04-29 23:05:04 +08:00
console.log('小程序事件: ', data);
2024-04-02 16:37:05 +08:00
// 用户如果没有注册商户 从小程序返回 入驻页面
if (ret.event == 'closeAppToOpenShop') {
mp.closeUniMP(ret.fromAppid, (ret) => {
2024-04-02 18:41:12 +08:00
setTimeout(() => {
uni.navigateTo({
url: "/pages/store/settled/index"
})
}, 200)
2024-04-02 16:37:05 +08:00
});
}
2024-04-02 18:34:35 +08:00
// 关闭app
if (ret.event == 'backApp') {
mp.closeUniMP(ret.fromAppid, (ret) => {});
}
2024-04-02 16:37:05 +08:00
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
},
(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));
});
}
2024-04-29 23:05:04 +08:00
2024-04-02 16:37:05 +08:00
if (ret.event == 'log') {
// console.log('2222222')
console.log('收到小程序事件: ' + JSON.stringify(ret));
}
//直播小程序跳转商城购买商品
if (ret.event == 'live_shop') {
console.log(JSON.stringify(ret))
let arr1 = ret.data
mp.closeUniMP(ret.fromAppid, (ret) => {
// console.log('closeUniMP: ' + JSON.stringify(ret));
setTimeout(() => {
uni.navigateTo({
url: '/pages/goods_details/index?id=' + arr1
.app_goods_id
}, 1000)
})
});
// console.log('收到小程序事件: ' + JSON.stringify(ret));
}
});
2024-02-26 13:35:08 +08:00
}