From 1eab02047ea551d1893093a4fad308d1c9af2ced Mon Sep 17 00:00:00 2001 From: xiaozhiyong Date: Wed, 12 Apr 2023 11:08:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- src/store/piniaIndex.js | 35 ++++------------------ src/views/HomeView.vue | 65 +++++++++++++++-------------------------- vue.config.js | 4 +-- 4 files changed, 31 insertions(+), 75 deletions(-) diff --git a/.env.development b/.env.development index 8416491..f85a567 100644 --- a/.env.development +++ b/.env.development @@ -12,7 +12,7 @@ VUE_APP_UPLOAD_PRIVATE_URL = '/api/oil-dict/imageHandler/uploadProtectedImg' VUE_APP_DOMAIN = '192.168.0.150:38080' # 开发环境,不会进行加密,会打印出数据 -VUE_APP_ENV = 'production' +VUE_APP_ENV = 'development' #production diff --git a/src/store/piniaIndex.js b/src/store/piniaIndex.js index 2fa77d4..6be6362 100644 --- a/src/store/piniaIndex.js +++ b/src/store/piniaIndex.js @@ -27,37 +27,20 @@ const instance = defineStore('user', { actions: { getPosition() { - this.position = { latitude: 36.636753, longitude: 119.11914 } - - if (navigator?.geolocation?.getCurrentPosition) { - console.log('存在原生定位') - navigator.geolocation.getCurrentPosition(position => { - console.log('原生定位', position) - }) - } else { - console.log('原生定位不可用') - } - - // return initAMap().then(() => { - // console.log(3) let AMap = Vue.prototype.$AMap let geolocation = new AMap.Geolocation({ // enableHighAccuracy: true // 是否使用高精度定位,默认:true }) geolocation.getCurrentPosition(function (status, result) { - console.log('geolocation.getCurrentPosition') - console.log('status', status) - console.log('result', result) - // if (status === 'complete') { - // let { lat: latitude, lng: longitude } = result.position - // this.position = { latitude, longitude } - // console.log('this.position', this.position) - // } + if (status === 'complete') { + let { lat: latitude, lng: longitude } = result.position + this.position = { latitude, longitude } + } else { + } }) }) return - if (navigator?.geolocation?.getCurrentPosition) { navigator.geolocation.getCurrentPosition( position => { @@ -65,14 +48,6 @@ const instance = defineStore('user', { let { latitude, longitude } = position.coords this.position = { latitude, longitude } }, - // function (position) { - // console.log('position', position) - // // that.$patch(state => { - // // ;({ latitude: state.position.latitude, longitude: state.position.longitude } = position.coords) - // // localStorage.setItem('position', JSON.stringify(state.position)) - // // console.log(state.position, position.coords, '检测到地理位置授权') - // // }) - // }, error => { console.log('error', error) switch (error.code) { diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 8073a59..2c55c96 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -22,6 +22,8 @@ import oilSiteApi from '@/api/oil-site.js' import initAMap from '@/utils/amap.js' +import { Notify } from 'vant' + export default { components: { homeNavBar, @@ -125,9 +127,27 @@ export default { return !position?.latitude && !position?.longitude ? true : false }, getlist() { - let position = { latitude: 36.636753, longitude: 119.11914 } - - this.page.params = Object.assign(this.page.params, position) + if (this.position) { + this.obtainData() + return + } + initAMap().then(() => { + let AMap = this.$AMap + let geolocation = new AMap.Geolocation({ + // enableHighAccuracy: true // 是否使用高精度定位,默认:true + }) + geolocation.getCurrentPosition((status, result) => { + if (status === 'complete') { + let { lat: latitude, lng: longitude } = result.position + this.position = { latitude, longitude } + this.obtainData() + } else { + } + }) + }) + }, + obtainData() { + this.page.params = Object.assign(this.page.params, this.position) this.loading = true oilSiteApi .getSiteList(this.page) @@ -148,45 +168,6 @@ export default { .catch(error => { this.finished = true }) - return - initAMap().then(() => { - let AMap = this.$AMap - let geolocation = new AMap.Geolocation({ - // enableHighAccuracy: true // 是否使用高精度定位,默认:true - }) - geolocation.getCurrentPosition((status, result) => { - if (status === 'complete') { - let { lat: latitude, lng: longitude } = result.position - - // this.position = { latitude, longitude } - // console.log('this.position', this.position) - - let position = { latitude, longitude } - - this.page.params = Object.assign(this.page.params, position) - this.loading = true - oilSiteApi - .getSiteList(this.page) - .then(res => { - if (res.code == 20000) { - if (res.data.list.length < 10) { - this.finished = true - } - if (this.page.currentPage == 1) { - this.list = res.data.list - } else { - this.list = this.list.concat(res.data.list) - } - this.loading = false - this.refreshing = false - } - }) - .catch(error => { - this.finished = true - }) - } - }) - }) } } } diff --git a/vue.config.js b/vue.config.js index 73fd7a9..fcb45ab 100644 --- a/vue.config.js +++ b/vue.config.js @@ -17,8 +17,8 @@ module.exports = defineConfig({ proxy: { [process.env.VUE_APP_BASE_API]: { // target: `http://192.168.1.83:38080`, - target: `https://www.xingoil.com/adminapi`, - // target: `http://uat.xingoil.com/adminapi`, + // target: `https://www.xingoil.com/adminapi`, + target: `http://uat.xingoil.com/adminapi`, changeOrigin: true, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: ''