setting.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import _ from 'lodash';
  4. // import axios from 'axios';
  5. import AxiosWrapper from '../utils/axios-wrapper';
  6. Vue.use(Vuex);
  7. const api = {
  8. interface: `/api/train/setting/findone`,
  9. update: id => `/api/train/setting/update/${id}`,
  10. termlist: `/api/train/setting/termlist`,
  11. };
  12. const state = () => ({});
  13. const mutations = {};
  14. const actions = {
  15. async create({ commit }, payload) {
  16. const res = await this.$axios.$post(`${api.interface}`, payload);
  17. return res;
  18. },
  19. async fetch({ commit }, payload) {
  20. const axios = new AxiosWrapper({ baseUrl: process.env.VUE_APP_AXIOS_BASE_URL, unwrap: true });
  21. const res = await axios.$get(api.interface);
  22. if (res.errcode == 0) {
  23. commit('setDefOpt', res.data, { root: true });
  24. return res;
  25. }
  26. },
  27. async checkCache({ rootState, commit, dispatch }) {
  28. let res = commit('setDefOpt', null, { root: true });
  29. dispatch('fetch');
  30. },
  31. async update({ commit }, { id, ...data }) {
  32. const res = await this.$axios.$post(`${api.update(id)}`, data);
  33. if (res.errcode == '0') {
  34. commit('setDefOpt', res.data, { root: true });
  35. }
  36. return res;
  37. },
  38. async termList() {
  39. const res = await this.$axios.$get(`${api.termlist}`);
  40. return res;
  41. },
  42. };
  43. export default {
  44. namespaced: true,
  45. state,
  46. mutations,
  47. actions,
  48. };