vuex_helpers.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { defineAsyncComponent } from "vue";
  2. const mapModalState = (namespace, map) => {
  3. const modalState = {};
  4. Object.entries(map).forEach(([mapKey, mapValue]) => {
  5. modalState[mapKey] = function func() {
  6. return mapValue(
  7. namespace
  8. .replace("MODAL_MODULE_PATH", this.modalModulePath)
  9. .replace("MODAL_UUID", this.modalUuid)
  10. .split("/")
  11. .reduce((a, b) => a[b], this.$store.state)
  12. );
  13. };
  14. });
  15. return modalState;
  16. };
  17. const mapModalActions = (namespace, map) => {
  18. const modalState = {};
  19. map.forEach(mapValue => {
  20. modalState[mapValue] = function func(value) {
  21. return this.$store.dispatch(
  22. `${namespace
  23. .replace("MODAL_MODULE_PATH", this.modalModulePath)
  24. .replace("MODAL_UUID", this.modalUuid)}/${mapValue}`,
  25. value
  26. );
  27. };
  28. });
  29. return modalState;
  30. };
  31. const mapModalComponents = (baseDirectory, map) => {
  32. const modalComponents = {};
  33. Object.entries(map).forEach(([mapKey, mapValue]) => {
  34. modalComponents[mapKey] = () =>
  35. defineAsyncComponent(() => import(`${baseDirectory}/${mapValue}`));
  36. });
  37. return modalComponents;
  38. };
  39. export { mapModalState, mapModalActions, mapModalComponents };