Browse Source

上传

master
前端-胡立永 7 months ago
parent
commit
1261d55c6e
4 changed files with 65 additions and 4 deletions
  1. +6
    -0
      App.vue
  2. +1
    -0
      api/api.js
  3. +48
    -1
      store/store.js
  4. +10
    -3
      utils/position.js

+ 6
- 0
App.vue View File

@ -5,6 +5,12 @@
onShow: function() { onShow: function() {
this.$store.commit('initConfig') this.$store.commit('initConfig')
this.$store.commit('getBanner') this.$store.commit('getBanner')
this.$store.commit('getPosition')
this.$store.commit('getSpotList')
setInterval(() => {
// this.$store.commit('getPosition')
}, 5000)
}, },
onHide: function() { onHide: function() {
} }


+ 1
- 0
api/api.js View File

@ -94,6 +94,7 @@ const config = {
method: 'GET', method: 'GET',
showLoading: true, showLoading: true,
}, },
// 获取景点列表
// areaId: 0-瓷都镇区 1-湖田片区 2-高岭片区 3-瑶里片区 4-蛟潭片区; categoryTyep: 0-景点 1-美食店铺 2-民宿 3-厕所 // areaId: 0-瓷都镇区 1-湖田片区 2-高岭片区 3-瑶里片区 4-蛟潭片区; categoryTyep: 0-景点 1-美食店铺 2-民宿 3-厕所
querySpotList: { querySpotList: {
url: '/info/querySpotList', url: '/info/querySpotList',


+ 48
- 1
store/store.js View File

@ -34,6 +34,7 @@ const store = new Vuex.Store({
], ],
banner : {}, banner : {},
cartCheckboxValue : [],//选中的购物车 cartCheckboxValue : [],//选中的购物车
spotList : [],
}, },
getters: { getters: {
// 角色 true为水洗店 false为酒店 // 角色 true为水洗店 false为酒店
@ -74,6 +75,51 @@ const store = new Vuex.Store({
}) })
}, },
getSpotList(state){
api('querySpotList', {
pageNo : 1,
pageSize : 999999999,
}, res => {
if(res.code == 200){
let spot = []
res.result.records.forEach(n => {
if(n.spotLatitude && n.spotLongitude){
spot.push(n)
}
})
Position.calculateDistance()
state.spotList = spot
this.commit('calculateDistance')
}
})
},
// 计算地点与自己的距离
calculateDistance(state){
if(state.spotList.length && state.position.latitude){
state.spotList.forEach(n => {
n.distance = parseFloat(Position.calculateDistance(
state.position.latitude,
state.position.longitude,
n.spotLatitude,
n.spotLongitude,
3
))
})
// 排序,最近的在前面
state.spotList.sort((a, b) => a.distance - b.distance)
console.log(state.spotList);
}
},
login(state){ login(state){
uni.showLoading({ uni.showLoading({
title: '登录中...' title: '登录中...'
@ -120,10 +166,11 @@ const store = new Vuex.Store({
}, },
getPosition(state){ getPosition(state){
Position.getLocation(res => { Position.getLocation(res => {
console.log(res);
state.position = res state.position = res
this.commit('calculateDistance')
}) })
}, },
}, },
actions: {}, actions: {},
}) })


+ 10
- 3
utils/position.js View File

@ -1,7 +1,14 @@
import config from '../config.js' import config from '../config.js'
function calculateDistance(lat1, lon1, lat2, lon2) { //计算两点距离
/**
* 计算两点之间的距离
* @param {number} lat1 地点1精度
* @param {number} lon1 地点1维度
* @param {number} lat2 地点2精度
* @param {number} lon2 地点2维度
* @param {number} fixed 保留几位小数默认0
*/
function calculateDistance(lat1, lon1, lat2, lon2, fixed = 0) { //计算两点距离
let distance = 0 let distance = 0
if (!lat2 || !lon2) return distance if (!lat2 || !lon2) return distance
//先强制转换一下(后端给的字符串) //先强制转换一下(后端给的字符串)
@ -21,7 +28,7 @@ function calculateDistance(lat1, lon1, lat2, lon2) { //计算两点距离
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
// 计算距离 // 计算距离
distance = R * c; distance = R * c;
return distance.toFixed(0)
return distance.toFixed(fixed)
} }
function getLocation(fn) { //获取用户经纬度 function getLocation(fn) { //获取用户经纬度


Loading…
Cancel
Save