app.js 1.4 KB
/*
 * @Descripttion:
 * @version:
 * @Author: limin
 * @Date: 2021-06-07 14:12:32
 * @LastEditors: limin
 * @LastEditTime: 2021-07-06 12:02:21
 */
import { ssoApi } from '@/api'
import { store } from 'utils'
import util from '@/utils/util'
const state = {
  pageMeta: '',
  keepAlives: [],
  next: ''
}
const mutations = {
  SET_PAGE_META(state, meta) {
    state.pageMeta = meta
  },
  PUSH_KEEP(state, name) {
    if (!state.keepAlives.includes(name)) {
      state.keepAlives.push(name)
    }
  },
  REMOVE_KEEP(state, names) {
    state.keepAlives = state.keepAlives.reduce((arr, name) => {
      if (!names.includes(name)) {
        return arr.push(name)
      }
      return arr
    }, [])
  },
  SET_ROUTER_OBJECT(state, next) {
    state.next = next
  }

}
const actions = {
  // 设置name
  setUserInfo({ commit }, user) {
    commit('SET_USER_INFO', user)
    store.set(store.consts.USER_KEY, user)
  },
  setPageMeta({ commit }, meta) {
    document.title = meta.title
    commit('SET_PAGE_META', meta)
  },
  setLoginToken({ commit }, val) {
    commit('SET_LOGIN_TOKEN', val)
  },
  setAccountList({ commit }, list) {
    commit('SET_ACCOUNT_LIST', list)
  },
  setSessionId({ commit }, id) {
    commit('SET_SESSION_ID', id)
  },
  pushKeep({ commit }, name) {
    commit('PUSH_KEEP', name)
  },
  removeKeep({ commit }, names) {
    commit('REMOVE_KEEP', names)
  }
}
export default {
  state,
  mutations,
  actions
}