util.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. };
  13. const state = () => ({});
  14. const mutations = {};
  15. const actions = {
  16. async fetch({ commit }, { skip, limit, model, ...info } = {}) {
  17. const res = await this.$axios.$get(`${api.interface(model)}`, { skip, limit, ...info });
  18. return res;
  19. },
  20. async findModel({ commit }, payload) {
  21. const res = await this.$axios.$get(`${api.findModel(payload)}`);
  22. return res;
  23. },
  24. async findIds({ commit }, { model, ids }) {
  25. const res = await this.$axios.$get(`${api.findByIds(model)}`, { data: ids });
  26. return res;
  27. },
  28. };
  29. export default {
  30. namespaced: true,
  31. state,
  32. mutations,
  33. actions,
  34. };