vuex_helpers.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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(
  9. "MODAL_MODULE_PATH",
  10. namespace.indexOf("MODAL_MODULE_PATH") !== -1
  11. ? this.modalModulePath
  12. : null
  13. )
  14. .replace("MODAL_UUID", this.modalUuid)
  15. .split("/")
  16. .reduce((a, b) => a[b], this.$store.state)
  17. );
  18. };
  19. });
  20. return modalState;
  21. };
  22. const mapModalActions = (namespace, map) => {
  23. const modalState = {};
  24. map.forEach(mapValue => {
  25. modalState[mapValue] = function func(value) {
  26. return this.$store.dispatch(
  27. `${namespace
  28. .replace(
  29. "MODAL_MODULE_PATH",
  30. namespace.indexOf("MODAL_MODULE_PATH") !== -1
  31. ? this.modalModulePath
  32. : null
  33. )
  34. .replace("MODAL_UUID", this.modalUuid)}/${mapValue}`,
  35. value
  36. );
  37. };
  38. });
  39. return modalState;
  40. };
  41. const mapModalComponents = (baseDirectory, map) => {
  42. const modalComponents = {};
  43. Object.entries(map).forEach(([mapKey, mapValue]) => {
  44. modalComponents[mapKey] = () =>
  45. defineAsyncComponent(() => import(`${baseDirectory}/${mapValue}`));
  46. });
  47. return modalComponents;
  48. };
  49. export { mapModalState, mapModalActions, mapModalComponents };