lilishop-uniapp/store/index.js

68 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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,
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;