Browse Source

增加定位功能

zyh
Gao xiaosong 5 years ago
parent
commit
ba199ff02d
  1. 2
      assets/css/style.css
  2. 2
      assets/css/style.css.map
  3. 33
      assets/css/style.less
  4. 3
      components/Home.vue
  5. 4
      components/SwitchWindow.vue
  6. 6
      main.js
  7. 6
      manifest.json
  8. 8
      pages/authorization/index.vue
  9. 3
      pages/home/index.vue
  10. 104
      pages/shop/GoodsCon/index.vue
  11. 4
      pages/user/Login/index.vue
  12. 8
      pages/user/PersonalData/index.vue
  13. 14
      pages/user/User/index.vue
  14. 76
      store/index.js
  15. 14
      utils/index.js

2
assets/css/style.css

File diff suppressed because one or more lines are too long

2
assets/css/style.css.map

File diff suppressed because one or more lines are too long

33
assets/css/style.less

@ -2373,17 +2373,42 @@ page {
} }
.user .wrapper .myService .serviceList .item { .user .wrapper .myService .serviceList .item {
width: 25%; width: 100%;
text-align: center; text-align: left;
font-size: 0.26*100rpx; font-size: 0.26*100rpx;
color: #333; color: #333;
margin-top: 0.3*100rpx; display: flex;
align-items: center;
padding: 0.2*100rpx 0.3*100rpx;
position: relative;
.iconfont {
font-size: .26*100rpx;
color: #666;
}
&::after {
content: "";
display: block;
position: absolute;
left: 0.3*100rpx;
right: 0;
bottom: 0;
border-bottom: 1rpx solid #f5f5f5;
z-index: 999;
height: 1rpx;
}
} }
.user .wrapper .myService .serviceList .item .pictrue { .user .wrapper .myService .serviceList .item .pictrue {
width: 0.52*100rpx; width: 0.52*100rpx;
height: 0.52*100rpx; height: 0.52*100rpx;
margin: 0 auto 0.16*100rpx auto; margin-right: 0.16*100rpx;
}
.user .wrapper .myService .serviceList .item .cell {
flex: 1
} }
.user .wrapper .myService .serviceList .item .pictrue image { .user .wrapper .myService .serviceList .item .pictrue image {

3
components/Home.vue

@ -40,9 +40,6 @@ export default {
// else if (top < 55) top = 55; // else if (top < 55) top = 55;
this.top = 55; this.top = 55;
}, },
open: function() {
this.homeActive ? this.$store.commit('CLOSE_HOME') : this.$store.commit('OPEN_HOME');
}
} }
}; };
</script> </script>

4
components/SwitchWindow.vue

@ -130,7 +130,7 @@ export default {
if (that.login_type === "h5") { if (that.login_type === "h5") {
cookie.set("loginType", "wechat", 60); cookie.set("loginType", "wechat", 60);
uni.hideLoading(); uni.hideLoading();
this.$store.commit("LOGOUT"); this.$store.commit("logout");
this.$emit("changeswitch", false); this.$emit("changeswitch", false);
location.reload(); location.reload();
} else { } else {
@ -138,7 +138,7 @@ export default {
.then(({ data }) => { .then(({ data }) => {
uni.hideLoading(); uni.hideLoading();
const expires_time = dayjs(data.expires_time); const expires_time = dayjs(data.expires_time);
store.commit("LOGIN", data.token, expires_time); store.commit("login", data.token, expires_time);
this.$emit("changeswitch", false); this.$emit("changeswitch", false);
location.reload(); location.reload();
}) })

6
main.js

@ -78,20 +78,20 @@ Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL
// #ifdef H5 // #ifdef H5
// H5编译的代码 // H5编译的代码
Vue.prototype.$deviceType = 'h5' Vue.prototype.$deviceType = 'h5'
store.commit('UPDATE_DEVICETYPE','h5') store.commit('updateDevicetype','h5')
// #endif // #endif
// #ifdef APP-PLUS // #ifdef APP-PLUS
// App平台编译的代码 // App平台编译的代码
Vue.prototype.$deviceType = 'app' Vue.prototype.$deviceType = 'app'
store.commit('UPDATE_DEVICETYPE','app') store.commit('updateDevicetype','app')
Vue.prototype.$platform = uni.getSystemInfoSync().platform Vue.prototype.$platform = uni.getSystemInfoSync().platform
// #endif // #endif
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
// 微信小程序编译的代码 // 微信小程序编译的代码
Vue.prototype.$deviceType = 'routine' Vue.prototype.$deviceType = 'routine'
store.commit('UPDATE_DEVICETYPE','routine') store.commit('updateDevicetype','routine')
// #endif // #endif
// !!! ps 不建议在 template 中使用 $deviceType 去判断当前环境,很有可能出现 $deviceType 为 undefined 导致判断出错的问题,可以在 script 模块中正常使用 // !!! ps 不建议在 template 中使用 $deviceType 去判断当前环境,很有可能出现 $deviceType 为 undefined 导致判断出错的问题,可以在 script 模块中正常使用

6
manifest.json

@ -137,7 +137,11 @@
"urlCheck" : false "urlCheck" : false
}, },
"usingComponents" : true, "usingComponents" : true,
"permission" : {} "permission" : {
"scope.userLocation" : {
"desc" : "你的位置信息将用于小程序位置接口的效果展示"
}
}
}, },
"mp-alipay" : { "mp-alipay" : {
"usingComponents" : true "usingComponents" : true

8
pages/authorization/index.vue

@ -59,17 +59,17 @@ export default {
}, },
onHide() { onHide() {
console.log("离开授权页面,11111"); console.log("离开授权页面,11111");
this.UPDATE_AUTHORIZATIONPAGE(false); this.updateAuthorizationPage(false);
this.changeAuthorization(false); this.changeAuthorization(false);
}, },
onUnload() { onUnload() {
console.log("离开授权页面,11111"); console.log("离开授权页面,11111");
this.UPDATE_AUTHORIZATIONPAGE(false); this.updateAuthorizationPage(false);
this.changeAuthorization(false); this.changeAuthorization(false);
}, },
methods: { methods: {
...mapActions(["changeAuthorization", "setUserInfo"]), ...mapActions(["changeAuthorization", "setUserInfo"]),
...mapMutations(["UPDATE_AUTHORIZATIONPAGE", "CHANGE_TABTAR"]), ...mapMutations(["updateAuthorizationPage",]),
back() { back() {
this.$yrouter.switchTab({ this.$yrouter.switchTab({
@ -111,7 +111,7 @@ export default {
}, },
onUnload() { onUnload() {
console.log("离开授权页面,11111"); console.log("离开授权页面,11111");
this.UPDATE_AUTHORIZATIONPAGE(false); this.updateAuthorizationPage(false);
this.changeAuthorization(false); this.changeAuthorization(false);
}, },
mounted() { mounted() {

3
pages/home/index.vue

@ -130,6 +130,7 @@
</template> </template>
<script> <script>
// import { swiper, swiperSlide } from "vue-awesome-swiper"; // import { swiper, swiperSlide } from "vue-awesome-swiper";
import { mapState, mapMutations, mapActions } from 'vuex';
import GoodList from '@/components/GoodList'; import GoodList from '@/components/GoodList';
import PromotionGood from '@/components/PromotionGood'; import PromotionGood from '@/components/PromotionGood';
@ -233,6 +234,7 @@
}; };
}, },
onShow: function() { onShow: function() {
this.getLocation()
let that = this; let that = this;
uni.showLoading({ uni.showLoading({
title: '加载中' title: '加载中'
@ -257,6 +259,7 @@
}); });
}, },
methods: { methods: {
...mapActions(["getLocation"]),
goRoll(item){ goRoll(item){
if(item.uniapp_url){ if(item.uniapp_url){
this.$yrouter.push(item.uniapp_url) this.$yrouter.push(item.uniapp_url)

104
pages/shop/GoodsCon/index.vue

@ -43,20 +43,33 @@
</view> </view>
<view class="iconfont icon-jiantou"></view> <view class="iconfont icon-jiantou"></view>
</view> </view>
<view class="store-info" v-if="system_store.id !== undefined"> <view class="store-info">
<text class="title">门店信息</text> <view class="title acea-row row-between-wrapper">
<view>门店信息</view>
<text @click="goEvaluateList(id)" class="praise">
更多
<text class="iconfont icon-jiantou"></text>
</text>
</view>
<view class="info acea-row row-between-wrapper"> <view class="info acea-row row-between-wrapper">
<view class="picTxt acea-row row-between-wrapper"> <view class="picTxt acea-row row-between-wrapper">
<view class="pictrue"> <view class="pictrue">
<image :src="system_store.image" /> <image :src="systemStore.image" />
</view> </view>
<view class="text"> <view class="text">
<view class="name line1">{{ system_store.name }}</view> <view class="name line1">{{ systemStore.name }}</view>
<view class="address acea-row row-middle" @click="showChang"> <view class="address acea-row row-middle" @click="showChang">
<text class="addressTxt line1">{{system_store._detailed_address}}</text> <text class="addressTxt">{{systemStore.address}}</text>
<text class="iconfont icon-youjian"></text> <text class="iconfont icon-youjian"></text>
</view> </view>
</view> </view>
<view class="addressBox">
<a
:href="'tel:'+systemStore.phone"
class="iconfont icon-dadianhua01 font-color-red phone"
></a>
<view class="addressTxt corlor-yshop">距离{{systemStore.distance}}千米</view>
</view>
</view> </view>
</view> </view>
</view> </view>
@ -142,13 +155,13 @@
<view class="generate-posters acea-row row-middle on" v-if="posters"> <view class="generate-posters acea-row row-middle on" v-if="posters">
<view class="item" @click="setPosterImageStatus"> <view class="item" @click="setPosterImageStatus">
<view class="iconfont icon-haibao"></view> <view class="iconfont icon-haibao"></view>
<view >生成海报</view> <view>生成海报</view>
</view> </view>
</view> </view>
<view class="generate-posters acea-row row-middle" v-if="!posters"> <view class="generate-posters acea-row row-middle" v-if="!posters">
<view class="item" @click="setPosterImageStatus"> <view class="item" @click="setPosterImageStatus">
<view class="iconfont icon-haibao"></view> <view class="iconfont icon-haibao"></view>
<view >生成海报</view> <view>生成海报</view>
</view> </view>
</view> </view>
<view class="mask" @touchmove.prevent @click="listenerActionClose" v-show="posters"></view> <view class="mask" @touchmove.prevent @click="listenerActionClose" v-show="posters"></view>
@ -158,7 +171,7 @@
height="100%" height="100%"
frameborder="0" frameborder="0"
scrolling="no" scrolling="no"
:src="'https://apis.map.qq.com/uri/v1/geocoder?coord=' +system_store.latitude +',' +system_store.longitude +'&referer=' +mapKey" :src="'https://apis.map.qq.com/uri/v1/geocoder?coord=' +systemStore.latitude +',' +systemStore.longitude +'&referer=' +mapKey"
></iframe> ></iframe>
</view> </view>
<view class="posterCanvasWarp"> <view class="posterCanvasWarp">
@ -255,18 +268,16 @@ export default {
observeParents: true observeParents: true
}, },
goodList: [], goodList: [],
system_store: {}, systemStore: {},
qqmapsdk: null, qqmapsdk: null,
productConClass: "product-con" productConClass: "product-con"
}; };
}, },
computed: mapGetters(["isLogin"]), computed: mapGetters(["isLogin", "location"]),
mounted: function() { mounted: function() {
let url = handleQrCode(); let url = handleQrCode();
console.log(url);
if (url && url.productId) { if (url && url.productId) {
this.id = url.productId; this.id = url.productId;
} else { } else {
this.id = this._route.query.id; this.id = this._route.query.id;
} }
@ -299,25 +310,22 @@ export default {
} }
}); });
}, },
showChang: function() { showChang: function(data) {
if (isWeixin()) { let config = {
let config = { latitude: data.latitude,
latitude: this.system_store.latitude, longitude: data.longitude,
longitude: this.system_store.longitude, name: data.name,
name: this.system_store.name, address: data._detailed_address
address: this.system_store._detailed_address };
}; if (!this.mapKey) {
} else { uni.showToast({
if (!this.mapKey) { title: "暂无法使用查看地图,请配置您的腾讯地图key",
uni.showToast({ icon: "none",
title: "暂无法使用查看地图,请配置您的腾讯地图key", duration: 2000
icon: "none", });
duration: 2000 return;
});
return;
}
this.mapShow = true;
} }
this.mapShow = true;
}, },
updateTitle() { updateTitle() {
// document.title = this.storeInfo.storeName || this.$yroute.meta.title; // document.title = this.storeInfo.storeName || this.$yroute.meta.title;
@ -340,13 +348,14 @@ export default {
// //
productCon: function() { productCon: function() {
let that = this; let that = this;
let from = {}; let from = this.location;
if (this.$deviceType == "app") { if (this.$deviceType == "app") {
from.from = "app"; from.from = "app";
} }
uni.showLoading({ title: "加载中", mask: true }); uni.showLoading({ title: "加载中", mask: true });
getProductDetail(that.id, from) getProductDetail(that.id, from)
.then(res => { .then(res => {
console.log(res);
that.$set(that, "storeInfo", res.data.storeInfo); that.$set(that, "storeInfo", res.data.storeInfo);
// attr attr // attr attr
that.$set(that.attr, "productAttr", res.data.productAttr); that.$set(that.attr, "productAttr", res.data.productAttr);
@ -365,7 +374,7 @@ export default {
} }
that.posterData.price = that.storeInfo.price; that.posterData.price = that.storeInfo.price;
that.posterData.code = that.storeInfo.codeBase; that.posterData.code = that.storeInfo.codeBase;
// that.system_store = res.data.system_store; that.systemStore = res.data.systemStore;
let good_list = res.data.goodList || []; let good_list = res.data.goodList || [];
let goodArray = []; let goodArray = [];
let count = Math.ceil(good_list.length / 6); let count = Math.ceil(good_list.length / 6);
@ -703,12 +712,16 @@ export default {
} }
.product-con .store-info .info .picTxt { .product-con .store-info .info .picTxt {
width: 6.15 * 100rpx; width: 100%;
display: flex;
align-items: center;
} }
.product-con .store-info .info .picTxt .pictrue { .product-con .store-info .info .picTxt .pictrue {
width: 0.76 * 100rpx; width: 0.76 * 100rpx;
height: 0.76 * 100rpx; height: 0.76 * 100rpx;
margin-right: 0.2 * 100rpx;
} }
.product-con .store-info .info .picTxt .pictrue image { .product-con .store-info .info .picTxt .pictrue image {
@ -718,7 +731,7 @@ export default {
} }
.product-con .store-info .info .picTxt .text { .product-con .store-info .info .picTxt .text {
width: 5.22 * 100rpx; flex: 1;
} }
.product-con .store-info .info .picTxt .text .name { .product-con .store-info .info .picTxt .text .name {
@ -738,13 +751,26 @@ export default {
margin-left: 0.1 * 100rpx; margin-left: 0.1 * 100rpx;
} }
.product-con .store-info .info .picTxt .text .address .addressTxt { .product-con .store-info .info .picTxt .addressBox {
width: 4.8 * 100rpx; display: flex;
flex-direction: column;
align-items: flex-end;
} }
.product-con .store-info .info .picTxt .addressBox .iconfont {
.product-con .store-info .info .iconfont {
font-size: 0.4 * 100rpx; font-size: 0.4 * 100rpx;
} }
.product-con .store-info .info .picTxt .addressBox .addressTxt {
font-size: 0.24 * 100rpx;
color: #00c17b;
}
.product-con .store-info .praise {
font-size: 0.28 * 100rpx;
color: #808080;
}
.product-con .store-info .praise .iconfont {
font-size: 0.28 * 100rpx;
}
.product-con .superior { .product-con .superior {
background-color: #fff; background-color: #fff;

4
pages/user/Login/index.vue

@ -174,7 +174,7 @@ export default {
}) })
.then(res => { .then(res => {
var data = res.data; var data = res.data;
that.$store.commit("LOGIN", data.token, dayjs(data.expires_time)); that.$store.commit("login", data.token, dayjs(data.expires_time));
handleGetUserInfo(); handleGetUserInfo();
}) })
.catch(err => { .catch(err => {
@ -305,7 +305,7 @@ export default {
spread: cookie.get("spread") spread: cookie.get("spread")
}) })
.then(({ data }) => { .then(({ data }) => {
this.$store.commit("LOGIN", data.token, dayjs(data.expires_time)); this.$store.commit("login", data.token, dayjs(data.expires_time));
handleGetUserInfo(); handleGetUserInfo();
// let replace=this.$yroute.query.replace // let replace=this.$yroute.query.replace
// if(replace){ // if(replace){

8
pages/user/PersonalData/index.vue

@ -149,7 +149,7 @@ export default {
.then(({ data }) => { .then(({ data }) => {
uni.hideLoading(); uni.hideLoading();
const expires_time = dayjs(data.expires_time); const expires_time = dayjs(data.expires_time);
store.commit("LOGIN", data.token, expires_time); store.commit("login", data.token, expires_time);
that.$emit("changeswitch", false); that.$emit("changeswitch", false);
location.reload(); location.reload();
}) })
@ -164,7 +164,7 @@ export default {
} else { } else {
cookie.set("loginType", "wechat", 60); cookie.set("loginType", "wechat", 60);
uni.hideLoading(); uni.hideLoading();
this.$store.commit("LOGOUT"); this.$store.commit("logout");
this.$emit("changeswitch", false); this.$emit("changeswitch", false);
} }
}, },
@ -204,7 +204,7 @@ export default {
avatar: userInfo.avatar avatar: userInfo.avatar
}).then( }).then(
res => { res => {
this.$store.dispatch("USERINFO", true); this.$store.dispatch("userInfo", true);
this.$uni.showToast({ this.$uni.showToast({
title: res.msg, title: res.msg,
icon: "none", icon: "none",
@ -229,7 +229,7 @@ export default {
if (res.confirm) { if (res.confirm) {
getLogout() getLogout()
.then(res => { .then(res => {
this.$store.commit("LOGOUT"); this.$store.commit("logout");
clearAuthStatus(); clearAuthStatus();
location.href = location.origin; location.href = location.origin;
}) })

14
pages/user/User/index.vue

@ -115,9 +115,6 @@
</view> </view>
</view> </view>
<view class="myService"> <view class="myService">
<view class="title acea-row row-middle">
<text>我的服务</text>
</view>
<view class="serviceList acea-row row-middle"> <view class="serviceList acea-row row-middle">
<template v-for="(item, MyMenusIndex) in MyMenus"> <template v-for="(item, MyMenusIndex) in MyMenus">
<view <view
@ -129,7 +126,8 @@
<view class="pictrue"> <view class="pictrue">
<image :src="item.pic" /> <image :src="item.pic" />
</view> </view>
<view>{{ item.name }}</view> <view class="cell">{{ item.name }}</view>
<text class="iconfont icon-jiantou"></text>
</view> </view>
</template> </template>
</view> </view>
@ -188,7 +186,7 @@ export default {
}, },
computed: mapGetters(["userInfo"]), computed: mapGetters(["userInfo"]),
methods: { methods: {
...mapMutations(["UPDATE_AUTHORIZATIONPAGE", "CHANGE_TABTAR"]), ...mapMutations(["updateAuthorizationPage", "CHANGE_TABTAR"]),
goReturnList() { goReturnList() {
this.$yrouter.push("/pages/order/ReturnList/index"); this.$yrouter.push("/pages/order/ReturnList/index");
}, },
@ -240,7 +238,7 @@ export default {
.then(res => { .then(res => {
console.log(res); console.log(res);
// this.User(); // this.User();
thit.$store.dispatch("USERINFO", true); thit.$store.dispatch("userInfo", true);
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
@ -250,7 +248,7 @@ export default {
}) })
.catch(error => { .catch(error => {
uni.hideLoading(); uni.hideLoading();
thit.$store.dispatch("USERINFO", true); thit.$store.dispatch("userInfo", true);
console.log(error); console.log(error);
uni.showToast({ uni.showToast({
title: title:
@ -353,7 +351,7 @@ export default {
}, },
onHide() { onHide() {
console.log('离开用户中心') console.log('离开用户中心')
this.UPDATE_AUTHORIZATIONPAGE(false); this.updateAuthorizationPage(false);
} }
}; };
</script> </script>

76
store/index.js

@ -11,7 +11,7 @@ import {
} from "@/api/user"; } from "@/api/user";
import dialog from "@/utils/dialog"; import dialog from "@/utils/dialog";
const LOGIN_KEY = "login_status"; const loginKey = "login_status";
const vuexStore = new Vuex.Store({ const vuexStore = new Vuex.Store({
state: { state: {
@ -20,37 +20,20 @@ const vuexStore = new Vuex.Store({
// 是否授权 // 是否授权
isAuthorization: false, isAuthorization: false,
// 不建议从这里取 token,但是删除掉会影响其他的页面 // 不建议从这里取 token,但是删除掉会影响其他的页面
token: cookie.get(LOGIN_KEY) || null, token: cookie.get(loginKey) || null,
userInfo: cookie.get('userInfo'), userInfo: cookie.get('userInfo'),
$deviceType: null, $deviceType: null,
location: {
latitude: '',
longitude: ''
}
}, },
mutations: { mutations: {
SHOW_FOOTER(state) { login(state, token, expires_time) {
state.footer = true;
},
HIDE_FOOTER(state) {
state.footer = false;
},
SHOW_HOME(state) {
state.home = true;
},
HIDE_HOME(state) {
state.home = false;
},
OPEN_HOME(state) {
state.homeActive = true;
},
CLOSE_HOME(state) {
state.homeActive = false;
},
CHANGE_TABTAR(state, index) {
state.tabtarIndex = index;
},
LOGIN(state, token, expires_time) {
state.token = token; state.token = token;
cookie.set(LOGIN_KEY, token, expires_time); cookie.set(loginKey, token, expires_time);
}, },
LOGOUT(state) { logout(state) {
console.log('清除数据') console.log('清除数据')
state.token = null; state.token = null;
state.userInfo = null state.userInfo = null
@ -59,11 +42,11 @@ const vuexStore = new Vuex.Store({
cookie.clearAll() cookie.clearAll()
cookie.set('spread', spread) cookie.set('spread', spread)
}, },
BACKGROUND_COLOR(state, color) { backgroundColor(state, color) {
state.color = color; state.color = color;
// document.body.style.backgroundColor = color; // document.body.style.backgroundColor = color;
}, },
UPDATE_USERINFO(state, userInfo) { updateUserInfo(state, userInfo) {
state.userInfo = userInfo; state.userInfo = userInfo;
if (userInfo) { if (userInfo) {
cookie.set('userInfo', userInfo) cookie.set('userInfo', userInfo)
@ -71,24 +54,40 @@ const vuexStore = new Vuex.Store({
cookie.set('userInfo', null) cookie.set('userInfo', null)
} }
}, },
UPDATE_AUTHORIZATIONPAGE(state, isAuthorizationPage) { updateAuthorizationPage(state, isAuthorizationPage) {
state.isAuthorizationPage = isAuthorizationPage; state.isAuthorizationPage = isAuthorizationPage;
}, },
UPDATE_AUTHORIZATION(state, isAuthorization) { updateAuthorization(state, isAuthorization) {
state.isAuthorization = isAuthorization; state.isAuthorization = isAuthorization;
}, },
UPDATE_DEVICETYPE(state, $deviceType) { updateDevicetype(state, $deviceType) {
state.$deviceType = $deviceType; state.$deviceType = $deviceType;
}, },
setLocation(state, location) {
console.log(location, '定位')
state.location = location
}
}, },
actions: { actions: {
USERINFO({ state, commit }, force) { getLocation({ state, commit }, force) {
uni.getLocation({
type: 'wgs84',
success: function (res) {
console.log(res)
commit("setLocation", {
longitude: res.longitude,
latitude: res.latitude,
});
}
});
},
userInfo({ state, commit }, force) {
if (state.userInfo !== null && !force) { if (state.userInfo !== null && !force) {
return Promise.resolve(state.userInfo); return Promise.resolve(state.userInfo);
} else { } else {
return new Promise(reslove => { return new Promise(reslove => {
getUserInfo().then(res => { getUserInfo().then(res => {
commit("UPDATE_USERINFO", res.data); commit("updateUserInfo", res.data);
reslove(res.data); reslove(res.data);
}); });
}).catch(() => { }).catch(() => {
@ -100,7 +99,7 @@ const vuexStore = new Vuex.Store({
return new Promise(reslove => { return new Promise(reslove => {
getUser().then(res => { getUser().then(res => {
console.log(res) console.log(res)
commit("UPDATE_USERINFO", res.data); commit("updateUserInfo", res.data);
reslove(res.data); reslove(res.data);
}); });
}).catch((error) => { }).catch((error) => {
@ -112,25 +111,25 @@ const vuexStore = new Vuex.Store({
state, state,
commit commit
}, data, date) { }, data, date) {
commit("LOGIN", data, date); commit("login", data, date);
}, },
setUserInfo({ setUserInfo({
state, state,
commit commit
}, user) { }, user) {
commit("UPDATE_USERINFO", user); commit("updateUserInfo", user);
}, },
changeAuthorizationPage({ changeAuthorizationPage({
state, state,
commit commit
}, index) { }, index) {
commit("UPDATE_AUTHORIZATIONPAGE", index); commit("updateAuthorizationPage", index);
}, },
changeAuthorization({ changeAuthorization({
state, state,
commit commit
}, index) { }, index) {
commit("UPDATE_AUTHORIZATION", index); commit("updateAuthorization", index);
}, },
}, },
getters: { getters: {
@ -139,6 +138,7 @@ const vuexStore = new Vuex.Store({
token: state => state.token, token: state => state.token,
isLogin: state => !!state.token, isLogin: state => !!state.token,
userInfo: state => state.userInfo || {}, userInfo: state => state.userInfo || {},
location: state => state.location,
}, },
strict: debug strict: debug
}); });

14
utils/index.js

@ -184,8 +184,8 @@ export const login = () => {
console.log('登录接口调用成功') console.log('登录接口调用成功')
console.log('开始处理登录信息保存,并获取用户详情') console.log('开始处理登录信息保存,并获取用户详情')
uni.hideLoading(); uni.hideLoading();
store.commit("LOGIN", data.token, dayjs(data.expires_time)); store.commit("login", data.token, dayjs(data.expires_time));
store.dispatch('USERINFO', true) store.dispatch('userInfo', true)
getUser().then(user => { getUser().then(user => {
console.log('获取用户信息成功') console.log('获取用户信息成功')
store.dispatch('setUserInfo', user.data) store.dispatch('setUserInfo', user.data)
@ -439,7 +439,7 @@ export function routerPermissions(url, type) {
console.log('————————') console.log('————————')
console.log('登录成功,跳转页面') console.log('登录成功,跳转页面')
console.log('————————') console.log('————————')
store.commit("UPDATE_AUTHORIZATIONPAGE", false); store.commit("updateAuthorizationPage", false);
if (path == '/pages/shop/ShoppingCart/index' || path == '/pages/user/User/index') { if (path == '/pages/shop/ShoppingCart/index' || path == '/pages/user/User/index') {
console.log('————————') console.log('————————')
console.log('当前是购物车,或者个人中心') console.log('当前是购物车,或者个人中心')
@ -475,7 +475,7 @@ export function routerPermissions(url, type) {
switchTab({ switchTab({
path, path,
}) })
store.commit("UPDATE_AUTHORIZATIONPAGE", false); store.commit("updateAuthorizationPage", false);
return return
} }
reLaunch({ reLaunch({
@ -709,8 +709,8 @@ export const handleLoginFailure = () => {
console.log('退出登录,标记当前页面为授权页面,防止多次跳转') console.log('退出登录,标记当前页面为授权页面,防止多次跳转')
console.log('————————') console.log('————————')
store.commit("LOGOUT"); store.commit("logout");
store.commit("UPDATE_AUTHORIZATION", false); store.commit("updateAuthorization", false);
// token 失效 // token 失效
// 判断当前是不是已经在登录页面或者授权页,防止二次跳转 // 判断当前是不是已经在登录页面或者授权页,防止二次跳转
@ -723,7 +723,7 @@ export const handleLoginFailure = () => {
console.log('当前是授权页面') console.log('当前是授权页面')
console.log(store.getters) console.log(store.getters)
console.log('————————') console.log('————————')
store.commit("UPDATE_AUTHORIZATIONPAGE", true); store.commit("updateAuthorizationPage", true);
let path = getCurrentPageUrlWithArgs() let path = getCurrentPageUrlWithArgs()

Loading…
Cancel
Save