dictionary.js 804 B

123456789101112131415161718192021222324252627282930313233
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import _ from 'lodash';
  4. Vue.use(Vuex);
  5. const api = {
  6. dictionary: type => `/api/code/${type}/items`, //type === xzqh:query:level(1/2);parent(无/code)
  7. };
  8. const state = () => ({});
  9. const mutations = {};
  10. const actions = {
  11. // 字典表
  12. async dicOperation({ state }, type) {
  13. let result;
  14. if (!_.isObject(type)) {
  15. result = await this.$axios.$get(api.dictionary(type));
  16. } else {
  17. let { level, parent, name } = type;
  18. if (name) {
  19. result = await this.$axios.$get(api.findOne, {}, { name: name });
  20. } else {
  21. result = await this.$axios.$get(api.dictionary(type), { level: level, parent: parent });
  22. }
  23. }
  24. return result;
  25. },
  26. };
  27. export default {
  28. namespaced: true,
  29. state,
  30. mutations,
  31. actions,
  32. };