util.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //这个js是查询单条的工具接口,因为不是所有查询单条的情况都有id
  2. //可能用几个条件就可以确定数据的唯一性,所以有这个接口
  3. import Vue from 'vue';
  4. import Vuex from 'vuex';
  5. import _ from 'lodash';
  6. import axios from 'axios';
  7. Vue.use(Vuex);
  8. const api = {
  9. interface: modelname => `/api/train/common/findone/${modelname}`,
  10. findModel: model => `/api/train/common/findbymodel?modelname=${model}`,
  11. findByIds: model => `/api/train/common/findbyids/${model}`,
  12. util: `/api/train/util`,
  13. taskupload: `/files/task/upload`,
  14. exportExcel: `/api/train/exportExcel`,
  15. schoolDownload: `/api/train/schoolDownload`,
  16. schoolImport: `/api/train/schoolImport`,
  17. stuImport: `/api/train/stuImport`,
  18. };
  19. const state = () => ({});
  20. const mutations = {};
  21. const actions = {
  22. async fetch({ commit }, { skip, limit, model, ...info } = {}) {
  23. const res = await this.$axios.$get(`${api.interface(model)}`, { skip, limit, ...info });
  24. return res;
  25. },
  26. async findModel({ commit }, payload) {
  27. const res = await this.$axios.$get(`${api.findModel(payload)}`);
  28. return res;
  29. },
  30. async findIds({ commit }, { model, ids }) {
  31. const res = await this.$axios.$get(`${api.findByIds(model)}`, { data: ids });
  32. return res;
  33. },
  34. async utilMethod({ commit }, payload) {
  35. const res = await this.$axios.$post(`${api.util}`, payload);
  36. },
  37. async exportExcel({ commit }, payload) {
  38. const res = await this.$axios.$post(`${api.exportExcel}`, payload);
  39. return res;
  40. },
  41. async schoolDownload({ commit }, payload) {
  42. const res = await this.$axios.$post(`${api.schoolDownload}`, payload);
  43. return res;
  44. },
  45. async schoolImport({ commit }, payload) {
  46. const res = await this.$axios.$post(`${api.schoolImport}`, { filepath: payload });
  47. return res;
  48. },
  49. async stuImport({ commit }, payload) {
  50. const res = await this.$axios.$post(`${api.stuImport}`, payload);
  51. return res;
  52. },
  53. async upload({ commit }, { file, uri }) {
  54. // const res = await this.$axios.$post(`${api.taskupload}`, payload, null, { 'Content-Type': 'multipart/form-data' });
  55. let param = new FormData(); //创建form对象
  56. param.append('file', file); //通过append向form对象添加数据
  57. const config = {
  58. headers: { 'Content-Type': 'multipart/form-data' },
  59. };
  60. const res = await axios.post(`${uri}`, param, config);
  61. return res;
  62. },
  63. };
  64. export default {
  65. namespaced: true,
  66. state,
  67. mutations,
  68. actions,
  69. };