school.js 2.5 KB

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