student.js 3.8 KB

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