classes.js 2.9 KB

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