123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import Vue from 'vue';
- import Vuex from 'vuex';
- import _ from 'lodash';
- import axios from 'axios';
- Vue.use(Vuex);
- const api = {
- interface: `/api/train/class`,
- divide: `/api/train/class/divide`,
- };
- const state = () => ({});
- const mutations = {};
- const actions = {
- async query({ commit }, { skip = 0, limit, ...info } = {}) {
- const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
- return res;
- },
- async create({ commit }, payload) {
- const res = await this.$axios.$post(`${api.interface}`, payload);
- return res;
- },
- async fetch({ commit }, payload) {
- const res = await this.$axios.$get(`${api.interface}/${payload}`);
- return res;
- },
- async update({ commit }, { id, ...data }) {
- const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
- return res;
- },
- async delete({ commit }, payload) {
- const res = await this.$axios.$delete(`${api.interface}/${payload}`);
- return res;
- },
- //分班
- async divide({ commit }, payload) {
- const res = await this.$axios.$post(`${api.divide}`, payload);
- return res;
- },
- async mergeRequest({ commit, dispatch }, { method, data }) {
- let toRequest = () => {
- let res = [];
- res.push(dispatch(method, data));
- };
- let result = await axios.all(toRequest());
- let arr = _.flattenDeep(_.flattenDeep(result).map(item => item.data));
- return arr;
- },
- };
- export default {
- namespaced: true,
- state,
- mutations,
- actions,
- };
|