123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import {
- getUserInfo
- } from "../../api/user.js";
- import {
- LOGIN_STATUS,
- LOGIN_TYPE,
- UID
- } from '../../config/cache';
- import Cache from '../../utils/cache';
- import {
- USER_INFO
- } from '../../config/cache';
-
- const state = {
- token: Cache.get(LOGIN_STATUS) || false,
- backgroundColor: "#fff",
- userInfo: {},
- uid: Cache.get(UID) || 0,
- homeActive: false,
- phoneStatus:true,
- loginType:Cache.get(LOGIN_TYPE) || false,
- };
-
- const mutations = {
- SETLOGINTYPE(state,opt){
- state.loginType = opt.val;
- Cache.set(LOGIN_TYPE, opt.val, opt.time);
- },
- SETPHONESTATUS(state,val){
- state.phoneStatus = val;
- },
- LOGIN(state, opt) {
- state.token = opt.token;
- Cache.set(LOGIN_STATUS, opt.token, opt.time);
- },
- SETUID(state,val){
- state.uid = val;
- Cache.set(UID, val);
- },
- UPDATE_LOGIN(state, token) {
- state.token = token;
- },
- LOGOUT(state) {
- state.token = undefined;
- state.uid = undefined
- Cache.clear(LOGIN_STATUS);
- Cache.clear(UID);
- },
- BACKGROUND_COLOR(state, color) {
- state.color = color;
- document.body.style.backgroundColor = color;
- },
- UPDATE_USERINFO(state, userInfo) {
- state.userInfo = userInfo;
- Cache.set(USER_INFO, userInfo);
- },
- OPEN_HOME(state) {
- state.homeActive = true;
- },
- CLOSE_HOME(state) {
- state.homeActive = false;
- },
- };
-
- const actions = {
- USERINFO({
- state,
- commit
- }, force) {
- if (state.userInfo !== null && !force)
- return Promise.resolve(state.userInfo);
- else
- return new Promise(reslove => {
- getUserInfo().then(res => {
- commit("UPDATE_USERINFO", res.data);
- Cache.set(USER_INFO, res.data);
- reslove(res.data);
- });
- }).catch(() => {
-
- });
- }
- };
-
- export default {
- state,
- mutations,
- actions
- };
|