notice.js 1.8 KB

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