!70 【代码优化】门店自提:h5 位置信息相关逻辑

Merge pull request !70 from puhui999/master
pull/69/MERGE
芋道源码 2024-08-08 04:56:46 +00:00 committed by Gitee
commit 2b5a06174f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 59 additions and 58 deletions

View File

@ -32,7 +32,7 @@
</view> </view>
<!-- #endif --> <!-- #endif -->
</view> </view>
<view class="store-distance ss-flex ss-row-center" @tap="showMaoLocation(item)"> <view class="store-distance ss-flex ss-row-center" @tap.stop="showMaoLocation(item)">
<text class="addressTxt" v-if="item.distance">{{ item.distance.toFixed(2) }}</text> <text class="addressTxt" v-if="item.distance">{{ item.distance.toFixed(2) }}</text>
<text class="addressTxt" v-else></text> <text class="addressTxt" v-else></text>
<view class="iconfont"> <view class="iconfont">
@ -55,13 +55,11 @@
const LONGITUDE = 'user_longitude'; const LONGITUDE = 'user_longitude';
const LATITUDE = 'user_latitude'; const LATITUDE = 'user_latitude';
const MAPKEY = 'mapKey';
const state = reactive({ const state = reactive({
loaded: false, loaded: false,
loading: false, loading: false,
storeList: [], storeList: [],
system_store: {}, system_store: {},
// mapKey: cookie.get(MAPKEY),
locationShow: false, locationShow: false,
user_latitude: 0, user_latitude: 0,
user_longitude: 0, user_longitude: 0,
@ -73,61 +71,62 @@
}); });
}; };
const selfLocation = () => { const selfLocation = () => {
// TODO h5
// #ifdef H5 // #ifdef H5
// if (state.$wechat.isWeixin()) { const jsWxSdk = sheep.$platform.useProvider('wechat').jsWxSdk;
// state.$wechat.location().then(res => { if (jsWxSdk.isWechat()) {
// state.user_latitude = res.latitude; jsWxSdk.getLocation((res) => {
// state.user_longitude = res.longitude; console.log(res);
// uni.setStorageSync(LATITUDE, res.latitude); state.user_latitude = res.latitude;
// uni.setStorageSync(LONGITUDE, res.longitude); state.user_longitude = res.longitude;
// getList(); uni.setStorageSync(LATITUDE, res.latitude);
// }); uni.setStorageSync(LONGITUDE, res.longitude);
// } else {
// #endif
uni.getLocation({
type: 'gcj02',
success: (res) => {
try {
state.user_latitude = res.latitude;
state.user_longitude = res.longitude;
uni.setStorageSync(LATITUDE, res.latitude);
uni.setStorageSync(LONGITUDE, res.longitude);
} catch {
}
getList(); getList();
}, });
complete: () => { } else {
getList(); // #endif
}, uni.getLocation({
}); type: 'gcj02',
// #ifdef H5 success: (res) => {
// } try {
state.user_latitude = res.latitude;
state.user_longitude = res.longitude;
uni.setStorageSync(LATITUDE, res.latitude);
uni.setStorageSync(LONGITUDE, res.longitude);
} catch {
}
getList();
},
complete: () => {
getList();
},
});
// #ifdef H5
}
// #endif // #endif
}; };
const showMaoLocation = (e) => { const showMaoLocation = (e) => {
// TODO h5
// #ifdef H5 // #ifdef H5
// if (state.$wechat.isWeixin()) { const jsWxSdk = sheep.$platform.useProvider('wechat').jsWxSdk;
// state.$wechat.seeLocation({ if (jsWxSdk.isWechat()) {
// latitude: Number(e.latitude), jsWxSdk.openLocation({
// longitude: Number(e.longitude), latitude: Number(e.latitude),
// }).then(res => { longitude: Number(e.longitude),
// console.log('success'); name: e.name,
// }); address: `${e.areaName}-${e.detailAddress}`
// } else { });
// #endif } else {
uni.openLocation({ // #endif
latitude: Number(e.latitude), uni.openLocation({
longitude: Number(e.longitude), latitude: Number(e.latitude),
name: e.name, longitude: Number(e.longitude),
address: `${e.areaName}-${e.detailAddress}`, name: e.name,
success: function() { address: `${e.areaName}-${e.detailAddress}`,
console.log('success'); success: function() {
}, console.log('success');
}); },
// #ifdef H5 });
// } // #ifdef H5
}
// #endif // #endif
}; };

View File

@ -1,9 +1,10 @@
/** /**
* 本模块封装微信浏览器下的一些方法 * 本模块封装微信浏览器下的一些方法
* 更多微信网页开发sdk方法,详见:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html * 更多微信网页开发sdk方法,详见:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
* the permission value is offline verifying 报错请参考 @see https://segmentfault.com/a/1190000042289419 解决
*/ */
import jweixin, { ready } from 'weixin-js-sdk'; import jweixin from 'weixin-js-sdk';
import $helper from '@/sheep/helper'; import $helper from '@/sheep/helper';
import AuthUtil from '@/sheep/api/member/auth'; import AuthUtil from '@/sheep/api/member/auth';
@ -38,7 +39,7 @@ export default {
timestamp: data.timestamp, timestamp: data.timestamp,
nonceStr: data.nonceStr, nonceStr: data.nonceStr,
signature: data.signature, signature: data.signature,
jsApiList: ['chooseWXPay'], // TODO 芋艿:后续可以设置更多权限; jsApiList: ['chooseWXPay', 'openLocation', 'getLocation','updateTimelineShareData','scanQRCode'], // TODO 芋艿:后续可以设置更多权限;
openTagList: data.openTagList openTagList: data.openTagList
}); });
} }
@ -137,9 +138,10 @@ export default {
openLocation(data, callback) { openLocation(data, callback) {
this.isReady(() => { this.isReady(() => {
jweixin.openLocation({ jweixin.openLocation({
//根据传入的坐标打开地图 ...data,
latitude: data.latitude, success: function (res) {
longitude: data.longitude, console.log(res);
}
}); });
}); });
}, },

View File

@ -103,5 +103,5 @@ export default {
unbind, unbind,
getInfo, getInfo,
getOpenid, getOpenid,
jssdk: $wxsdk, jsWxSdk: $wxsdk,
}; };