teacher.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/teacher`,
  8. status: `/api/train/teacher/status`,
  9. scoreimport: `/api/train/teacher/teaimport`, //filepath
  10. teacherLesson: `/api/train/teacher/fetchteachers`,
  11. checkArrange: `/api/train/teacher/checkarrange`,
  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 create({ commit }, payload) {
  21. const res = await this.$axios.$post(`${api.interface}`, payload);
  22. return res;
  23. },
  24. async fetch({ commit }, payload) {
  25. const res = await this.$axios.$get(`${api.interface}/${payload}`);
  26. return res;
  27. },
  28. async lessonteafetch({ commit }, ids) {
  29. const res = await this.$axios.$post(`${api.teacherLesson}`, { ids });
  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. async status({ commit }, payload) {
  41. const res = await this.$axios.$post(`${api.status}`, payload);
  42. return res;
  43. },
  44. async scoreImport({ commit }, payload) {
  45. const res = await this.$axios.$post(`${api.scoreimport}`, { filepath: payload });
  46. return res;
  47. },
  48. async checkArrange({ commit }, payload) {
  49. const res = await this.$axios.$get(`${api.checkArrange}`, payload);
  50. return res;
  51. },
  52. async mergeRequest({ commit, dispatch }, { method, data }) {
  53. let toRequest = () => {
  54. let res = [];
  55. for (const i of data) {
  56. res.push(dispatch(method, i));
  57. }
  58. return res;
  59. };
  60. let result = await axios.all(toRequest());
  61. let newFilter = data => {
  62. let res = data.map(i => {
  63. let type = _.isArray(i);
  64. if (!type) {
  65. //fetch的多个请求 是object 将errcode为0的data取出来
  66. return _.get(i, `data`, i);
  67. } else {
  68. //query的多个请求 array 将此数据再次走这个方法
  69. return newFilter(i);
  70. }
  71. });
  72. return res;
  73. };
  74. let returns = _.flattenDeep(newFilter(result));
  75. return returns;
  76. },
  77. };
  78. export default {
  79. namespaced: true,
  80. state,
  81. mutations,
  82. actions,
  83. };