import Vue from 'vue'; import Vuex from 'vuex'; import _ from 'lodash'; import axios from 'axios'; Vue.use(Vuex); const api = { interface: `/api/train/student`, noClass: '/api/train/student/seek', bedroom: `/api/train/student/findbedroom`, removeClass: `/api/train/student/deleteclass`, //ids findscore: `/api/train/student/findscore`, findList: `/api/train/student/findbystuids`, deleteAll: '/api/train/student/deletestus', batUpdateBedroom: `/api/train/student/updatabedroom`, computedIsFine: `/api/train/student/finestudent`, export: `/api/train/student/export`, printCert: `/api/train/student/printcert`, schoolStudent: `/api/train/student/school`, }; 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 noClass({ commit }, payload) { const res = await this.$axios.$get(`${api.noClass}`, payload); return res; }, async bedRoom({ commit }, payload) { const res = await this.$axios.$get(`${api.bedroom}`, payload); return res; }, async removeClass({ commit }, payload) { const res = await this.$axios.$post(`${api.removeClass}`, payload); return res; }, async findscore({ commit }, { skip = 0, limit, ...info } = {}) { const res = await this.$axios.$get(`${api.findscore}`, { skip, limit, ...info }); return res; }, async findList({ commit }, payload) { const res = await this.$axios.$post(`${api.findList}`, { data: payload }); return res; }, async removeAll({ commit }, payload) { const res = await this.$axios.$post(`${api.deleteAll}`, payload); return res; }, async updateBedroom({ commit }, payload) { const res = await this.$axios.$post(`${api.batUpdateBedroom}`, payload); return res; }, async computedIsFine({ commit }, payload) { const res = await this.$axios.$get(`${api.computedIsFine}/${payload}`); return res; }, // 导出条件下的学生 async toExport({ commit }, payload) { const res = await this.$axios.$post(`${api.export}`, payload); return res; }, // 修改学生证书状态 async cert({ commit }, payload) { const res = await this.$axios.$post(`${api.printCert}`, { ids: payload }); return res; }, // 学校上传学生情况 async schoolStudent({ commit }, payload) { const res = await this.$axios.$get(`${api.schoolStudent}`, payload); 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, };