question-completion.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. for (const i of data) {
  37. res.push(dispatch(method, i));
  38. }
  39. return res;
  40. };
  41. let result = await axios.all(toRequest());
  42. let newFilter = data => {
  43. let res = data.map(i => {
  44. let type = _.isArray(i);
  45. if (!type) {
  46. //fetch的多个请求 是object 将errcode为0的data取出来
  47. return _.get(i, `data`, i);
  48. } else {
  49. //query的多个请求 array 将此数据再次走这个方法
  50. return newFilter(i);
  51. }
  52. });
  53. return res;
  54. };
  55. let returns = _.flattenDeep(newFilter(result));
  56. return returns;
  57. },
  58. };
  59. export default {
  60. namespaced: true,
  61. state,
  62. mutations,
  63. actions,
  64. };