You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crmeb/app/store/modules/app.js

153 lines
3.4 KiB

import {
getUserInfo
} from "../../api/user.js";
import {
getAdminInfoByUid
} from "../../api/property.js";
import {
LOGIN_STATUS,
UID,
PLATFORM,
ADMIN_INFO
} from '../../config/cache';
import Cache from '../../utils/cache';
import {
USER_INFO
} from '../../config/cache';
const state = {
token: Cache.get(LOGIN_STATUS) || '',
backgroundColor: "#fff",
userInfo: Cache.get(USER_INFO)?JSON.parse(Cache.get(USER_INFO)):null,
uid: Cache.get(UID) || null,
homeActive: false,
chatUrl: Cache.get('chatUrl') || '',
systemPlatform: Cache.get(PLATFORM)?Cache.get(PLATFORM):'',
productType: Cache.get('productType') || '',
// 管理员账号信息
adminInfo: Cache.get(ADMIN_INFO) ? JSON.parse(Cache.get(ADMIN_INFO)) : null
};
const mutations = {
LOGIN(state, opt) {
state.token = opt.token;
Cache.set(LOGIN_STATUS, opt.token);
},
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;
state.adminInfo = null;
Cache.clear(LOGIN_STATUS);
Cache.clear(UID);
Cache.clear(USER_INFO);
Cache.clear(ADMIN_INFO);
},
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;
},
SET_CHATURL(state, chatUrl){
state.chatUrl = chatUrl;
},
// AuthorizeType(state, authorizeType){
// state.authorizeType = authorizeType;
// },
SYSTEM_PLATFORM(state, systemPlatform){
state.systemPlatform = systemPlatform;
Cache.set(PLATFORM, systemPlatform);
},
//更新useInfo数据
changInfo(state, payload) {
state.userInfo[payload.amount1] = payload.amount2;
Cache.set(USER_INFO, state.userInfo);
},
//商品类型,用于区分视频号商品与一般商品
PRODUCT_TYPE(state, productType) {
state.productType = productType;
Cache.set('productType', productType);
},
// 设置管理员账号信息
SET_ADMIN_INFO(state, adminInfo) {
state.adminInfo = adminInfo;
Cache.set(ADMIN_INFO, adminInfo);
},
// 清理管理员账号信息
CLEAR_ADMIN_INFO(state) {
state.adminInfo = null;
Cache.clear(ADMIN_INFO);
}
};
const actions = {
USERINFO({
state,
commit
}, force) {
return new Promise(reslove => {
getUserInfo().then(res => {
commit("UPDATE_USERINFO", res.data);
reslove(res.data);
});
}).catch(() => {
});
// debugger
// if (state.userInfo !== null && !force)
// return Promise.resolve(state.userInfo);
// else
// return new Promise(reslove => {
// getUserInfo().then(res => {
// commit("UPDATE_USERINFO", res.data);
// reslove(res.data);
// });
// }).catch(() => {
// });
},
// 获取管理员账号信息
ADMIN_INFO({ commit }) {
return new Promise((resolve, reject) => {
getAdminInfoByUid().then(res => {
commit("SET_ADMIN_INFO", res.data);
resolve(res.data);
}).catch(() => {
reject();
});
});
},
// 登录成功后获取管理员信息
LOGIN_ADMIN_INFO({ dispatch }) {
return new Promise((resolve, reject) => {
dispatch('ADMIN_INFO').then(res => {
resolve(res);
}).catch(() => {
// 管理员信息获取失败不影响主流程
resolve(null);
});
});
}
};
export default {
state,
mutations,
actions
};