index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. };
  13. //改变状态的方法
  14. const mutations = {
  15. loadingStore(state, tag) {
  16. state.loading = tag;
  17. },
  18. changeTheme(state, tag) {
  19. state.themeName = tag;
  20. },
  21. update(state, newData) {
  22. state.windturbineMap = newData.data
  23. },
  24. changeMenuData(state, newData) {
  25. state.menuData = newData;
  26. }
  27. };
  28. const actions = {
  29. getupdate(context, newData) {
  30. context.commit("update", newData);
  31. },
  32. changeTheme(context, str) {
  33. context.commit("changeTheme", str);
  34. },
  35. changeMenuData(context, str) {
  36. context.commit("changeMenuData", str);
  37. }
  38. };
  39. const getters = {
  40. authToken: state => state.user.authToken, //建立token的快捷访问 user 是因为index.js中导入的时候名称定义为user
  41. submitDDTag: state => state.submitDDTag,
  42. loading: state => state.loading,
  43. username: state => state.user.username,
  44. themeName: state => state.themeName,
  45. asidez: state => state.z,
  46. mainy: state => state.y,
  47. login: state => state.login,
  48. menuData: state => state.menuData
  49. }
  50. export default createStore({
  51. modules: {
  52. weather,
  53. user
  54. },
  55. state,
  56. mutations,
  57. actions,
  58. getters,
  59. strict: debug,
  60. plugins: debug ? [createLogger()] : []
  61. });