dictionary.js 920 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {
  2. reqDictionary
  3. } from "@/request/api.js";
  4. import cloneDeep from 'lodash/cloneDeep'
  5. const stateReset = {
  6. dictionaryInfo: {},
  7. };
  8. const state = cloneDeep(stateReset);
  9. const getters = {};
  10. const mutations = {
  11. // 重置字典数据
  12. resetVxDictionary(state) {
  13. Object.assign(state, cloneDeep(stateReset))
  14. },
  15. // 获取数据
  16. vxDictionary(state, args) {
  17. state.dictionaryInfo[args.key] = args.data;
  18. },
  19. };
  20. const actions = {
  21. // 获取字典数据
  22. async vxDictionary({
  23. commit,
  24. state
  25. }, args) {
  26. if (state.dictionaryInfo[args.key]) {
  27. //如果存在
  28. return await Promise.resolve(state.dictionaryInfo[args.key]);
  29. } else {
  30. let result = await reqDictionary(args);
  31. commit("vxDictionary", {
  32. key: args.key,
  33. data: result
  34. });
  35. return result;
  36. }
  37. },
  38. };
  39. export default {
  40. namespaced: true,
  41. state,
  42. getters,
  43. mutations,
  44. actions,
  45. };