group.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import _ from 'lodash';
  4. import axios from 'axios';
  5. Vue.use(Vuex);
  6. const api = {
  7. groupInfo: `/api/train/group`,
  8. // insertInfo: `/api/train/group/insert`,
  9. // exitInfo: `/api/train/group/exit`,
  10. };
  11. const state = () => ({});
  12. const mutations = {};
  13. const actions = {
  14. async query({ commit }, { skip = 0, limit, termid, batchid, classid, ...info } = {}) {
  15. const res = await this.$axios.$get(`${api.groupInfo}`, { skip, limit, ...info, termid, batchid, classid });
  16. return res;
  17. },
  18. async create({ commit }, payload) {
  19. const res = await this.$axios.$post(`${api.groupInfo}`, payload);
  20. return res;
  21. },
  22. async fetch({ commit }, payload) {
  23. const res = await this.$axios.$get(`${api.groupInfo}/${payload}`);
  24. return res;
  25. },
  26. async update({ commit }, { id, ...data }) {
  27. const res = await this.$axios.$post(`${api.groupInfo}/update/${id}`, data);
  28. return res;
  29. },
  30. async delete({ commit }, payload) {
  31. const res = await this.$axios.$delete(`${api.groupInfo}/${payload}`);
  32. return res;
  33. },
  34. async insert({ commit }, payload) {
  35. const res = await this.$axios.$post(`${api.groupInfo}/insert`, payload);
  36. return res;
  37. },
  38. async exit({ commit }, payload) {
  39. const res = await this.$axios.$post(`${api.groupInfo}/exit`, payload);
  40. return res;
  41. },
  42. async mergeRequest({ commit, dispatch }, { method, data }) {
  43. let toRequest = () => {
  44. let res = [];
  45. res.push(dispatch(method, data));
  46. };
  47. let result = await axios.all(toRequest());
  48. let arr = _.flattenDeep(_.flattenDeep(result).map(item => item.data));
  49. return arr;
  50. },
  51. };
  52. export default {
  53. namespaced: true,
  54. state,
  55. mutations,
  56. actions,
  57. };