classes.js 3.1 KB

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