12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- //这个js是查询单条的工具接口,因为不是所有查询单条的情况都有id
- //可能用几个条件就可以确定数据的唯一性,所以有这个接口
- import Vue from 'vue';
- import Vuex from 'vuex';
- import _ from 'lodash';
- import axios from 'axios';
- Vue.use(Vuex);
- const api = {
- interface: modelname => `/api/train/common/findone/${modelname}`,
- findModel: model => `/api/train/common/findbymodel?modelname=${model}`,
- findByIds: model => `/api/train/common/findbyids/${model}`,
- util: `/api/train/util`,
- taskupload: `/files/task/upload`,
- exportExcel: `/api/train/exportExcel`,
- schoolDownload: `/api/train/schoolDownload`,
- schoolImport: `/api/train/schoolImport`,
- stuImport: `/api/train/stuImport`,
- };
- const state = () => ({});
- const mutations = {};
- const actions = {
- async fetch({ commit }, { skip, limit, model, ...info } = {}) {
- const res = await this.$axios.$get(`${api.interface(model)}`, { skip, limit, ...info });
- return res;
- },
- async findModel({ commit }, payload) {
- const res = await this.$axios.$get(`${api.findModel(payload)}`);
- return res;
- },
- async findIds({ commit }, { model, ids }) {
- const res = await this.$axios.$get(`${api.findByIds(model)}`, { data: ids });
- return res;
- },
- async utilMethod({ commit }, payload) {
- const res = await this.$axios.$post(`${api.util}`, payload);
- },
- async exportExcel({ commit }, payload) {
- const res = await this.$axios.$post(`${api.exportExcel}`, payload);
- return res;
- },
- async schoolDownload({ commit }, payload) {
- const res = await this.$axios.$post(`${api.schoolDownload}`, payload);
- return res;
- },
- async schoolImport({ commit }, payload) {
- const res = await this.$axios.$post(`${api.schoolImport}`, { filepath: payload });
- return res;
- },
- async stuImport({ commit }, payload) {
- const res = await this.$axios.$post(`${api.stuImport}`, payload);
- return res;
- },
- async upload({ commit }, { file, uri }) {
- // const res = await this.$axios.$post(`${api.taskupload}`, payload, null, { 'Content-Type': 'multipart/form-data' });
- let param = new FormData(); //创建form对象
- param.append('file', file); //通过append向form对象添加数据
- const config = {
- headers: { 'Content-Type': 'multipart/form-data' },
- };
- const res = await axios.post(`${uri}`, param, config);
- return res;
- },
- };
- export default {
- namespaced: true,
- state,
- mutations,
- actions,
- };
|