attendance.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. checkInfo: `/api/train/attendance`,
  8. };
  9. const state = () => ({});
  10. const mutations = {};
  11. const actions = {
  12. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  13. const res = await this.$axios.$get(`${api.checkInfo}`, { skip, limit, ...info });
  14. return res;
  15. },
  16. async create({ commit }, payload) {
  17. const res = await this.$axios.$post(`${api.checkInfo}`, payload);
  18. return res;
  19. },
  20. async fetch({ commit }, payload) {
  21. const res = await this.$axios.$get(`${api.checkInfo}/${payload}`);
  22. return res;
  23. },
  24. async update({ commit }, { id, ...data }) {
  25. const res = await this.$axios.$post(`${api.checkInfo}/update/${id}`, data);
  26. return res;
  27. },
  28. async delete({ commit }, payload) {
  29. const res = await this.$axios.$delete(`${api.checkInfo}/${payload}`);
  30. return res;
  31. },
  32. async mergeRequest({ commit, dispatch }, { method, data }) {
  33. let toRequest = () => {
  34. let res = [];
  35. for (const i of data) {
  36. res.push(dispatch(method, i));
  37. }
  38. return res;
  39. };
  40. let result = await axios.all(toRequest());
  41. let newFilter = data => {
  42. let res = data.map(i => {
  43. let type = _.isArray(i);
  44. if (!type) {
  45. //fetch的多个请求 是object 将errcode为0的data取出来
  46. return _.get(i, `data`, i);
  47. } else {
  48. //query的多个请求 array 将此数据再次走这个方法
  49. return newFilter(i);
  50. }
  51. });
  52. return res;
  53. };
  54. let returns = _.flattenDeep(newFilter(result));
  55. return returns;
  56. },
  57. // 特殊班考勤管理
  58. async attendancecreateList({ commit }, payload) {
  59. const res = await this.$axios.$post(`${api.checkInfo}/attendancecreateList`, { studentIds: payload });
  60. return res;
  61. },
  62. };
  63. export default {
  64. namespaced: true,
  65. state,
  66. mutations,
  67. actions,
  68. };