| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import {
- getUserInfo
- } from "../../api/user.js";
- import {
- LOGIN_STATUS,
- UID
- } from '../../config/cache';
- import Cache from '../../utils/cache';
- import {
- USER_INFO
- } from '../../config/cache';
- const state = {
- token: Cache.get(LOGIN_STATUS) || null,
- backgroundColor: "#fff",
- userInfo: null,
- uid: Cache.get(UID) || null,
- homeActive: false,
- power: '',
- };
- const mutations = {
- 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;
- },
- OPEN_HOME(state) {
- state.homeActive = true;
- },
- CLOSE_HOME(state) {
- state.homeActive = false;
- },
- setPower(state,val) {
- state.power = val
- }
- };
- 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
- };
|