index.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { EditorModule } from "..";
  2. import { DesignTemp } from "../../objects/DesignTemp";
  3. import { EditorMode } from "../../typings";
  4. export const store = EditorModule.store({
  5. state: () => ({
  6. textEditingState: false,
  7. mode: "editPage" as EditorMode,
  8. isWk: false, //作品集内作品
  9. croppImage: "", //裁剪图片
  10. compEditMode: false, //组件编辑模式
  11. compEditReslut: 0, // -1 取消, 1 确定
  12. tplCategory: undefined,
  13. filesCacheUrl: {} as any,
  14. }),
  15. getters: {
  16. currCompId() {
  17. return this.controls.pageCtrl.state.currCompId;
  18. },
  19. isEditMode(): boolean {
  20. return !this.store.isPreview && !this.store.isDisplay;
  21. },
  22. isEditPage(state) {
  23. return state.mode === "editPage";
  24. },
  25. isEditComp(state) {
  26. return state.mode === "editComp";
  27. },
  28. isPreview(state) {
  29. return state.mode === "preview";
  30. },
  31. isDisplay(state) {
  32. return state.mode === "display";
  33. },
  34. previewImageList(state) {
  35. const res: string[] = [];
  36. let scope = this;
  37. function deepChild(item: any) {
  38. if (typeof item == "string") {
  39. const comp = scope.controls.pageCtrl.compMap[item];
  40. if (comp.compKey === "Image") {
  41. res.push(comp.value.url);
  42. } else if (comp.children) {
  43. deepChild(comp.children);
  44. }
  45. } else if (item instanceof Object) {
  46. if (item instanceof Array) {
  47. item.forEach((d) => {
  48. deepChild(d);
  49. });
  50. } else {
  51. Object.values(item).forEach((d) => {
  52. deepChild(d);
  53. });
  54. }
  55. }
  56. }
  57. deepChild(this.controls.pageCtrl.compMap["root"].children);
  58. return res;
  59. },
  60. },
  61. actions: {
  62. setCompData(id: string, data: any) {
  63. this.controls.pageCtrl.compMap[id] = data;
  64. },
  65. setMode(v: EditorMode) {
  66. this.store.mode = v;
  67. },
  68. setWk(v: boolean) {
  69. this.store.isWk = v;
  70. },
  71. setTplCategory(data) {
  72. this.store.tplCategory = data;
  73. },
  74. setDesignData(data: Partial<DesignTemp>) {
  75. this.controls.pageCtrl.designData = new DesignTemp(data);
  76. },
  77. setTextEditingState(state: boolean) {
  78. this.store.textEditingState = state;
  79. },
  80. },
  81. });