uploadtask.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/uploadtask`,
  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.interface}`, { skip, limit, ...info });
  14. return res;
  15. },
  16. async create({ commit }, payload) {
  17. const res = await this.$axios.$post(`${api.interface}`, payload);
  18. return res;
  19. },
  20. async fetch({ commit }, payload) {
  21. const res = await this.$axios.$get(`${api.interface}/${payload}`);
  22. return res;
  23. },
  24. async update({ commit }, { id, ...data }) {
  25. const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
  26. return res;
  27. },
  28. async delete({ commit }, payload) {
  29. const res = await this.$axios.$delete(`${api.interface}/${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. };
  39. let result = await axios.all(toRequest());
  40. let newFilter = data => {
  41. let res = data.map(i => {
  42. let type = _.isArray(i);
  43. if (!type) {
  44. //fetch的多个请求 是object 将errcode为0的data取出来
  45. return _.get(i, `data`, i);
  46. } else {
  47. //query的多个请求 array 将此数据再次走这个方法
  48. return newFilter(i);
  49. }
  50. });
  51. return res;
  52. };
  53. let returns = _.flattenDeep(newFilter(result));
  54. return returns;
  55. },
  56. };
  57. export default {
  58. namespaced: true,
  59. state,
  60. mutations,
  61. actions,
  62. };