school.js 2.1 KB

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