index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
  2. import { css } from "@linaria/core";
  3. import { defineUI } from "queenjs";
  4. import { onUnmounted, reactive, ref } from "vue";
  5. import { Container, Draggable } from "vue-dndrop";
  6. import { useEditor } from "../../..";
  7. import { HotKeyCtrl } from "../../../controllers/HotKeyCtrl";
  8. import { CompUI } from "../../CompUI";
  9. import { Transfer } from "../../CompUI/basicUI/Transfer";
  10. import { StreamCardTransfer } from "../../CompUI/basicUI/Transfer/streamCard";
  11. import { SelectTransfer } from "../../CompUI/basicUI/Transfer/select";
  12. export default defineUI({
  13. setup() {
  14. const editor = useEditor();
  15. const { store, actions, helper, controls } = editor;
  16. const hotKeyCtrl = new HotKeyCtrl(editor);
  17. hotKeyCtrl.init();
  18. onUnmounted(() => {
  19. hotKeyCtrl.destroy();
  20. });
  21. const state = reactive({
  22. draging: false,
  23. });
  24. const NotFoundComp = () => <div>无效的组件</div>;
  25. const flagRef = ref();
  26. const containRef = ref();
  27. const selectCanvasRef = ref();
  28. const viewportRef = ref();
  29. return () => {
  30. const pageRoot = helper.findRootComp();
  31. if (!pageRoot) return;
  32. const streamCardIndex = store.streamCardIds.indexOf(
  33. store.currStreamCardId
  34. );
  35. if (!flagRef.value) {
  36. flagRef.value = true;
  37. setTimeout(() => {
  38. actions.onViewReady(
  39. pageRoot.$el,
  40. selectCanvasRef.value,
  41. viewportRef.value
  42. );
  43. }, 0);
  44. }
  45. return (
  46. <div class="scrollbar overflow-y-auto h-1/1" ref={viewportRef}>
  47. <div class="relative">
  48. <div class={"w-375px my-60px mx-auto select-none " + contentCls}>
  49. <CompUI.Page.Component compId={pageRoot.id}>
  50. {{
  51. Container(children: any) {
  52. return (
  53. <>
  54. <Container
  55. behaiver="drop-zone"
  56. class={store.isEditPage ? "!min-h-750px" : ""}
  57. // drag-handle-selector=".draganchor"
  58. ref={containRef}
  59. should-accept-drop={(
  60. sourceContainerOptions: any,
  61. payload: any
  62. ) => {
  63. if (sourceContainerOptions.groupName != "canvas") {
  64. return false;
  65. }
  66. if (typeof payload == "string")
  67. controls.dragAddCtrl.updateCompKey(payload);
  68. else {
  69. controls.dragAddCtrl.updateCompKey(payload.type);
  70. controls.dragAddCtrl.updateCompData(payload.data);
  71. }
  72. return false;
  73. }}
  74. drop-not-allowed={(p: any) => {
  75. console.log("p", p);
  76. }}
  77. onDrop={(e: any) => {
  78. if (e.payload) {
  79. actions.addCompToDesign(e.payload, e.addedIndex);
  80. } else {
  81. actions.moveComp(e.removedIndex, e.addedIndex);
  82. }
  83. }}
  84. onDragStart={() => (state.draging = true)}
  85. onDragEnd={() => {
  86. state.draging = false;
  87. }}
  88. non-drag-area-selector={".drag-disable"}
  89. >
  90. {children}
  91. </Container>
  92. {/* {store.currStreamCardId && (
  93. <StreamCardTransfer
  94. key={store.currStreamCardId + streamCardIndex}
  95. />
  96. )} */}
  97. {/* {store.currCompId &&
  98. store.currStreamCardId &&
  99. store.currCompId !== "root" &&
  100. !store.textEditingState &&
  101. store.currCompId !== store.currStreamCardId &&
  102. !state.draging && (
  103. <Transfer key={store.currCompId + streamCardIndex} />
  104. )} */}
  105. {!state.draging && <SelectTransfer />}
  106. </>
  107. );
  108. },
  109. CompItem(comp: DesignComp) {
  110. const Comp =
  111. controls.compUICtrl.state.components.get(comp.compKey)
  112. ?.Component || NotFoundComp;
  113. return (
  114. <Draggable key={comp.id}>
  115. <Comp compId={comp.id} />
  116. </Draggable>
  117. );
  118. },
  119. }}
  120. </CompUI.Page.Component>
  121. </div>
  122. <canvas class={selectCls} ref={selectCanvasRef} />
  123. </div>
  124. </div>
  125. );
  126. };
  127. },
  128. });
  129. const contentCls = css`
  130. .dndrop-container.vertical > .dndrop-draggable-wrapper {
  131. overflow: unset;
  132. }
  133. `;
  134. const selectCls = css`
  135. pointer-events: none;
  136. position: fixed;
  137. left: 0;
  138. top: 0;
  139. width: 100%;
  140. height: 100%;
  141. z-index: 1000;
  142. `;