lilishop-uniapp/store/index.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-05-13 11:03:32 +08:00
import Vue from "vue";
import Vuex from "vuex";
import storage from "@/utils/storage";
Vue.use(Vuex);
2021-05-17 18:19:26 +08:00
2021-05-13 11:03:32 +08:00
const store = new Vuex.Store({
state: {
verificationKey: "", //获取key表示验证通过
/**
* 是否需要强制登录
*/
2021-05-13 11:03:32 +08:00
forcedLogin: false,
distributionId:"", //分销员Id 如果当前账户从未登录过时记录
2021-05-13 11:03:32 +08:00
hasLogin: storage.getHasLogin(),
userInfo: storage.getUserInfo(),
uuid: storage.getUuid(),
token: "",
getHeadInfo: "",
getWeixinHeightInfo: "",
},
mutations: {
/**
* 获取头部高度 异步使用
* 文档链接在 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync
* */
GET_HEAD_HEIGHT(state) {
return new Promise((resolve, reject) => {
state.getHeadInfo = uni.getSystemInfoSync();
resolve();
});
},
/**
* 获取微信小胶囊高度 */
MP_WEIXIN_HEIGHT(state) {
// width number 宽度单位px
// height number 高度单位px
// top number 上边界坐标单位px
// right number 右边界坐标单位px
// bottom number 下边界坐标单位px
// left number 左边界坐标单位px
state.getWeixinHeightInfo = uni.getMenuButtonBoundingClientRect();
},
// 前台存储登录状态
SET_HAS_LOGIN(state, val) {
state.hasLogin = val;
},
// 登录信息
SET_USER_INFO(state, val) {
state.userInfo = val;
},
login(state, userInfo) {
state.userInfo = userInfo || {};
state.userName =
userInfo.Name || userInfo.Nickname || userInfo.Username || "匿名用户";
state.hasLogin = true;
},
logout(state) {
state.userName = "";
state.hasLogin = false;
},
},
actions: {},
});
export default store;