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