import { createStore, createLogger } from 'vuex'; import weather from './modules/weather'; import user from './modules/user'; const debug = process.env.NODE_ENV !== 'production'; // 默认状态 const state = { websocketTimeSec: 1000, loading: false, //全局 - 加载中.... themeName: localStorage.getItem("themeName") || "dark", // 主题 menuData: [], windturbineMap: {}, moudleName: "", }; //改变状态的方法` const mutations = { loadingStore(state, tag) { state.loading = tag; }, changeTheme(state, tag) { state.themeName = tag; }, update(state, newData) { state.windturbineMap = newData.data }, changeMenuData(state, newData) { state.menuData = newData; }, changeModuleName(state, newData) { state.moudleName = newData; } }; const actions = { getupdate(context, newData) { context.commit("update", newData); }, changeTheme(context, str) { context.commit("changeTheme", str); }, changeMenuData(context, str) { context.commit("changeMenuData", str); }, changeModuleName(context, str) { context.commit("changeModuleName", str); } }; const getters = { authToken: state => state.user.authToken, //建立token的快捷访问 user 是因为index.js中导入的时候名称定义为user submitDDTag: state => state.submitDDTag, loading: state => state.loading, username: state => state.user.username, themeName: state => state.themeName, asidez: state => state.z, mainy: state => state.y, login: state => state.login, menuData: state => state.menuData } export default createStore({ modules: { weather, user }, state, mutations, actions, getters, strict: debug, plugins: debug ? [createLogger()] : [] });