index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { createStore, createLogger } from 'vuex';
  2. import weather from './modules/weather';
  3. import user from './modules/user';
  4. const debug = process.env.NODE_ENV !== 'production';
  5. // 默认状态
  6. const state = {
  7. websocketTimeSec: 1000,
  8. loading: false, //全局 - 加载中....
  9. themeName: localStorage.getItem("themeName") || "dark", // 主题
  10. menuData: [],
  11. windturbineMap: {},
  12. moudleName: "",
  13. };
  14. //改变状态的方法`
  15. const mutations = {
  16. loadingStore(state, tag) {
  17. state.loading = tag;
  18. },
  19. changeTheme(state, tag) {
  20. state.themeName = tag;
  21. },
  22. update(state, newData) {
  23. state.windturbineMap = newData.data
  24. },
  25. changeMenuData(state, newData) {
  26. state.menuData = newData;
  27. },
  28. changeModuleName(state, newData) {
  29. state.moudleName = newData;
  30. }
  31. };
  32. const actions = {
  33. getupdate(context, newData) {
  34. context.commit("update", newData);
  35. },
  36. changeTheme(context, str) {
  37. context.commit("changeTheme", str);
  38. },
  39. changeMenuData(context, str) {
  40. context.commit("changeMenuData", str);
  41. },
  42. changeModuleName(context, str) {
  43. context.commit("changeModuleName", str);
  44. }
  45. };
  46. const getters = {
  47. authToken: state => state.user.authToken, //建立token的快捷访问 user 是因为index.js中导入的时候名称定义为user
  48. submitDDTag: state => state.submitDDTag,
  49. loading: state => state.loading,
  50. username: state => state.user.username,
  51. themeName: state => state.themeName,
  52. asidez: state => state.z,
  53. mainy: state => state.y,
  54. login: state => state.login,
  55. menuData: state => state.menuData
  56. }
  57. export default createStore({
  58. modules: {
  59. weather,
  60. user
  61. },
  62. state,
  63. mutations,
  64. actions,
  65. getters,
  66. strict: debug,
  67. plugins: debug ? [createLogger()] : []
  68. });