classes.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/class`,
  8. divide: `/api/train/class/divide`,
  9. updateHeadTeacher: `/api/train/class/uptea`,
  10. addStudent: id => `/api/train/class/upstuclass/${id} `, //id:班级id, ids:学生ID列表
  11. teacherQuery: `/api/train/lesson/classbyteaid`,
  12. };
  13. const state = () => ({});
  14. const mutations = {};
  15. const actions = {
  16. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  17. const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
  18. return res;
  19. },
  20. async teacherQuery({ commit }, { skip = 0, limit, ...info } = {}) {
  21. const res = await this.$axios.$get(`${api.teacherQuery}`, { skip, limit, ...info });
  22. return res;
  23. },
  24. async create({ commit }, payload) {
  25. const res = await this.$axios.$post(`${api.interface}`, payload);
  26. return res;
  27. },
  28. async fetch({ commit }, payload) {
  29. const res = await this.$axios.$get(`${api.interface}/${payload}`);
  30. return res;
  31. },
  32. async update({ commit }, { id, ...data }) {
  33. const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
  34. return res;
  35. },
  36. async delete({ commit }, payload) {
  37. const res = await this.$axios.$delete(`${api.interface}/${payload}`);
  38. return res;
  39. },
  40. //分班
  41. async divide({ commit }, payload) {
  42. const res = await this.$axios.$post(`${api.divide}`, payload);
  43. return res;
  44. },
  45. //手动分班
  46. async addStudent({ commit }, { id, ids }) {
  47. const res = await this.$axios.$post(`${api.addStudent(id)}`, ids);
  48. return res;
  49. },
  50. async upHeadTea({ commit }, payload) {
  51. const res = await this.$axios.$post(`${api.updateHeadTeacher}`, payload);
  52. return res;
  53. },
  54. async mergeRequest({ commit, dispatch }, { method, data }) {
  55. let toRequest = () => {
  56. let res = [];
  57. for (const i of data) {
  58. res.push(dispatch(method, i));
  59. }
  60. return res;
  61. };
  62. let result = await axios.all(toRequest());
  63. let newFilter = data => {
  64. let res = data.map(i => {
  65. let type = _.isArray(i);
  66. if (!type) {
  67. //fetch的多个请求 是object 将errcode为0的data取出来
  68. return _.get(i, `data`, i);
  69. } else {
  70. //query的多个请求 array 将此数据再次走这个方法
  71. return newFilter(i);
  72. }
  73. });
  74. return res;
  75. };
  76. let returns = _.flattenDeep(newFilter(result));
  77. return returns;
  78. },
  79. async searchDate({ commit }, { skip = 0, limit, ...info } = {}) {
  80. const res = await this.$axios.$get(`${api.searchDate}`, { ...info });
  81. return res;
  82. },
  83. };
  84. export default {
  85. namespaced: true,
  86. state,
  87. mutations,
  88. actions,
  89. };