index.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 { SelectTransfer } from "../../CompUI/basicUI/Transfer/select";
  10. import { TipIcons } from "../../TipIcons";
  11. export default defineUI({
  12. setup() {
  13. const editor = useEditor();
  14. const { store, actions, helper, controls } = editor;
  15. const hotKeyCtrl = new HotKeyCtrl(editor);
  16. hotKeyCtrl.init();
  17. onUnmounted(() => {
  18. hotKeyCtrl.destroy();
  19. });
  20. const state = reactive({
  21. draging: false,
  22. });
  23. const NotFoundComp = () => <div>无效的组件</div>;
  24. const flagRef = ref();
  25. const containRef = ref();
  26. const selectCanvasRef = ref();
  27. const viewportRef = ref();
  28. controls.cropCtrl.modifyCtrl.toolbars = TipIcons;
  29. const editLayerRef = ref();
  30. return () => {
  31. const pageRoot = helper.findRootComp();
  32. if (!pageRoot) return;
  33. // const streamCardIndex = store.streamCardIds.indexOf(
  34. // store.currStreamCardId
  35. // );
  36. if (!flagRef.value) {
  37. flagRef.value = true;
  38. setTimeout(() => {
  39. actions.onViewReady(
  40. pageRoot.$el,
  41. selectCanvasRef.value,
  42. viewportRef.value
  43. );
  44. helper.initEditLayer(editLayerRef.value);
  45. }, 0);
  46. }
  47. return (
  48. <div class="scrollbar overflow-y-auto h-1/1" ref={viewportRef}>
  49. <div class="relative">
  50. <div class={"w-375px my-60px mx-auto select-none " + contentCls}>
  51. <CompUI.Page.Component compId={pageRoot.id}>
  52. {{
  53. Container(children: any) {
  54. return (
  55. <>
  56. <Container
  57. behaiver="drop-zone"
  58. class={store.isEditPage ? "!min-h-750px" : ""}
  59. // drag-handle-selector=".draganchor"
  60. ref={containRef}
  61. should-accept-drop={(
  62. sourceContainerOptions: any,
  63. payload: any
  64. ) => {
  65. if (sourceContainerOptions.groupName != "canvas") {
  66. return false;
  67. }
  68. if (typeof payload == "string") {
  69. controls.dragAddCtrl.updateCompKey(payload);
  70. } else {
  71. controls.dragAddCtrl.updateCompKey(payload.type);
  72. controls.dragAddCtrl.updateCompData(payload.data);
  73. }
  74. return false;
  75. }}
  76. drop-not-allowed={(p: any) => {
  77. console.log("p", p);
  78. }}
  79. onDrop={(e: any) => {
  80. if (e.payload) {
  81. actions.addCompToDesign(e.payload, e.addedIndex);
  82. } else {
  83. actions.moveComp(e.removedIndex, e.addedIndex);
  84. }
  85. }}
  86. onDragStart={() => (state.draging = true)}
  87. onDragEnd={() => {
  88. state.draging = false;
  89. }}
  90. non-drag-area-selector={".drag-disable"}
  91. >
  92. {children}
  93. </Container>
  94. {/* {store.currStreamCardId && (
  95. <StreamCardTransfer
  96. key={store.currStreamCardId + streamCardIndex}
  97. />
  98. )} */}
  99. {/* {
  100. !state.draging && controls.cropCtrl.state.visible && <Transforms ctrl={ controls.cropCtrl.modifyCtrl} />
  101. } */}
  102. {!state.draging && <SelectTransfer />}
  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. <div class={editLayerStyle} ref={editLayerRef}></div>
  120. <canvas class={selectCls} ref={selectCanvasRef} />
  121. </div>
  122. <div class={meatureStyle}>
  123. <div class="ruler top" id="rulerTop"></div>
  124. <div class="ruler left" id="rulerLeft"></div>
  125. {/* <div class="ruler right" id="rulerRight"></div>
  126. <div class="ruler bottom" id="rulerBottom"></div> */}
  127. </div>
  128. </div>
  129. );
  130. };
  131. },
  132. });
  133. const contentCls = css`
  134. .dndrop-container.vertical > .dndrop-draggable-wrapper {
  135. overflow: unset;
  136. }
  137. `;
  138. const selectCls = css`
  139. pointer-events: none;
  140. position: fixed;
  141. left: 0;
  142. top: 0;
  143. width: 100%;
  144. height: 100%;
  145. z-index: 1000;
  146. `;
  147. const meatureStyle = css`
  148. position: absolute;
  149. width: 100%;
  150. height: 100%;
  151. left: 0;
  152. top: 56px;
  153. z-index: 999;
  154. pointer-events: none;
  155. .ruler {
  156. position: absolute;
  157. cursor: ns-resize;
  158. pointer-events: auto;
  159. }
  160. .top {
  161. top: 0;
  162. left: 0;
  163. height: 20px;
  164. width: 100%;
  165. z-index: 2;
  166. background-color: rgba(38, 38, 38, 0.8);
  167. background-image: repeating-linear-gradient(
  168. 90deg,
  169. #434343 0,
  170. #434343 1px,
  171. transparent 0,
  172. transparent 1cm
  173. ),
  174. repeating-linear-gradient(
  175. 90deg,
  176. #434343 0,
  177. #434343 1px,
  178. transparent 0,
  179. transparent 0.5cm
  180. );
  181. border-bottom: 1px solid #434343;
  182. background-position: 0.5cm 100%;
  183. background-repeat: no-repeat;
  184. background-size: 100% 15px, 100% 10px;
  185. }
  186. .bottom {
  187. bottom: 0;
  188. left: 0;
  189. height: 10px;
  190. width: 100%;
  191. }
  192. .left {
  193. top: 0;
  194. left: 0;
  195. height: 100%;
  196. width: 20px;
  197. z-index: 1;
  198. cursor: ew-resize;
  199. border-right: 1px solid #434343;
  200. background-color: rgba(38, 38, 38, 0.8);
  201. background-image: repeating-linear-gradient(
  202. 180deg,
  203. #434343 0,
  204. #434343 1px,
  205. transparent 0,
  206. transparent 1cm
  207. ),
  208. repeating-linear-gradient(
  209. 180deg,
  210. #434343 0,
  211. #434343 1px,
  212. transparent 0,
  213. transparent 0.5cm
  214. );
  215. background-position: 100% 0.5cm;
  216. background-repeat: no-repeat;
  217. background-size: 15px 100%, 10px 100%;
  218. }
  219. .right {
  220. top: 0;
  221. right: 0;
  222. height: 100%;
  223. width: 20px;
  224. cursor: ew-resize;
  225. }
  226. `;
  227. const editLayerStyle = css`
  228. pointer-events: none;
  229. position: absolute;
  230. left: 0;
  231. top: 0;
  232. width: 100%;
  233. height: 100%;
  234. z-index: 1000;
  235. `;