import Vue from 'vue' import Vuex, { Store } from 'vuex' import config from '@/config.js' import defaultConfig from '@/common/config.default.js' const state = { apiRoot: null, loginUser: null, loginMark: null, token: null, company: null, department: null, user: null, dataDictionary: null, pageParam: null, jumpParam: null } const mutations = { apiRoot(state, val) { state.apiRoot = val }, loginUser(state, val) { state.loginUser = val }, loginMark(state, val) { state.loginMark = val }, token(state, val) { state.token = val }, company(state, val) { state.company = val }, department(state, val) { state.department = val }, user(state, val) { state.user = val }, dataDictionary(state, val) { state.dataDictionary = val }, pageParam(state, val) { state.pageParam = val }, jumpParam(state, val) { state.jumpParam = val } } // 获取用户定义的全局变量,依次注册它们 const globalVariables = config['globalVariables'] || defaultConfig['globalVariables'] globalVariables.forEach(t => state[t] = null) globalVariables.forEach(t => mutations[t] = (state, val) => { state[t] = val }) mutations.clear = (state) => { state.loginUser = null state.token = null state.company = null state.department = null state.user = null state.dataDictionary = null state.pageParam = null state.jumpParam = null globalVariables.forEach(t => { state[t] = null }) } Vue.use(Vuex) export default new Store({ state, mutations })