From 902224ebf1f1709d4d394970b51081856cf41da0 Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Wed, 20 Sep 2023 20:11:10 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 13 +++---------- utils/uniMPevent.js | 43 ++++++++++++++++++++++++++++++++++++++++++ utils/uniMPfunction.js | 20 ++++++++++++++++++++ 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 utils/uniMPevent.js create mode 100644 utils/uniMPfunction.js diff --git a/App.vue b/App.vue index 3fe566e..3ec68f2 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 @@ -87,15 +87,8 @@ // #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 let that = this; diff --git a/utils/uniMPevent.js b/utils/uniMPevent.js new file mode 100644 index 0000000..eea9892 --- /dev/null +++ b/utils/uniMPevent.js @@ -0,0 +1,43 @@ +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)); + }); + } + }); +} \ No newline at end of file diff --git a/utils/uniMPfunction.js b/utils/uniMPfunction.js new file mode 100644 index 0000000..cdce7d1 --- /dev/null +++ b/utils/uniMPfunction.js @@ -0,0 +1,20 @@ + +export const test = ()=>{ + return '测试' +} + +export const uniMPgetLocation = ()=>{ + return new Promise((resolve, reject)=>{ + uni.getLocation({ + type: 'gcj02', + geocode: true, + isHighAccuracy: true, + success: (res)=> { + resolve(res) + }, + fail(e) { + reject(e) + } + }); + }) +} \ No newline at end of file From d70f6c6f8a5fb7454eb0a290f853178dc9ac80c2 Mon Sep 17 00:00:00 2001 From: wpf <2187978347@qq.com> Date: Wed, 20 Sep 2023 23:11:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 14 ++++++++++++++ utils/uniMPevent.js | 17 ++++++++++++++--- utils/uniMPfunction.js | 14 ++++++++------ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/App.vue b/App.vue index 3ec68f2..842c470 100644 --- a/App.vue +++ b/App.vue @@ -91,6 +91,20 @@ 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/utils/uniMPevent.js b/utils/uniMPevent.js index eea9892..19262b2 100644 --- a/utils/uniMPevent.js +++ b/utils/uniMPevent.js @@ -17,9 +17,20 @@ export const initEvent = () => { console.log('获取定位'); let res = await uniMPgetLocation(); console.log(res); - // mp.sendUniMPEvent(ret.fromAppid, 'getLocation', res, (e) => { - // console.log('发送成功', e); - // }) + // 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}, diff --git a/utils/uniMPfunction.js b/utils/uniMPfunction.js index cdce7d1..32184bc 100644 --- a/utils/uniMPfunction.js +++ b/utils/uniMPfunction.js @@ -6,15 +6,17 @@ export const test = ()=>{ export const uniMPgetLocation = ()=>{ return new Promise((resolve, reject)=>{ uni.getLocation({ - type: 'gcj02', - geocode: true, - isHighAccuracy: true, + // type: 'gcj02', + // geocode: true, + // isHighAccuracy: true, + // altitude: true, + accuracy: 'best', success: (res)=> { resolve(res) }, - fail(e) { - reject(e) - } + fail(e) { + reject(e) + } }); }) } \ No newline at end of file From 9bdb627cf2f68b159955a28a77cf0f073ee20322 Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Thu, 21 Sep 2023 11:59:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 26 +++++++++++++------------- manifest.json | 10 ++++++---- utils/uniMPfunction.js | 29 ++++++++++++++--------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/App.vue b/App.vue index 842c470..09c5f38 100644 --- a/App.vue +++ b/App.vue @@ -91,19 +91,19 @@ initEvent(); // #endif - uni.getLocation({ - // type: 'gcj02', - // geocode: true, - // isHighAccuracy: true, - // altitude: true, - accuracy: 'best', - success: (res)=> { - console.log(res); - }, - fail(e) { - console.log(e); - } - }); + // 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 diff --git a/manifest.json b/manifest.json index 0712ed8..b571c8e 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/uniMPfunction.js b/utils/uniMPfunction.js index 32184bc..3d207f1 100644 --- a/utils/uniMPfunction.js +++ b/utils/uniMPfunction.js @@ -1,22 +1,21 @@ - -export const test = ()=>{ +export const test = () => { return '测试' } -export const uniMPgetLocation = ()=>{ - return new Promise((resolve, reject)=>{ +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) { - reject(e) - } + type: 'gcj02', + geocode: true, + isHighAccuracy: true, + // altitude: true, + // accuracy: 'best', + success: (res) => { + resolve(res) + }, + fail(e) { + resolve(e) + } }); }) } \ No newline at end of file