student.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/student`,
  8. noClass: '/api/train/student/seek',
  9. bedroom: `/api/train/student/findbedroom`,
  10. removeClass: `/api/train/student/deleteclass`, //ids
  11. findscore: `/api/train/student/findscore`,
  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 update({ commit }, { id, ...data }) {
  29. const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
  30. return res;
  31. },
  32. async delete({ commit }, payload) {
  33. const res = await this.$axios.$delete(`${api.interface}/${payload}`);
  34. return res;
  35. },
  36. async noClass({ commit }, payload) {
  37. const res = await this.$axios.$get(`${api.noClass}`, payload);
  38. return res;
  39. },
  40. async bedRoom({ commit }, payload) {
  41. const res = await this.$axios.$get(`${api.bedroom}`, payload);
  42. return res;
  43. },
  44. async removeClass({ commit }, payload) {
  45. const res = await this.$axios.$post(`${api.removeClass}`, payload);
  46. return res;
  47. },
  48. async findscore({ commit }, { skip = 0, limit, ...info } = {}) {
  49. const res = await this.$axios.$get(`${api.findscore}`, { skip, limit, ...info });
  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. };