index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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(pageRoot.$el, selectCanvasRef.value, viewportRef.value);
  39. }, 0);
  40. }
  41. return (
  42. <div class="scrollbar overflow-y-auto h-1/1" ref={viewportRef}>
  43. <div class="relative">
  44. <div class={"w-375px my-60px mx-auto select-none " + contentCls}>
  45. <CompUI.Page.Component compId={pageRoot.id}>
  46. {{
  47. Container(children: any) {
  48. return (
  49. <>
  50. <Container
  51. behaiver="drop-zone"
  52. class={store.isEditPage ? "!min-h-750px" : ""}
  53. // drag-handle-selector=".draganchor"
  54. ref={containRef}
  55. should-accept-drop={(
  56. sourceContainerOptions: any,
  57. payload: any
  58. ) => {
  59. console.log(
  60. "sourceContainerOptions:any, payload:any",
  61. sourceContainerOptions,
  62. payload
  63. );
  64. if (sourceContainerOptions.groupName != "canvas")
  65. return false;
  66. controls.dragAddCtrl.updateCompKey(payload);
  67. return false;
  68. }}
  69. drop-not-allowed={(p: any) => {
  70. console.log("p", p);
  71. }}
  72. onDrop={(e: any) => {
  73. if (e.payload) {
  74. actions.addCompToDesign(e.payload, e.addedIndex);
  75. } else {
  76. actions.moveComp(e.removedIndex, e.addedIndex);
  77. }
  78. }}
  79. onDragStart={() => (state.draging = true)}
  80. onDragEnd={() => {
  81. state.draging = false
  82. }}
  83. non-drag-area-selector={".drag-disable"}
  84. >
  85. {children}
  86. </Container>
  87. {/* {store.currStreamCardId && (
  88. <StreamCardTransfer
  89. key={store.currStreamCardId + streamCardIndex}
  90. />
  91. )} */}
  92. {/* {store.currCompId &&
  93. store.currStreamCardId &&
  94. store.currCompId !== "root" &&
  95. !store.textEditingState &&
  96. store.currCompId !== store.currStreamCardId &&
  97. !state.draging && (
  98. <Transfer key={store.currCompId + streamCardIndex} />
  99. )} */}
  100. {
  101. !state.draging && <SelectTransfer />
  102. }
  103. </>
  104. );
  105. },
  106. CompItem(comp: DesignComp) {
  107. const Comp =
  108. controls.compUICtrl.state.components.get(comp.compKey)
  109. ?.Component || NotFoundComp;
  110. return (
  111. <Draggable key={comp.id}>
  112. <Comp compId={comp.id} />
  113. </Draggable>
  114. );
  115. },
  116. }}
  117. </CompUI.Page.Component>
  118. </div>
  119. <canvas class={selectCls} ref={selectCanvasRef} />
  120. </div>
  121. </div>
  122. );
  123. };
  124. },
  125. });
  126. const contentCls = css`
  127. .dndrop-container.vertical > .dndrop-draggable-wrapper {
  128. overflow: unset;
  129. }
  130. `;
  131. const selectCls = css`
  132. pointer-events: none;
  133. position: fixed;
  134. left: 0;
  135. top: 0;
  136. width: 100%;
  137. height: 100%;
  138. z-index: 1000;
  139. `;