vuex_helpers.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { defineAsyncComponent } from "vue";
  2. const mapModalState = (namespace, map) => {
  3. const modalState = {};
  4. // console.log("MAP MODAL STATE", namespace);
  5. Object.entries(map).forEach(([mapKey, mapValue]) => {
  6. modalState[mapKey] = function func() {
  7. // console.log(
  8. // 321,
  9. // namespace
  10. // .replace(
  11. // "MODAL_MODULE_PATH",
  12. // namespace.indexOf("MODAL_MODULE_PATH") !== -1
  13. // ? this.modalModulePath
  14. // : null
  15. // )
  16. // .replace("MODAL_UUID", this.modalUuid)
  17. // .split("/")
  18. // );
  19. // console.log(3211, mapKey);
  20. const state = namespace
  21. .replace(
  22. "MODAL_MODULE_PATH",
  23. namespace.indexOf("MODAL_MODULE_PATH") !== -1
  24. ? this.modalModulePath
  25. : null
  26. )
  27. .replace("MODAL_UUID", this.modalUuid)
  28. .split("/")
  29. .reduce((a, b) => a[b], this.$store.state);
  30. // console.log(32111, state);
  31. // if (state) console.log(321111, mapValue(state));
  32. // else console.log(321111, "NADA");
  33. if (state) return mapValue(state);
  34. return mapValue({});
  35. };
  36. });
  37. return modalState;
  38. };
  39. const mapModalActions = (namespace, map) => {
  40. const modalState = {};
  41. map.forEach(mapValue => {
  42. modalState[mapValue] = function func(value) {
  43. return this.$store.dispatch(
  44. `${namespace
  45. .replace(
  46. "MODAL_MODULE_PATH",
  47. namespace.indexOf("MODAL_MODULE_PATH") !== -1
  48. ? this.modalModulePath
  49. : null
  50. )
  51. .replace("MODAL_UUID", this.modalUuid)}/${mapValue}`,
  52. value
  53. );
  54. };
  55. });
  56. return modalState;
  57. };
  58. const mapModalComponents = (baseDirectory, map) => {
  59. const modalComponents = {};
  60. Object.entries(map).forEach(([mapKey, mapValue]) => {
  61. modalComponents[mapKey] = () =>
  62. defineAsyncComponent(() =>
  63. import(`./${baseDirectory}/${mapValue}`)
  64. );
  65. });
  66. return modalComponents;
  67. };
  68. export { mapModalState, mapModalActions, mapModalComponents };