UserContext.js 1.6 KB
Newer Older
fukai committed
1
const UserContext={
fukai committed
2
    namespaced: true,
fukai committed
3 4 5 6 7 8 9
    state:{
        userName:"",
        userId:"",
        ptyCode:"",
        menu:[],
        state:"LOGOUT",
        token:"",
潘际乾 committed
10 11
        homeCellsSetting: {
            defaultCells: [],
12 13 14
            cellRows: 2,
            cellCols: 2,
            cellNames: [['QuickVisit', 'TaskStatistics'], ['CustomerAnalyse', 'NoticeAnnouncement']]
潘际乾 committed
15
        }
fukai committed
16 17 18 19 20 21 22 23 24
    },
    mutations:{
        setLoginInfo(state,info){
            state.userName = info.userName
            state.userId = info.userId
            state.ptyCode = info.ptyCode
            state.menu = info.menu
            state.state = "LOGIN"
            state.token = info.token
fukai committed
25 26 27
            window.sessionStorage.userId = info.userId
            window.sessionStorage.userName = info.userName
            window.sessionStorage.token = info.token
fukai committed
28 29 30 31 32 33 34 35
        },
        setLogout(state){
            state.userName = ""
            state.userId = ""
            state.ptyCode = ""
            state.menu = []
            state.state = "LOGOUT"
            state.token = ""
36 37 38
        },
        setMenu(state, menu) {
            state.menu = menu;
潘际乾 committed
39 40 41 42 43 44 45 46 47
        },
        setHomeCellsSetting(state, setting) {
            state.homeCellsSetting.cellRows = setting.cellRows
            state.homeCellsSetting.cellCols = setting.cellCols
            state.homeCellsSetting.cellNames = setting.cellNames
            localStorage.setItem(`cells-setting-${state.userId}`, JSON.stringify(setting));
        },
        setHomeDefaultCells(state, cells) {
            state.homeCellsSetting.defaultCells = cells;
fukai committed
48 49 50 51
        }
    }
}
export default UserContext;