config.js 726 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import miscApi from '../../api/misc';
  2. // initial state
  3. const state = {
  4. name: null,
  5. version: null,
  6. mode: null,
  7. };
  8. // getters
  9. const getters = {};
  10. // actions
  11. const actions = {
  12. async loadConfig({ commit, state }) {
  13. commit('setApiError', null, { root: true });
  14. commit('setConfig', {});
  15. try {
  16. const config = await miscApi.loadConfig();
  17. commit('setConfig', config);
  18. } catch (e) {
  19. commit('setApiError', e, { root: true });
  20. }
  21. },
  22. };
  23. // mutations
  24. const mutations = {
  25. setConfig(state, value) {
  26. Object.assign(state, value);
  27. },
  28. };
  29. export default {
  30. namespaced: true,
  31. state,
  32. getters,
  33. actions,
  34. mutations
  35. };