123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import Vue from 'vue';
- import Vuex from 'vuex';
- import _ from 'lodash';
- import axios from 'axios';
- Vue.use(Vuex);
- const api = {
- interface: `/api/train/apply`,
- apply: `/api/train/apply/queryteacher`,
- divide: `/api/train/teaplan/divide`, //query: trainplanid
- findTeacher: `/api/train/teaplan/findteacher`, //planid termid batchid
- arrange: `/api/train/apply/arrange`, //计划-安排教师
- sendmsg: `/api/train/apply/sendmsg`, //计划,给指定期安排的教师发送通知
- confirm: `/api/train/apply/confirm`, //计划,给指定期安排的教师变更为确认状态
- };
- 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 applyQuery({ commit }, { skip = 0, limit, ...info } = {}) {
- const res = await this.$axios.$get(`${api.apply}`, { skip, limit, ...info });
- return res;
- },
- async divide({ commit }, payload) {
- //payload是trainplanid
- const res = await this.$axios.$get(`${api.divide}`, payload);
- return res;
- },
- async findTeacher({ commit }, payload) {
- //payload是trainplanid
- const res = await this.$axios.$get(`${api.findTeacher}`, payload);
- return res;
- },
- // 计划-安排教师
- async arrangeTeacher({ commit }, payload) {
- const res = await this.$axios.$post(`${api.arrange}`, payload);
- return res;
- },
- // 计划-给指定期安排的教师发送通知
- async sendMsg({ commit }, { planid, ...info }) {
- const res = await this.$axios.$post(`${api.sendmsg}/${planid}`, info);
- return res;
- },
- // 计划-给指定期安排的教师确认状态
- async confirmPlan({ commit }, { planid, ...info }) {
- const res = await this.$axios.$post(`${api.confirm}/${planid}`, info);
- return res;
- },
- async mergeRequest({ commit, dispatch }, { method, data }) {
- let toRequest = () => {
- let res = [];
- for (const i of data) {
- res.push(dispatch(method, i));
- }
- return res;
- };
- let result = await axios.all(toRequest());
- let newFilter = data => {
- let res = data.map(i => {
- let type = _.isArray(i);
- if (!type) {
- //fetch的多个请求 是object 将errcode为0的data取出来
- return _.get(i, `data`, i);
- } else {
- //query的多个请求 array 将此数据再次走这个方法
- return newFilter(i);
- }
- });
- return res;
- };
- let returns = _.flattenDeep(newFilter(result));
- return returns;
- },
- };
- export default {
- namespaced: true,
- state,
- mutations,
- actions,
- };
|