trainplan.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/trainplan`,
  8. notice: `/api/train/class/notice`,
  9. exportStudent: `/api/train/trainplan/exportExcel`,
  10. };
  11. const state = () => ({});
  12. const mutations = {};
  13. const actions = {
  14. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  15. const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
  16. return res;
  17. },
  18. async create({ commit }, payload) {
  19. const res = await this.$axios.$post(`${api.interface}`, payload);
  20. return res;
  21. },
  22. async fetch({ commit }, payload) {
  23. const res = await this.$axios.$get(`${api.interface}/${payload}`);
  24. return res;
  25. },
  26. async update({ commit }, { id, ...data }) {
  27. const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
  28. return res;
  29. },
  30. async delete({ commit }, payload) {
  31. const res = await this.$axios.$delete(`${api.interface}/${payload}`);
  32. return res;
  33. },
  34. async notice({ commit }, payload) {
  35. //payload是班级id的集合
  36. const res = await this.$axios.$post(`${api.notice}`, payload);
  37. return res;
  38. },
  39. //根据计划ids导出学生
  40. async exportStudents({ commit }, payload) {
  41. const res = await this.$axios.$post(`${api.exportStudent}`, { trainplanIds: payload });
  42. return res;
  43. },
  44. async mergeRequest({ commit, dispatch }, { method, data }) {
  45. let toRequest = () => {
  46. let res = [];
  47. for (const i of data) {
  48. res.push(dispatch(method, i));
  49. }
  50. return res;
  51. };
  52. let result = await axios.all(toRequest());
  53. let newFilter = data => {
  54. let res = data.map(i => {
  55. let type = _.isArray(i);
  56. if (!type) {
  57. //fetch的多个请求 是object 将errcode为0的data取出来
  58. return _.get(i, `data`, i);
  59. } else {
  60. //query的多个请求 array 将此数据再次走这个方法
  61. return newFilter(i);
  62. }
  63. });
  64. return res;
  65. };
  66. let returns = _.flattenDeep(newFilter(result));
  67. return returns;
  68. },
  69. };
  70. export default {
  71. namespaced: true,
  72. state,
  73. mutations,
  74. actions,
  75. };