Files
lilishop-uniapp/store/index.js
2021-06-04 18:11:34 +08:00

70 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Vue from "vue";
import Vuex from "vuex";
import storage from "@/utils/storage";
Vue.use(Vuex);
const store = new Vuex.Store({
state: {
verificationKey: "", //获取key表示验证通过
/**
* 是否需要强制登录
*/
forcedLogin: false,
distributionId:"", //分销员Id 如果当前账户从未登录过时记录
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;