student.js 3.4 KB

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