index.js 1.3 KB

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