diff --git a/App.vue b/App.vue index b5bfc38..e273265 100644 --- a/App.vue +++ b/App.vue @@ -10,7 +10,7 @@ // +---------------------------------------------------------------------- // #ifdef APP-PLUS let jpushModule = uni.requireNativePlugin("JG-JPush"); - const mp = uni.requireNativePlugin('uniMP'); + import { initEvent } from "@/utils/uniMPevent.js"; // #endif import { checkLogin @@ -86,17 +86,24 @@ } // #ifdef APP-PLUS - //监听uni小程序发送的事件 - mp.onUniMPEventReceive(ret => { - console.log('小程序事件: ', ret); - if (ret.event == 'closeApp') { - mp.closeUniMP(ret.fromAppid, (ret) => { - console.log('closeUniMP: ' + JSON.stringify(ret)); - }); - } - }); + //初始化uniMP小程序发送的事件以及其他操作 + initEvent(); // #endif + // uni.getLocation({ + // type: 'gcj02', + // geocode: true, + // isHighAccuracy: true, + // // altitude: true, + // // accuracy: 'best', + // success: (res)=> { + // console.log(res); + // }, + // fail(e) { + // console.log(e); + // } + // }); + let that = this; // #ifdef MP if (HTTP_REQUEST_URL == '') { diff --git a/manifest.json b/manifest.json index c61eaac..d51d063 100644 --- a/manifest.json +++ b/manifest.json @@ -95,8 +95,8 @@ "sdkConfigs" : { "maps" : { "amap" : { - "appkey_ios" : "048d9f3f323eea894b49c3a7edbc8d87", - "appkey_android" : "048d9f3f323eea894b49c3a7edbc8d87" + "appkey_ios" : "82af93ec51139c712c4118d84ba684ee", + "appkey_android" : "0799f37420c0784f1e6cba230a68bdb1" } }, "payment" : { @@ -113,8 +113,10 @@ } }, "geolocation" : { - "system" : { - "__platform__" : [ "ios", "android" ] + "amap" : { + "__platform__" : [ "ios", "android" ], + "appkey_ios" : "82af93ec51139c712c4118d84ba684ee", + "appkey_android" : "0799f37420c0784f1e6cba230a68bdb1" } }, "oauth" : {}, diff --git a/utils/uniMPevent.js b/utils/uniMPevent.js new file mode 100644 index 0000000..19262b2 --- /dev/null +++ b/utils/uniMPevent.js @@ -0,0 +1,54 @@ +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); + // 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)); + }); + } + }); +} \ No newline at end of file diff --git a/utils/uniMPfunction.js b/utils/uniMPfunction.js new file mode 100644 index 0000000..3d207f1 --- /dev/null +++ b/utils/uniMPfunction.js @@ -0,0 +1,21 @@ +export const test = () => { + return '测试' +} + +export const uniMPgetLocation = () => { + return new Promise((resolve, reject) => { + uni.getLocation({ + type: 'gcj02', + geocode: true, + isHighAccuracy: true, + // altitude: true, + // accuracy: 'best', + success: (res) => { + resolve(res) + }, + fail(e) { + resolve(e) + } + }); + }) +} \ No newline at end of file