index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* eslint-disable no-underscore-dangle */
  2. /* eslint-disable object-curly-newline */
  3. /* eslint-disable no-param-reassign */
  4. import Vue from 'vue';
  5. import Vuex from 'vuex';
  6. import * as types from './mutation-types';
  7. import * as menu from '@/store/naf/menu';
  8. import * as dict from '@lib/store/naf/dict';
  9. import util from '@lib/utils/user-util';
  10. import * as login from './login';
  11. Vue.use(Vuex);
  12. export default new Vuex.Store({
  13. modules: {
  14. naf: {
  15. namespaced: true,
  16. modules: {
  17. menu,
  18. dict,
  19. },
  20. },
  21. login,
  22. },
  23. state: {
  24. loading: false,
  25. platform: 'school',
  26. unit: null,
  27. name: null,
  28. },
  29. getters: {
  30. platform: state => state.login.platform,
  31. isAuthenticated: state => state.login.isAuthenticated,
  32. userinfo: state => state.login.userinfo,
  33. // access_token: state => state.login.access_token,
  34. // unitcode: state => state.login.unit,
  35. menuItems: state => state.naf.menu.items,
  36. },
  37. mutations: {
  38. [types.SHOW_LOADING](state) {
  39. state.loading = true;
  40. },
  41. [types.HIDE_LOADING](state) {
  42. state.loading = false;
  43. },
  44. [types.USER_INFO](state, { userinfo }) {
  45. state.userinfo = userinfo;
  46. },
  47. [types.PLATFORM_INIT](state, { unit = 'master', name }) {
  48. state.name = name;
  49. if (unit === 'master') {
  50. state.platform = 'master';
  51. state.unit = null;
  52. } else {
  53. state.platform = 'school';
  54. state.unit = unit;
  55. }
  56. },
  57. },
  58. actions: {
  59. async load({ commit, dispatch }) {
  60. console.log('start loading data...');
  61. commit(types.SHOW_LOADING);
  62. await dispatch('naf/menu/load');
  63. await dispatch('naf/dict/load', 'unit');
  64. commit(types.HIDE_LOADING);
  65. console.log('load data ok!');
  66. },
  67. },
  68. });