import _config from '@/config' import { getButtonAuth, getMenuCornersNum } from '@/api/menu' import { checkIsCollect } from '@/api/collect' import { findTenantDefind } from '@/api/login' import { getUserInfo } from '@/utils/auth' import { AxiosResponse } from 'axios' declare const window: any const actions = { ToggleSideBar: ({ commit }) => { commit('TOGGLE_SIDEBAR') }, CloseSideBar({ commit }, { withoutAnimation }) { commit('CLOSE_SIDEBAR', withoutAnimation) }, ToggleDevice({ commit }, device) { commit('TOGGLE_DEVICE', device) }, setActiveMenuId({ commit }, { menuId }) { if (!menuId) { commit('SET_ACTIVE_MENUID', '') return } commit('SET_ACTIVE_MENUID', menuId) }, async setAuthBTN({ commit }, { menuId }) { if (!menuId) { commit('BTNAUTH', []) sessionStorage.setItem('btnAuthList', JSON.stringify([])) return } commit('importTemplate', []) //设置按钮权限 const res:AxiosResponse = await getButtonAuth(menuId) if (res.code !== 800 || !res.data) return sessionStorage.setItem('btnAuthList', JSON.stringify(res.data)) commit('BTNAUTH', res.data) }, getCollectStatus({ commit }, menuData) { checkIsCollect({ menuId: menuData.menuId, params: JSON.stringify(menuData.query) }).then(res => { if (res.code === 800) { commit('CollectStatus', { data: res.data, menuId: menuData.menuId }) } }) }, setActiveRoute({ commit }, route) { commit('SET_ACTIVE_ROUTE', route) }, SetSystemSetting({ commit }) { // 图标默认值 let href = `${window.VUE_CDN_HOST}img/boostrap/system_management_icon.png`; // 系统Logo默认值 let systemLogo = `${window.VUE_CDN_HOST}img/boostrap/logo1.png` // 创建浏览器图标标签 const link = document.createElement('link') link.rel = 'shortcut icon' link.type = 'image/x-icon' // 取浏览器缓存 const systemSetting = localStorage.getItem('systemSetting') let setting = JSON.parse(systemSetting) || {} if (setting && setting.iconUrl) { href = setting.iconUrl } // 是否有用户数据缓存 const userInfo = getUserInfo() console.log(JSON.parse(systemSetting), typeof JSON.parse(systemSetting), '-----'); if (!userInfo) { console.log(systemSetting, 'hhh'); link.href = href document.head.appendChild(link) // commit('SET_SYSTEM_SETTING', systemSetting) return } // 请求系统配置 const params = { systemCode: _config.systemCode, tenantId: userInfo.tenantId } findTenantDefind(params).then(res => { const data = res.data || {}; commit('SET_SYSTEM_SETTING', JSON.stringify({ ...data, systemLogo: data.systemLogo || systemLogo } || setting)) // 设置浏览器标签页图标 link.href = data.iconUrl || href document.head.appendChild(link) }).catch(() => { commit('SET_SYSTEM_SETTING', JSON.stringify({ ...setting, systemLogo: setting.systemLogo || systemLogo })) link.href = href document.head.appendChild(link) }) }, setMessageCount({ commit }, msgInfo) { commit('SET_MESSAGE_COUNT', msgInfo) }, setFullscreenGlobal({ commit }, isFull) { commit('SET_FULLSCREEN', isFull) commit('SET_COLLECT_BUTTON_STATUS', !isFull) }, getMenuCornersNumData({ commit ,state }) { // keys 有值的时候进行请求处理 if(state.cornerKeys && state.cornerKeys.length > 0){ const data = { params: { keys: state.cornerKeys } } // api getMenuCornersNum(data).then((res) => { if (res.code == 800) { commit('SET_CORNERKEYSNUM', res.data.nums) } }) } } } export default actions