bedroom.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import axios from 'axios';
  4. import _ from 'lodash';
  5. Vue.use(Vuex);
  6. const api = {
  7. interface: `/api/train/bedroom`,
  8. apart: `/api/train/bedroom/apart`,
  9. updateBat: `/api/train/bedroom/batch`,
  10. assignroom: `/api/train/bedroom/assignroom`,
  11. };
  12. const state = () => ({});
  13. const mutations = {};
  14. const actions = {
  15. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  16. const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
  17. return res;
  18. },
  19. async create({ commit }, payload) {
  20. const res = await this.$axios.$post(`${api.interface}`, payload);
  21. return res;
  22. },
  23. async fetch({ commit }, payload) {
  24. const res = await this.$axios.$get(`${api.interface}/${payload}`);
  25. return res;
  26. },
  27. async update({ commit }, { id, ...data }) {
  28. const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
  29. return res;
  30. },
  31. async delete({ commit }, payload) {
  32. const res = await this.$axios.$delete(`${api.interface}/${payload}`);
  33. return res;
  34. },
  35. async apart({ commit }, payload) {
  36. const res = await this.$axios.$post(`${api.apart}`, payload);
  37. return res;
  38. },
  39. async getClassList({ commit }, payload) {
  40. const res = await this.$axios.$get(`${api.interface}/student/${payload}`);
  41. return res;
  42. },
  43. // 批量修改寝室
  44. async updateBat({ commit }, payload) {
  45. const res = await this.$axios.$post(`${api.updateBat}`, payload);
  46. return res;
  47. },
  48. // 获取本期可以获取
  49. async getAssignRoom({ commit }, { termid }) {
  50. const res = await this.$axios.$get(`${api.assignroom}`, { termid });
  51. return res;
  52. },
  53. //还原寝室,payload:classid
  54. async restore({ commit }, payload) {
  55. const res = await this.$axios.$post(`${api.interface}/restore/${payload}`);
  56. return res;
  57. },
  58. async mergeRequest({ commit, dispatch }, { method, data }) {
  59. let toRequest = () => {
  60. let res = [];
  61. for (const i of data) {
  62. res.push(dispatch(method, i));
  63. }
  64. return res;
  65. };
  66. let result = await axios.all(toRequest());
  67. let newFilter = data => {
  68. let res = data.map(i => {
  69. let type = _.isArray(i);
  70. if (!type) {
  71. //fetch的多个请求 是object 将errcode为0的data取出来
  72. return _.get(i, `data`, i);
  73. } else {
  74. //query的多个请求 array 将此数据再次走这个方法
  75. return newFilter(i);
  76. }
  77. });
  78. return res;
  79. };
  80. let returns = _.flattenDeep(newFilter(result));
  81. return returns;
  82. },
  83. };
  84. export default {
  85. namespaced: true,
  86. state,
  87. mutations,
  88. actions,
  89. };