import { getValueByKey } from '@/api/login' import { DEFAULT_THEME_COLOR, DEFAULT_THEME_COLOR_KEY, getCookieInDomain, setCookieInDomain } from '@/utils/theme' import { getToken } from '@/utils/auth' const actions = { //获取默认主题颜色并缓存 async GetDefaultThemeColor(context) { const token = getToken() if (!token) return false const res = await getValueByKey({ configKey: 'DEFAULT_THEMECOLOR' }) // 获取 cookie 中的 themeColor const cacheThemeColor = getCookieInDomain(DEFAULT_THEME_COLOR_KEY) if (res.data) { context.commit('SET_CONFIG_THEME_COLOR', res.data) // 如果和缓存的主题色值不一致,更新主题色 if (res.data !== cacheThemeColor) { setCookieInDomain(DEFAULT_THEME_COLOR_KEY, res.data || cacheThemeColor || DEFAULT_THEME_COLOR) } } return res.data }, // 获取是否隐藏主题控件 async GetHideThemeControlStatus({ commit }) { const res = await getValueByKey({ configKey: 'HIDE_THEME_CONTROL' }) if (res.data) { commit('SET_HIDE_THEME_CONTROL', res.data) return res.data } return false } } export default actions