index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. controls.selectCtrl.selecteObjs([])
  83. }}
  84. non-drag-area-selector={".drag-disable"}
  85. >
  86. {children}
  87. </Container>
  88. {store.currStreamCardId && !state.draging && (
  89. <StreamCardTransfer
  90. key={store.currStreamCardId + streamCardIndex}
  91. />
  92. )}
  93. {/* {store.currCompId &&
  94. store.currStreamCardId &&
  95. store.currCompId !== "root" &&
  96. !store.textEditingState &&
  97. store.currCompId !== store.currStreamCardId &&
  98. !state.draging && (
  99. <Transfer key={store.currCompId + streamCardIndex} />
  100. )} */}
  101. {
  102. !state.draging && <SelectTransfer />
  103. }
  104. </>
  105. );
  106. },
  107. CompItem(comp: DesignComp) {
  108. const Comp =
  109. controls.compUICtrl.state.components.get(comp.compKey)
  110. ?.Component || NotFoundComp;
  111. return (
  112. <Draggable key={comp.id}>
  113. <Comp compId={comp.id} />
  114. </Draggable>
  115. );
  116. },
  117. }}
  118. </CompUI.Page.Component>
  119. </div>
  120. <canvas class={selectCls} ref={selectCanvasRef} />
  121. </div>
  122. </div>
  123. );
  124. };
  125. },
  126. });
  127. const contentCls = css`
  128. .dndrop-container.vertical > .dndrop-draggable-wrapper {
  129. overflow: unset;
  130. }
  131. `;
  132. const selectCls = css`
  133. pointer-events: none;
  134. position: fixed;
  135. left: 0;
  136. top: 0;
  137. width: 100%;
  138. height: 100%;
  139. z-index: 1000;
  140. `;