init.js 1.03 KB
import { utils } from 'glsx-common'
import { constants } from '@/common'
const modulesFiles = require.context('.', true, /\.js$/).keys()
const init = {
  namespaced: true,
  actions: {
    async init({ dispatch }) {
      // 获取页面持久化数据
      const currentPage = utils.storage.getSession(constants.SCRM_BASE_CURRENTPAGE)
      currentPage && (await dispatch('app/setCurrentPage', currentPage, { root: true }))
      const sessionInfo = utils.storage.getSession(constants.SCRM_BASE_SESSIONINFO)
      sessionInfo && (await dispatch('auth/setSessionInfo', sessionInfo, { root: true }))
      const menuList = utils.storage.getSession(constants.SCRM_BASE_MENULIST)
      menuList && (await dispatch('app/persisted', { data: menuList, isWithModuleName: false }, { root: true }))
    },
    reset({ dispatch }) {
      modulesFiles.forEach(modulePath => {
        const module = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
        module !== 'init' && dispatch(`${module}/clear`, null, { root: true })
      })
    }
  }
}
export default init