/* * @Author: 张嘉彬 * @Date: 2021-10-13 15:15:36 * @Description: */ import Cookie from 'js-cookie' import flat from '../utils/flat' import { initGlobalState } from 'qiankun' // 跨域认证信息 header 名 const xsrfHeaderName = 'Authorization' export default { // 存储token setToken(state, data) { state.token = data.token state.expireAt = new Date(new Date().getTime() + 240 * 60 * 1000) Cookie.set(xsrfHeaderName, data.token, { expires: state.expireAt }) }, // 清除token logout(state, token) { state.token = '' Cookie.remove(xsrfHeaderName) Cookie.remove('systemAuthIds') Cookie.remove('isMenuAuth') Cookie.remove('authInfo') localStorage.removeItem('userInfo') window.sessionStorage.removeItem('routerHistory') state.routerHistory = [] state.userTree = [] state.userTreeFlat = [] }, // 设置按钮样式 setBtnStyle(state, val) { const obj = val || { type: 'text', size: '' } localStorage.setItem('btnStyleVal', JSON.stringify(obj)) state.btnStyleVal = obj initGlobalState(state.btnStyleVal) // qiankun微服务 实时更新子应用 }, // 设置内容区域高度 getMainContainerHeight(state, height) { state.mainContainerHeight = height }, setRouterHistory(state, routerHistory) { state.routerHistory = routerHistory window.sessionStorage.setItem('routerHistory', JSON.stringify(routerHistory)) }, // 保存用户路由列表 setUserTree(state, userTree) { state.userTree = userTree state.userTreeFlat = flat(userTree) }, setUserInfo(state, userInfo) { state.userInfo = userInfo localStorage.setItem('userInfo', JSON.stringify(userInfo)) }, setNoReadMsgCount(state, count) { state.noReadMsgCount = count } }