cyywl_server/yudao-ui-app/store/modules/app.js

147 lines
3.2 KiB
JavaScript
Raw Normal View History

2023-05-15 10:12:22 +08:00
import {
getUserInfo
} from "../../api/user.js";
import {
LOGIN_STATUS,
2023-05-16 18:00:52 +08:00
REFRESH_TOKEN,
2023-05-15 10:12:22 +08:00
UID,
2023-05-18 14:56:38 +08:00
TENANT_ID,
IS_PROPERTY,
2023-05-18 18:07:27 +08:00
OPEN_ID,
2023-05-19 17:34:57 +08:00
SPREAD_ID,
2023-05-15 10:12:22 +08:00
PLATFORM
} from '../../config/cache';
import Cache from '../../utils/cache';
import {
2023-05-19 11:25:26 +08:00
USER_INFO,
TENANT_INFO
2023-05-15 10:12:22 +08:00
} from '../../config/cache';
const state = {
token: Cache.get(LOGIN_STATUS) || '',
2023-05-16 18:00:52 +08:00
refreshToken: Cache.get(REFRESH_TOKEN) || '',
2023-05-15 10:12:22 +08:00
backgroundColor: "#fff",
userInfo: Cache.get(USER_INFO)?JSON.parse(Cache.get(USER_INFO)):null,
2023-05-19 11:25:26 +08:00
tenantInfo: Cache.get(TENANT_INFO)?JSON.parse(Cache.get(TENANT_INFO)):null,
2023-05-15 10:12:22 +08:00
uid: Cache.get(UID) || null,
2023-05-18 14:56:38 +08:00
tenantId: Cache.get(TENANT_ID) || '',
2023-05-19 17:34:57 +08:00
spreadId: Cache.get(SPREAD_ID) || '',
2023-05-18 18:07:27 +08:00
openId: Cache.get(OPEN_ID) || '',
isProperty: false,
2023-05-15 10:12:22 +08:00
homeActive: false,
chatUrl: Cache.get('chatUrl') || '',
systemPlatform: Cache.get(PLATFORM)?Cache.get(PLATFORM):'',
productType: Cache.get('productType') || ''
};
const mutations = {
LOGIN(state, opt) {
state.token = opt.token;
2023-05-16 18:00:52 +08:00
state.refreshToken = opt.refreshToken;
2023-05-15 10:12:22 +08:00
Cache.set(LOGIN_STATUS, opt.token);
2023-05-16 18:00:52 +08:00
Cache.set(REFRESH_TOKEN, opt.refreshToken);
2023-05-15 10:12:22 +08:00
},
2023-05-19 11:25:26 +08:00
SET_TENANT_INFO(state,val){
state.tenantInfo = val
Cache.set(TENANT_INFO, val);
},
2023-05-16 18:00:52 +08:00
SETUID(state,val){
2023-05-15 10:12:22 +08:00
state.uid = val;
Cache.set(UID, val);
},
2023-05-18 14:56:38 +08:00
SET_TENANTID(state,val){
state.tenantId = val;
Cache.set(TENANT_ID, val);
2023-05-18 18:07:27 +08:00
},
SET_SPREADID(state, val){
state.spreadId = val;
2023-05-19 17:34:57 +08:00
Cache.set(SPREAD_ID, val);
2023-05-18 18:07:27 +08:00
},
SET_OPENID(state, val){
state.openId = val;
Cache.set(OPEN_ID, val);
2023-05-18 14:56:38 +08:00
},
2023-05-15 10:12:22 +08:00
UPDATE_LOGIN(state, token) {
state.token = token;
},
SET_IS_PROPERTY(state, value){
state.isProperty = value
},
2023-05-15 10:12:22 +08:00
LOGOUT(state) {
state.token = undefined;
state.uid = undefined
Cache.clear(LOGIN_STATUS);
2023-05-16 18:00:52 +08:00
Cache.clear(REFRESH_TOKEN);
2023-05-15 10:12:22 +08:00
Cache.clear(UID);
Cache.clear(USER_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);
}
};
const actions = {
USERINFO({
state,
commit
}, force) {
return new Promise(reslove => {
getUserInfo().then(res => {
commit("UPDATE_USERINFO", res.data);
reslove(res.data);
});
}).catch(() => {
2023-05-16 18:00:52 +08:00
2023-05-15 10:12:22 +08:00
});
// 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(() => {
// });
}
};
export default {
state,
mutations,
actions
};