question-completion.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. interface: `/api/train/uploadquestion/completion`,
  8. };
  9. const state = () => ({});
  10. const mutations = {};
  11. const actions = {
  12. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  13. // type: 0=> typeid=期id; 1 => typeid = 批次id; 2 => typeid = 班级id
  14. const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
  15. return res;
  16. },
  17. async create({ commit }, payload) {
  18. const res = await this.$axios.$post(`${api.interface}`, payload);
  19. return res;
  20. },
  21. async fetch({ commit }, payload) {
  22. const res = await this.$axios.$get(`${api.interface}/${payload}`);
  23. return res;
  24. },
  25. async update({ commit }, { id, ...data }) {
  26. const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
  27. return res;
  28. },
  29. async delete({ commit }, payload) {
  30. const res = await this.$axios.$delete(`${api.interface}/${payload}`);
  31. return res;
  32. },
  33. async mergeRequest({ commit, dispatch }, { method, data }) {
  34. let toRequest = () => {
  35. let res = [];
  36. res.push(dispatch(method, data));
  37. };
  38. let result = await axios.all(toRequest());
  39. let arr = _.flattenDeep(_.flattenDeep(result).map(item => item.data));
  40. return arr;
  41. },
  42. };
  43. export default {
  44. namespaced: true,
  45. state,
  46. mutations,
  47. actions,
  48. };