index.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. console.log("payload===>", "xxx", payload);
  69. if (typeof payload == "string") {
  70. controls.dragAddCtrl.updateCompKey(payload);
  71. } else {
  72. controls.dragAddCtrl.updateCompKey(payload.type);
  73. controls.dragAddCtrl.updateCompData(payload.data);
  74. }
  75. return false;
  76. }}
  77. drop-not-allowed={(p: any) => {
  78. console.log("p", p);
  79. }}
  80. onDrop={(e: any) => {
  81. if (e.payload) {
  82. actions.addCompToDesign(e.payload, e.addedIndex);
  83. } else {
  84. actions.moveComp(e.removedIndex, e.addedIndex);
  85. }
  86. }}
  87. onDragStart={() => (state.draging = true)}
  88. onDragEnd={() => {
  89. state.draging = false;
  90. }}
  91. non-drag-area-selector={".drag-disable"}
  92. >
  93. {children}
  94. </Container>
  95. {/* {store.currStreamCardId && (
  96. <StreamCardTransfer
  97. key={store.currStreamCardId + streamCardIndex}
  98. />
  99. )} */}
  100. {/* {
  101. !state.draging && controls.cropCtrl.state.visible && <Transforms ctrl={ controls.cropCtrl.modifyCtrl} />
  102. } */}
  103. {!state.draging && <SelectTransfer />}
  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. <div class={editLayerStyle} ref={editLayerRef}></div>
  121. <canvas class={selectCls} ref={selectCanvasRef} />
  122. </div>
  123. <div class={meatureStyle}>
  124. <div class="ruler top" id="rulerTop"></div>
  125. <div class="ruler left" id="rulerLeft"></div>
  126. {/* <div class="ruler right" id="rulerRight"></div>
  127. <div class="ruler bottom" id="rulerBottom"></div> */}
  128. </div>
  129. </div>
  130. );
  131. };
  132. },
  133. });
  134. const contentCls = css`
  135. .dndrop-container.vertical > .dndrop-draggable-wrapper {
  136. overflow: unset;
  137. }
  138. `;
  139. const selectCls = css`
  140. pointer-events: none;
  141. position: fixed;
  142. left: 0;
  143. top: 0;
  144. width: 100%;
  145. height: 100%;
  146. z-index: 1000;
  147. `;
  148. const meatureStyle = css`
  149. position: absolute;
  150. width: 100%;
  151. height: 100%;
  152. left: 0;
  153. top: 0;
  154. z-index: 999;
  155. pointer-events: none;
  156. .ruler {
  157. position: absolute;
  158. cursor: ns-resize;
  159. pointer-events: auto;
  160. }
  161. .top {
  162. top: 0;
  163. left: 0;
  164. height: 20px;
  165. width: 100%;
  166. z-index: 2;
  167. background-color: rgba(38, 38, 38, 0.8);
  168. background-image: repeating-linear-gradient(
  169. 90deg,
  170. #434343 0,
  171. #434343 1px,
  172. transparent 0,
  173. transparent 1cm
  174. ),
  175. repeating-linear-gradient(
  176. 90deg,
  177. #434343 0,
  178. #434343 1px,
  179. transparent 0,
  180. transparent 0.5cm
  181. );
  182. border-bottom: 1px solid #434343;
  183. background-position: 0.5cm 100%;
  184. background-repeat: no-repeat;
  185. background-size: 100% 15px, 100% 10px;
  186. }
  187. .bottom {
  188. bottom: 0;
  189. left: 0;
  190. height: 10px;
  191. width: 100%;
  192. }
  193. .left {
  194. top: 0;
  195. left: 0;
  196. height: 100%;
  197. width: 20px;
  198. z-index: 1;
  199. cursor: ew-resize;
  200. border-right: 1px solid #434343;
  201. background-color: rgba(38, 38, 38, 0.8);
  202. background-image: repeating-linear-gradient(
  203. 180deg,
  204. #434343 0,
  205. #434343 1px,
  206. transparent 0,
  207. transparent 1cm
  208. ),
  209. repeating-linear-gradient(
  210. 180deg,
  211. #434343 0,
  212. #434343 1px,
  213. transparent 0,
  214. transparent 0.5cm
  215. );
  216. background-position: 100% 0.5cm;
  217. background-repeat: no-repeat;
  218. background-size: 15px 100%, 10px 100%;
  219. }
  220. .right {
  221. top: 0;
  222. right: 0;
  223. height: 100%;
  224. width: 20px;
  225. cursor: ew-resize;
  226. }
  227. `;
  228. const editLayerStyle = css`
  229. pointer-events: none;
  230. position: absolute;
  231. left: 0;
  232. top: 0;
  233. width: 100%;
  234. height: 100%;
  235. z-index: 1000;
  236. `;