From 7c3ed839ac8923f9aa739e92920fdf6b470771bb Mon Sep 17 00:00:00 2001 From: fanfan Date: Tue, 21 Jan 2025 10:11:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods/detail.vue | 74 ++++++++++++++++++++++++++++++++++- pages/goods/seckillDetail.vue | 73 ++++++++++++++++++++++++++++++++++ pages/index/index.vue | 73 ---------------------------------- 3 files changed, 146 insertions(+), 74 deletions(-) diff --git a/pages/goods/detail.vue b/pages/goods/detail.vue index 0b445f8..5998379 100644 --- a/pages/goods/detail.vue +++ b/pages/goods/detail.vue @@ -489,6 +489,7 @@ import * as address from '@/api/address.js' import * as CartApi from '@/api/cart' import store from '@/store' + import QQMapWX from '@/utils/qqmap-wx-jssdk' export default { components: { SkuPopup, @@ -572,8 +573,8 @@ } }, onLoad(options) { - console.log(options) const that = this; + that.getAuthorize(); that.options = options; let result = uni.getStorageSync("addressResult") this.addressResult = result ? result.address_component : this.addressResult @@ -627,6 +628,77 @@ } }, 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() { // 商城客服设置 diff --git a/pages/goods/seckillDetail.vue b/pages/goods/seckillDetail.vue index bc37597..0d7deb6 100644 --- a/pages/goods/seckillDetail.vue +++ b/pages/goods/seckillDetail.vue @@ -426,6 +426,7 @@ import * as CartApi from '@/api/cart' import * as SharpGoodsApi from '@/api/sharp/goods' import store from '@/store' + import QQMapWX from '@/utils/qqmap-wx-jssdk' export default { components: { SkuPopup, @@ -512,6 +513,7 @@ onLoad(options) { const that = this; that.options = options; + that.getAuthorize(); let result = uni.getStorageSync("addressResult") this.addressResult = result ? result.address_component : this.addressResult this.isPre = options.isPre ? options.isPre : null @@ -539,6 +541,77 @@ } }, 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() { // 商城客服设置 diff --git a/pages/index/index.vue b/pages/index/index.vue index 0cbe499..16f5b1d 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -567,7 +567,6 @@ import * as Api from '@/api/goods' import * as activity from '@/api/activity' import * as newFunApi from '@/api/newFun' - import QQMapWX from '@/utils/qqmap-wx-jssdk' import styleColor from '../styleColor'; export default { data() { @@ -1170,77 +1169,6 @@ 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() { this.getTypeList() @@ -1250,7 +1178,6 @@ this.getServeList(); this.queryBannerList(); this.getStore(); - this.getAuthorize(); this.recommendPage = 1; this.recommendFinish = false; this.recommendLoadTitle = '';