diff --git a/src/main.js b/src/main.js index 9239d99..7cb8c42 100644 --- a/src/main.js +++ b/src/main.js @@ -12,7 +12,8 @@ import '@/plugins/vant' import '@/assets/css/index.less' // 移动端适配 import 'amfe-flexible' - +// 请求 +import http from "axios"; // icon import './assets/icons' import Android from '@/components/Android' @@ -25,11 +26,14 @@ import dayjs from 'dayjs' Vue.prototype.$dayjs = dayjs // 提示框封装 import { Tips } from '@/utils' +Vue.prototype.$http = http; Vue.prototype.$tips = Tips //开发环境使用,生产环境自动取消 import Vconsole from 'vconsole' import Perfect from '@/components/Perfect' +import axios from 'axios' +axios.defaults.baseURL = '/geocode' Vue.config.ignoredElements = ["wx-open-launch-weapp"]; Vue.component('Perfect', Perfect) if (process.env.NODE_ENV !== 'production') { diff --git a/src/views/communityPublicity/detail.vue b/src/views/communityPublicity/detail.vue index 5cf0139..6dab240 100644 --- a/src/views/communityPublicity/detail.vue +++ b/src/views/communityPublicity/detail.vue @@ -17,7 +17,7 @@
点赞{{ info.likes || 0 }}
diff --git a/src/views/selectAgency/index.vue b/src/views/selectAgency/index.vue index a4bf11d..f2c0793 100644 --- a/src/views/selectAgency/index.vue +++ b/src/views/selectAgency/index.vue @@ -34,7 +34,8 @@ export default { address: null, district: null, show:true, - autoFlag:true + autoFlag:true, + latLng:null }; }, created() { @@ -42,6 +43,9 @@ export default { mounted() { setConfig(['checkJsApi', 'openLocation', 'getLocation', 'updateAppMessageShareData', 'updateTimelineShareData']) this.signWX() + if(this.latLng){ + this.getAgency() + } }, methods: { restAddress() { @@ -66,8 +70,8 @@ export default { wx.getLocation({ type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' success: function (res) { - var latLng = new qq.maps.LatLng(res.latitude, res.longitude) - getAddr.getAddress(latLng) + _this.latLng = new qq.maps.LatLng(res.latitude, res.longitude) + _this.getAddress() }, cancel: function (res) { alert('用户拒绝授权获取地理位置') @@ -77,18 +81,19 @@ export default { wx.error(function (res) { console.log('微信js-sdk 配置失败000' + res.errMsg) }) - // 调取腾讯地图 - var getAddr = new qq.maps.Geocoder({ - complete: function (res) { - _this.address = res.detail - var allAddress = res.detail.addressComponents - var address = res.detail.address - console.log('地址:', address, allAddress.province, allAddress.city, allAddress.district) - _this.district = allAddress.district; - _this.getAgency(true) + }, + // 地址逆解析 + getAddress() { + this.$http.get(`https://restapi.amap.com/v3/geocode/regeo?location=${this.latLng.lng},${this.latLng.lat}&key=2af5c38e8d31470a87b4671829e01d1a&radius=1000&extensions=all`).then((res) => { + if (res.status == 200) { + this.district = res.data.regeocode.addressComponent.district; + this.getAgency(true) + } else{ + console.log(res); } }) }, + backAuto(){ if(this.autoFlag) return this.autoFlag = true; diff --git a/vue.config.js b/vue.config.js index 8732496..8ab1bc8 100644 --- a/vue.config.js +++ b/vue.config.js @@ -38,6 +38,15 @@ module.exports = defineConfig({ pathRewrite: { '^api': '' } + }, + '/geocode': { + target: `https://restapi.amap.com/v3`, + // target: `http://127.0.0.1:8080`, + changeOrigin: true, + ws: false, + pathRewrite: { + '/geocode': '/' + } } } },