notice.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 resend({ commit }, payload) {
  35. const res = await this.$axios.$post(`${api.noticeInfo}/resend`, payload);
  36. return res;
  37. },
  38. async mergeRequest({ commit, dispatch }, { method, data }) {
  39. let toRequest = () => {
  40. let res = [];
  41. for (const i of data) {
  42. res.push(dispatch(method, i));
  43. }
  44. return res;
  45. };
  46. let result = await axios.all(toRequest());
  47. let newFilter = data => {
  48. let res = data.map(i => {
  49. let type = _.isArray(i);
  50. if (!type) {
  51. //fetch的多个请求 是object 将errcode为0的data取出来
  52. return _.get(i, `data`, i);
  53. } else {
  54. //query的多个请求 array 将此数据再次走这个方法
  55. return newFilter(i);
  56. }
  57. });
  58. return res;
  59. };
  60. let returns = _.flattenDeep(newFilter(result));
  61. return returns;
  62. },
  63. };
  64. export default {
  65. namespaced: true,
  66. state,
  67. mutations,
  68. actions,
  69. };