index.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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, onMounted } 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 { SelectTransfer } from "../../CompUI/basicUI/Transfer/select";
  10. import { TipIcons } from "../../TipIcons";
  11. import { CompBase } from "@/modules/editor/objects/Elements/base";
  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. controls.cropCtrl.modifyCtrl.toolbars = TipIcons;
  30. const editLayerRef = ref();
  31. onMounted(()=>{
  32. if (!flagRef.value) {
  33. flagRef.value = true;
  34. setTimeout(() => {
  35. actions.onViewReady(
  36. controls.compCtrl.getRootPage().$el,
  37. selectCanvasRef.value,
  38. viewportRef.value
  39. );
  40. // helper.initEditLayer(editLayerRef.value);
  41. }, 0);
  42. }
  43. })
  44. return () => {
  45. const pageRoot = controls.compCtrl.getRootPage();
  46. return (
  47. <div class="scrollbar overflow-y-auto h-1/1" ref={viewportRef}>
  48. <div class="relative">
  49. <div class={"w-375px my-60px mx-auto select-none " + contentCls}>
  50. <CompUI.Page.Component compId={pageRoot.id}>
  51. {{
  52. Container(children: any) {
  53. return (
  54. <>
  55. <Container
  56. behaiver="drop-zone"
  57. class={store.isEditPage ? "!min-h-750px" : ""}
  58. // drag-handle-selector=".draganchor"
  59. ref={containRef}
  60. should-accept-drop={(
  61. sourceContainerOptions: any,
  62. payload: any
  63. ) => {
  64. if (sourceContainerOptions.groupName != "canvas") {
  65. return false;
  66. }
  67. if (typeof payload == "string")
  68. controls.dragAddCtrl.updateCompKey(payload);
  69. else {
  70. controls.dragAddCtrl.updateCompKey(payload.type);
  71. controls.dragAddCtrl.updateCompData(payload.data);
  72. }
  73. return false;
  74. }}
  75. drop-not-allowed={(p: any) => {
  76. console.log("p", p);
  77. }}
  78. onDrop={(e: any) => {
  79. if (e.payload) {
  80. actions.addCompToDesign(e.payload, e.addedIndex);
  81. } else {
  82. controls.compCtrl.switchCard(e.removedIndex, e.addedIndex);
  83. }
  84. }}
  85. onDragStart={() => (state.draging = true)}
  86. onDragEnd={() => {
  87. state.draging = false;
  88. }}
  89. non-drag-area-selector={".drag-disable"}
  90. >
  91. {children}
  92. </Container>
  93. {/* {store.currStreamCardId && (
  94. <StreamCardTransfer
  95. key={store.currStreamCardId + streamCardIndex}
  96. />
  97. )} */}
  98. {/* {
  99. !state.draging && controls.cropCtrl.state.visible && <Transforms ctrl={ controls.cropCtrl.modifyCtrl} />
  100. } */}
  101. {!state.draging && <SelectTransfer />}
  102. </>
  103. );
  104. },
  105. CompItem(c: CompBase<object>) {
  106. const Comp = controls.compUICtrl.state.components.get(c.compKey)
  107. ?.Component || NotFoundComp;
  108. return (
  109. <Draggable key={c.id}>
  110. <Comp compId={c.id} />
  111. </Draggable>
  112. );
  113. },
  114. }}
  115. </CompUI.Page.Component>
  116. </div>
  117. <div class={editLayerStyle} ref={editLayerRef}>
  118. </div>
  119. <canvas class={selectCls} ref={selectCanvasRef} />
  120. </div>
  121. <div class={meatureStyle}>
  122. <div class="ruler top" id="rulerTop"></div>
  123. <div class="ruler left" id="rulerLeft"></div>
  124. <div class="ruler right" id="rulerRight"></div>
  125. <div class="ruler bottom" id="rulerBottom"></div>
  126. </div>
  127. </div>
  128. );
  129. };
  130. },
  131. });
  132. const contentCls = css`
  133. .dndrop-container.vertical > .dndrop-draggable-wrapper {
  134. overflow: unset;
  135. }
  136. `;
  137. const selectCls = css`
  138. pointer-events: none;
  139. position: fixed;
  140. left: 0;
  141. top: 0;
  142. width: 100%;
  143. height: 100%;
  144. z-index: 1000;
  145. `;
  146. const meatureStyle = css`
  147. position: absolute;
  148. width: 100%;
  149. height: 100%;
  150. left: 0;
  151. top: 0;
  152. z-index: 1001;
  153. pointer-events: none;
  154. .ruler {
  155. position: absolute;
  156. cursor: ns-resize;
  157. pointer-events: auto;
  158. }
  159. .top {
  160. top: 0;
  161. left: 0;
  162. height: 10px;
  163. width: 100%;
  164. }
  165. .bottom {
  166. bottom: 0;
  167. left: 0;
  168. height: 10px;
  169. width: 100%;
  170. }
  171. .left {
  172. top: 0;
  173. left: 0;
  174. height: 100%;
  175. width: 10px;
  176. cursor: ew-resize;
  177. }
  178. .right {
  179. top: 0;
  180. right: 0;
  181. height: 100%;
  182. width: 10px;
  183. cursor: ew-resize;
  184. }
  185. `;
  186. const editLayerStyle = css`
  187. pointer-events: none;
  188. position: absolute;
  189. left: 0;
  190. top: 0;
  191. width: 100%;
  192. height: 100%;
  193. z-index: 1000;
  194. `