student.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. findList: `/api/train/student/findbystuids`,
  13. deleteAll: '/api/train/student/deletestus',
  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 create({ commit }, payload) {
  23. const res = await this.$axios.$post(`${api.interface}`, payload);
  24. return res;
  25. },
  26. async fetch({ commit }, payload) {
  27. const res = await this.$axios.$get(`${api.interface}/${payload}`);
  28. return res;
  29. },
  30. async update({ commit }, { id, ...data }) {
  31. const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
  32. return res;
  33. },
  34. async delete({ commit }, payload) {
  35. const res = await this.$axios.$delete(`${api.interface}/${payload}`);
  36. return res;
  37. },
  38. async noClass({ commit }, payload) {
  39. const res = await this.$axios.$get(`${api.noClass}`, payload);
  40. return res;
  41. },
  42. async bedRoom({ commit }, payload) {
  43. const res = await this.$axios.$get(`${api.bedroom}`, payload);
  44. return res;
  45. },
  46. async removeClass({ commit }, payload) {
  47. const res = await this.$axios.$post(`${api.removeClass}`, payload);
  48. return res;
  49. },
  50. async findscore({ commit }, { skip = 0, limit, ...info } = {}) {
  51. const res = await this.$axios.$get(`${api.findscore}`, { skip, limit, ...info });
  52. return res;
  53. },
  54. async findList({ commit }, payload) {
  55. const res = await this.$axios.$post(`${api.findList}`, { data: payload });
  56. return res;
  57. },
  58. async removeAll({ commit }, payload) {
  59. const res = await this.$axios.$post(`${api.deleteAll}`, payload);
  60. return res;
  61. },
  62. async mergeRequest({ commit, dispatch }, { method, data }) {
  63. let toRequest = () => {
  64. let res = [];
  65. for (const i of data) {
  66. res.push(dispatch(method, i));
  67. }
  68. return res;
  69. };
  70. let result = await axios.all(toRequest());
  71. let newFilter = data => {
  72. let res = data.map(i => {
  73. let type = _.isArray(i);
  74. if (!type) {
  75. //fetch的多个请求 是object 将errcode为0的data取出来
  76. return _.get(i, `data`, i);
  77. } else {
  78. //query的多个请求 array 将此数据再次走这个方法
  79. return newFilter(i);
  80. }
  81. });
  82. return res;
  83. };
  84. let returns = _.flattenDeep(newFilter(result));
  85. return returns;
  86. },
  87. };
  88. export default {
  89. namespaced: true,
  90. state,
  91. mutations,
  92. actions,
  93. };