student.js 3.6 KB

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