<script>
|
var QQMapWX = require('@/utils/qqmap-wx-jssdk.js')
|
import { mapState } from 'vuex'
|
export default {
|
computed: {
|
...mapState(['userInfo', 'token'])
|
},
|
onLaunch: async function() {
|
// 登录
|
var that = this;
|
if (!this.token) {
|
uni.login({
|
provider: 'weixin',
|
success: async function (loginRes) {
|
let { code } = loginRes;
|
let res = await that.$u.api.wxLogin({ code })
|
if (res.code === 200) {
|
// 判断有无openid
|
if (res.data.openid) {
|
await that.$store.commit('setOpenId', res.data.openid)
|
}
|
// 判断有无token
|
if (res.data.token) {
|
await that.$store.commit('setToken', res.data.token)
|
}
|
// 判断有无用户信息
|
if (res.data.member) {
|
await that.$store.commit('setUserInfo', res.data.member)
|
await that.$store.commit('setOpenId', res.data.member.openId)
|
}
|
// 设置定位
|
await that.checkLocationAuth()
|
}
|
}
|
});
|
} else {
|
// 缓存用户信息
|
let res = await that.$u.api.getUserInfo()
|
if (res.code === 200) {
|
await that.$store.commit('setUserInfo', res.data)
|
await that.$store.commit('setOpenId', res.data.openId)
|
}
|
// 设置定位
|
await that.checkLocationAuth()
|
}
|
},
|
onShow: function() {
|
console.log('App Show')
|
},
|
onHide: function() {
|
console.log('App Hide')
|
},
|
methods: {
|
checkLocationAuth() {
|
uni.getSetting({
|
success: (res) => {
|
if (!res.authSetting['scope.userLocation']) {
|
uni.authorize({
|
scope: 'scope.userLocation',
|
success: () => {
|
this.positioning()
|
},
|
fail: () => {
|
uni.showModal({
|
title: '提示',
|
content: '需要获取您的位置信息,请在设置中开启位置权限',
|
confirmText: '去设置',
|
success: (res) => {
|
if (res.confirm) {
|
this.goToAppSetting();
|
} else {
|
this.$isResolve()
|
}
|
}
|
});
|
}
|
});
|
} else {
|
this.positioning()
|
}
|
}
|
});
|
},
|
goToAppSetting() {
|
var that = this;
|
uni.openSetting({
|
success: (res) => {
|
if (res.authSetting['scope.userLocation']) {
|
that.positioning()
|
}
|
that.$isResolve()
|
}
|
});
|
},
|
// 定位
|
positioning() {
|
var that = this;
|
uni.getLocation({
|
type: 'gcj02',
|
highAccuracyExpireTime: 3000,
|
isHighAccuracy: true,
|
success: function (addr) {
|
const locParam = { latitude: addr.latitude, longitude: addr.longitude };
|
const qqmapsdk = new QQMapWX({
|
key: 'HEIBZ-QJLLM-SZ36X-6ZBHI-S6Y2J-S6FND'
|
});
|
qqmapsdk.reverseGeocoder({
|
locParam,
|
success: function(res) {
|
console.log(res, '==================获取地址');
|
that.$store.commit('setPosition', res)
|
that.$isResolve()
|
},
|
fail: (err) => {
|
console.error('获取位置失败===========', err);
|
that.$isResolve()
|
}
|
});
|
}
|
});
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
@import "uview-ui/index.scss";
|
/*每个页面公共css */
|
.tc {
|
width: calc(100vw - 148rpx);
|
.tc-btn {
|
width: 100%;
|
height: 102rpx;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
border-top: 1rpx solid #EEEEEE;
|
.tc-btn-item {
|
flex: 1;
|
height: 100%;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
font-weight: 400;
|
font-size: 32rpx;
|
color: #666666;
|
border-right: 1rpx solid #EEEEEE;
|
&:last-child {
|
border: none !important;
|
}
|
}
|
}
|
.tc-contemt {
|
width: 100%;
|
padding: 40rpx 0;
|
box-sizing: border-box;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
flex-direction: column;
|
.tc-contemt-title {
|
width: 100%;
|
text-align: center;
|
font-weight: 600;
|
font-size: 32rpx;
|
color: #111111;
|
}
|
.tc-contemt-nr {
|
width: 472rpx;
|
text-align: center;
|
font-weight: 400;
|
font-size: 28rpx;
|
color: #333333;
|
margin-top: 40rpx;
|
}
|
}
|
}
|
</style>
|