pull/1/head
xiaozhiyong 2 years ago
parent 87caa6203b
commit 74f02f1ce2
  1. 2
      src/permission.js
  2. 29
      src/store/piniaIndex.js
  3. 70
      src/views/HomeView.vue

@ -12,7 +12,7 @@ router.beforeEach(async (to, from, next) => {
let store = useStore() //获取状态 let store = useStore() //获取状态
let token = getToken() //获取cookie let token = getToken() //获取cookie
// removeToken() // removeToken()
store.getPosition() // store.getPosition()
if (!token) { if (!token) {
let paramsTarget = obtainUrlPathParameterTarget(location.href) let paramsTarget = obtainUrlPathParameterTarget(location.href)

@ -27,22 +27,27 @@ const instance = defineStore('user', {
actions: { actions: {
getPosition() { getPosition() {
// initAMap().then(() => { initAMap().then(() => {
// console.log(3) // console.log(3)
// let AMap = Vue.prototype.$AMap let AMap = Vue.prototype.$AMap
// let geolocation = new AMap.Geolocation({ let geolocation = new AMap.Geolocation({
// // enableHighAccuracy: true // 是否使用高精度定位,默认:true // enableHighAccuracy: true // 是否使用高精度定位,默认:true
// }) })
// geolocation.getCurrentPosition(function (status, result) { geolocation.getCurrentPosition(function (status, result) {
// console.log('status', status) console.log(2)
// console.log('result', result) if (status === 'complete') {
// }) let { lat: latitude, lng: longitude } = result.position
// }) this.position = { latitude, longitude }
// return console.log('this.position', this.position)
}
})
})
return
if (navigator?.geolocation?.getCurrentPosition) { if (navigator?.geolocation?.getCurrentPosition) {
navigator.geolocation.getCurrentPosition( navigator.geolocation.getCurrentPosition(
position => { position => {
console.log('position.coords', position.coords)
let { latitude, longitude } = position.coords let { latitude, longitude } = position.coords
this.position = { latitude, longitude } this.position = { latitude, longitude }
}, },

@ -19,6 +19,9 @@
import homeNavBar from '@/components/homeNavBar.vue' import homeNavBar from '@/components/homeNavBar.vue'
import listItem from '@/components/listItem.vue' import listItem from '@/components/listItem.vue'
import oilSiteApi from '@/api/oil-site.js' import oilSiteApi from '@/api/oil-site.js'
import initAMap from '@/utils/amap.js'
export default { export default {
components: { components: {
homeNavBar, homeNavBar,
@ -122,39 +125,44 @@ export default {
return !position?.latitude && !position?.longitude ? true : false return !position?.latitude && !position?.longitude ? true : false
}, },
getlist() { getlist() {
let position = this.$pinia.state.value.user.position initAMap().then(() => {
// console.log('position', position) let AMap = this.$AMap
// console.log(Object.assign(this.page.params, position), position, '') let geolocation = new AMap.Geolocation({
if (this.positionChenk(position)) { // enableHighAccuracy: true // 使true
position = JSON.parse(localStorage.getItem('position'))
if (this.positionChenk(position)) {
// console.log(position, this.$pinia.state.value.user.position, '')
this.finished = true
return
}
}
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
}
// console.log(res)
}) })
.catch(error => { geolocation.getCurrentPosition((status, result) => {
this.finished = true 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
})
}
}) })
})
} }
} }
} }

Loading…
Cancel
Save