定位移动

master
fanfan 2 weeks ago
parent 1f18377c37
commit 7c3ed839ac
  1. 74
      pages/goods/detail.vue
  2. 73
      pages/goods/seckillDetail.vue
  3. 73
      pages/index/index.vue

@ -489,6 +489,7 @@
import * as address from '@/api/address.js' import * as address from '@/api/address.js'
import * as CartApi from '@/api/cart' import * as CartApi from '@/api/cart'
import store from '@/store' import store from '@/store'
import QQMapWX from '@/utils/qqmap-wx-jssdk'
export default { export default {
components: { components: {
SkuPopup, SkuPopup,
@ -572,8 +573,8 @@
} }
}, },
onLoad(options) { onLoad(options) {
console.log(options)
const that = this; const that = this;
that.getAuthorize();
that.options = options; that.options = options;
let result = uni.getStorageSync("addressResult") let result = uni.getStorageSync("addressResult")
this.addressResult = result ? result.address_component : this.addressResult this.addressResult = result ? result.address_component : this.addressResult
@ -627,6 +628,77 @@
} }
}, },
methods: { methods: {
//
getAuthorize() {
const _this = this
// #ifdef MP-WEIXIN
uni.authorize({
scope: 'scope.userLocation', //
success(res) {
_this.getAdressLocation()
},
//
fail(err) {
uni.showModal({
title: '温馨提示',
content: '无法获取当前位置,请手动开启授权',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定')
uni.openSetting({
success(res) {
if (res.authSetting['scope.userLocation']) {
console.log('打开授权设置定位')
_this.getAdressLocation()
}
},
})
} else if (res.cancel) {
console.log('用户点击取消')
}
},
})
},
})
// #endif
// #ifndef MP-WEIXIN
_this.getAdressLocation()
// #endif
},
getAdressLocation() {
var that = this;
const tMap = new QQMapWX({
key: "ZDBBZ-QQX66-YVYSB-M56JB-FGSS5-EIBI4", //
});
uni.getLocation({
type: "gcj02",
geocode: true,
success: (res) => {
that.longitude = res.longitude;
that.latitude = res.latitude;
tMap.reverseGeocoder({
location: {
latitude: that.latitude,
longitude: that.longitude,
},
success: function(res) {
uni.setStorageSync("addressResult", res.result);
console.log("当前地址:", res.result);
},
fail: function(res) {
console.log("定位失败", res);
},
});
},
fail: () => {
console.log("获取经纬度失败");
},
complete: (e) => {
console.log(e);
}
});
},
// 线 // 线
handleContact() { handleContact() {
// //

@ -426,6 +426,7 @@
import * as CartApi from '@/api/cart' import * as CartApi from '@/api/cart'
import * as SharpGoodsApi from '@/api/sharp/goods' import * as SharpGoodsApi from '@/api/sharp/goods'
import store from '@/store' import store from '@/store'
import QQMapWX from '@/utils/qqmap-wx-jssdk'
export default { export default {
components: { components: {
SkuPopup, SkuPopup,
@ -512,6 +513,7 @@
onLoad(options) { onLoad(options) {
const that = this; const that = this;
that.options = options; that.options = options;
that.getAuthorize();
let result = uni.getStorageSync("addressResult") let result = uni.getStorageSync("addressResult")
this.addressResult = result ? result.address_component : this.addressResult this.addressResult = result ? result.address_component : this.addressResult
this.isPre = options.isPre ? options.isPre : null this.isPre = options.isPre ? options.isPre : null
@ -539,6 +541,77 @@
} }
}, },
methods: { methods: {
//
getAuthorize() {
const _this = this
// #ifdef MP-WEIXIN
uni.authorize({
scope: 'scope.userLocation', //
success(res) {
_this.getAdressLocation()
},
//
fail(err) {
uni.showModal({
title: '温馨提示',
content: '无法获取当前位置,请手动开启授权',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定')
uni.openSetting({
success(res) {
if (res.authSetting['scope.userLocation']) {
console.log('打开授权设置定位')
_this.getAdressLocation()
}
},
})
} else if (res.cancel) {
console.log('用户点击取消')
}
},
})
},
})
// #endif
// #ifndef MP-WEIXIN
_this.getAdressLocation()
// #endif
},
getAdressLocation() {
var that = this;
const tMap = new QQMapWX({
key: "ZDBBZ-QQX66-YVYSB-M56JB-FGSS5-EIBI4", //
});
uni.getLocation({
type: "gcj02",
geocode: true,
success: (res) => {
that.longitude = res.longitude;
that.latitude = res.latitude;
tMap.reverseGeocoder({
location: {
latitude: that.latitude,
longitude: that.longitude,
},
success: function(res) {
uni.setStorageSync("addressResult", res.result);
console.log("当前地址:", res.result);
},
fail: function(res) {
console.log("定位失败", res);
},
});
},
fail: () => {
console.log("获取经纬度失败");
},
complete: (e) => {
console.log(e);
}
});
},
// 线 // 线
handleContact() { handleContact() {
// //

@ -567,7 +567,6 @@
import * as Api from '@/api/goods' import * as Api from '@/api/goods'
import * as activity from '@/api/activity' import * as activity from '@/api/activity'
import * as newFunApi from '@/api/newFun' import * as newFunApi from '@/api/newFun'
import QQMapWX from '@/utils/qqmap-wx-jssdk'
import styleColor from '../styleColor'; import styleColor from '../styleColor';
export default { export default {
data() { data() {
@ -1170,77 +1169,6 @@
scrollTop: 0 scrollTop: 0
}) })
}, },
//
getAuthorize() {
const _this = this
// #ifdef MP-WEIXIN
uni.authorize({
scope: 'scope.userLocation', //
success(res) {
_this.getAdressLocation()
},
//
fail(err) {
uni.showModal({
title: '温馨提示',
content: '无法获取当前位置,请手动开启授权',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定')
uni.openSetting({
success(res) {
if (res.authSetting['scope.userLocation']) {
console.log('打开授权设置定位')
_this.getAdressLocation()
}
},
})
} else if (res.cancel) {
console.log('用户点击取消')
}
},
})
},
})
// #endif
// #ifndef MP-WEIXIN
_this.getAdressLocation()
// #endif
},
getAdressLocation() {
var that = this;
const tMap = new QQMapWX({
key: "ZDBBZ-QQX66-YVYSB-M56JB-FGSS5-EIBI4", //
});
uni.getLocation({
type: "gcj02",
geocode: true,
success: (res) => {
that.longitude = res.longitude;
that.latitude = res.latitude;
tMap.reverseGeocoder({
location: {
latitude: that.latitude,
longitude: that.longitude,
},
success: function(res) {
uni.setStorageSync("addressResult", res.result);
console.log("当前地址:", res.result);
},
fail: function(res) {
console.log("定位失败", res);
},
});
},
fail: () => {
console.log("获取经纬度失败");
},
complete: (e) => {
console.log(e);
}
});
},
}, },
onLoad() { onLoad() {
this.getTypeList() this.getTypeList()
@ -1250,7 +1178,6 @@
this.getServeList(); this.getServeList();
this.queryBannerList(); this.queryBannerList();
this.getStore(); this.getStore();
this.getAuthorize();
this.recommendPage = 1; this.recommendPage = 1;
this.recommendFinish = false; this.recommendFinish = false;
this.recommendLoadTitle = ''; this.recommendLoadTitle = '';

Loading…
Cancel
Save