student.js 3.2 KB

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