import { getTokenInfo } from '@/assets/utils/code.js'
export default {
    saveAccessToken (state, token) {
        state.access_token = token
        try {
            localStorage.teacherToken = token
        } catch (e) {}

        state.tokenPayload = getTokenInfo(token)
        state.tokenInfo = getTokenInfo(token, true)
        state.userInfo = { ...state.userInfo, ...state.tokenPayload, UserId: state.tokenPayload.jti }
        try {
            localStorage.teacherUserInfo = JSON.stringify(state.userInfo)
        } catch (e) {}
    },

    saveExpireTime (state, expireTime) {
        state.expireTime = expireTime
        try {
            localStorage.teacherExpireTime = expireTime
        } catch (e) {}
    },

    saveOpenId (state, openId) {
        state.openId = openId
        try {
            localStorage.storeOpenId = openId
        } catch (e) {}
    },

    saveSchoolCode (state, schoolCode) {
        state.schoolCode = schoolCode
        try {
            localStorage.storeSchoolCode = schoolCode
        } catch (e) {}
    },

    saveCompanyId (state, companyId) {
        state.companyId = companyId
        try {
            localStorage.storeCompanyId = companyId
        } catch (e) {}
    },

    // 考勤模块角色
    dailySignUserPermission (state, dailySignUserPermission) {
        state.dailySignUserPermission = dailySignUserPermission
    },
    // 教师组织架构存储
    saveTeacherOrgList (state, teacherOrgList) {
        state.teacherOrgList = teacherOrgList
        try {
            localStorage.storeTeacherOrgList = teacherOrgList
        } catch (e) {}
    },

    saveUserInfo (state, userInfo) {
        state.userInfo = userInfo
        try {
            localStorage.teacherUserInfo = JSON.stringify(userInfo)
        } catch (e) {}
    }
}
