student.js 3.0 KB

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