123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- import { IconDelete } from "@/assets/icons";
- import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
- import { css, cx } from "@linaria/core";
- import { defineUI } from "queenjs";
- import { nextTick, onUnmounted, reactive, ref } from "vue";
- import { Container, Draggable } from "vue-dndrop";
- import { useEditor } from "../../..";
- import { HotKeyCtrl } from "../../../controllers/HotKeyCtrl";
- import { CompUI } from "../../CompUI";
- import { SelectTransfer } from "../../CompUI/basicUI/Transfer/select";
- import { TipIcons } from "../../TipIcons";
- import { history } from "@/modules/editor/objects/DesignTemp/factory";
- export default defineUI({
- setup() {
- const editor = useEditor();
- const { store, actions, helper, controls } = editor;
- const hotKeyCtrl = new HotKeyCtrl(editor);
- hotKeyCtrl.init();
- onUnmounted(() => {
- hotKeyCtrl.destroy();
- });
- const state = reactive({
- draging: false,
- });
- const NotFoundComp = () => <div>无效的组件</div>;
- const flagRef = ref();
- const containRef = ref();
- controls.cropCtrl.modifyCtrl.toolbars = TipIcons;
- const editLayerRef = ref();
- const refs = controls.editorCtrl.useEditor();
- return () => {
- console.log("rootId=>", controls.pageCtrl.state.rootId );
- const page = controls.pageCtrl;
- const pageRoot = helper.findRootComp();
- if (!pageRoot) return;
- // const streamCardIndex = store.streamCardIds.indexOf(
- // store.currStreamCardId
- // );
- if (!flagRef.value) {
- flagRef.value = true;
- setTimeout(() => {
- actions.onViewReady(
- pageRoot.$el,
- refs.canvas.value,
- refs.parent.value
- );
- helper.initEditLayer(editLayerRef.value);
- }, 100);
- }
- return (
- <div class="flex flex-1 relative">
- <div class={["scrollbar", cardList]}>
- <div>
- <Container
- class="space-y-15px mt-15px"
- onDrop={(e: any) => {
- if (e.payload) {
- actions.addCompToDesign(e.payload, e.addedIndex);
- } else {
- actions.moveComp(e.removedIndex, e.addedIndex);
- }
- }}
- >
- {page.streamCardIds.map((item) => {
- const c = helper.findComp(item) as DesignComp;
- const Comp =
- controls.compUICtrl.state.components.get(c.compKey)
- ?.Component || NotFoundComp;
- const r = c.layout.size[1] / c.layout.size[0];
- let h = 80 * r;
- if (h > 80) h = 80;
- if (h < 40) h = 40;
- const style: any = { height: h + "px" };
- return (
- <Draggable>
- <div
- key={item + controls.screenCtrl.currScreenId}
- class={cx(
- "card-item relative transition-opacity hover:opacity-80",
- store.currStreamCardId == item && "active"
- )}
- style={style}
- onClick={() => {
- controls.editorCtrl.clickPickComp(item);
- history.submit();
- nextTick(() => {
- controls.editorCtrl.autoInScreen();
- });
- }}
- >
- {page.streamCardIds.length > 1 && (
- <IconDelete
- onClick={() => {
- actions.removeStreamCard(item);
- }}
- class="deleteitem absolute right-4px top-4px text-light-50"
- />
- )}
- <div class="pointer-events-none">
- <Comp
- compId={c.id}
- style={{
- transformOrigin: "0 0",
- pointerEvent: "none",
- transform: `scale(${
- 80.0 / helper.designSizeToPx(c.layout.size[0])
- })`,
- }}
- />
- </div>
- </div>
- </Draggable>
- );
- })}
- <img
- class="mt-15px cursor-pointer"
- onClick={() => {
- const index = page.streamCardIds.length;
- actions.addCompToDesign("Container", index);
- history.submit();
- setTimeout(() => {
- controls.editorCtrl.autoInScreen();
- }, 200);
- }}
- src={require("@/assets/imgs/add.svg")}
- alt=""
- />
- </Container>
- </div>
- </div>
- <div ref={refs.parent} class={["absolute", viewportStyle]}>
- <div ref={refs.editor}>
- <div ref={refs.page} class={"select-none " + contentCls}>
- <CompUI.Page.Component compId={pageRoot.id}>
- {{
- Container(children: any) {
- return (
- <>
- <Container
- behaiver="drop-zone"
- should-accept-drop={(
- sourceContainerOptions: any,
- payload: any
- ) => {
- if (
- sourceContainerOptions.groupName != "canvas"
- ) {
- return false;
- }
- console.log("payload===>", "xxx", payload);
- if (typeof payload == "string") {
- controls.dragAddCtrl.updateCompKey(payload);
- } else {
- controls.dragAddCtrl.updateCompKey(
- payload.type
- );
- controls.dragAddCtrl.updateCompData(
- payload.data
- );
- }
- return false;
- }}
- onDrop={(e: any) => {
- debugger;
- if (e.payload) {
- console.log("xx a");
- actions.addCompToDesign(
- e.payload,
- e.addedIndex
- );
- }
- }}
- >
- {children}
- </Container>
- {!state.draging && <SelectTransfer />}
- </>
- );
- },
- CompItem(comp: DesignComp) {
- const Comp =
- controls.compUICtrl.state.components.get(comp.compKey)
- ?.Component || NotFoundComp;
- return (
- <Comp
- compId={comp.id}
- key={comp.id + controls.screenCtrl.currScreenId}
- showMask={true}
- />
- );
- },
- }}
- </CompUI.Page.Component>
- </div>
- <div class={editLayerStyle} ref={editLayerRef}></div>
- </div>
- <canvas class={selectCls} ref={refs.canvas} />
- {/* <div class={meatureStyle}>
- <div class="ruler top" id="rulerTop"></div>
- <div class="ruler left" id="rulerLeft"></div>
- <div class="ruler right" id="rulerRight"></div>
- <div class="ruler bottom" id="rulerBottom"></div>
- </div> */}
- </div>
- </div>
- );
- };
- },
- });
- const contentCls = css`
- position: absolute;
- .dndrop-container.vertical > .dndrop-draggable-wrapper {
- overflow: unset;
- }
- `;
- const selectCls = css`
- position: absolute;
- pointer-events: none;
- left: 0;
- top: 0;
- width: 100%;
- height: 100%;
- z-index: 10000;
- `;
- const meatureStyle = css`
- position: absolute;
- width: 100%;
- height: 100%;
- left: 0;
- top: 0px;
- z-index: 998;
- pointer-events: none;
- .ruler {
- position: absolute;
- cursor: ns-resize;
- pointer-events: auto;
- }
- .top {
- top: 0;
- left: 0px;
- height: 20px;
- width: 100%;
- z-index: 2;
- background-color: rgba(38, 38, 38, 0.8);
- background-image: repeating-linear-gradient(
- 90deg,
-
-
- transparent 0,
- transparent 1cm
- ),
- repeating-linear-gradient(
- 90deg,
-
-
- transparent 0,
- transparent 0.5cm
- );
- border-bottom: 1px solid
- background-position: 0.5cm 100%;
- background-repeat: no-repeat;
- background-size: 100% 15px, 100% 10px;
- }
- .bottom {
- bottom: 0;
- left: 0;
- height: 10px;
- width: 100%;
- }
- .left {
- top: 0;
- left: 0px;
- height: 100%;
- width: 20px;
- z-index: 1;
- cursor: ew-resize;
- border-right: 1px solid
- background-color: rgba(38, 38, 38, 0.8);
- background-image: repeating-linear-gradient(
- 180deg,
-
-
- transparent 0,
- transparent 1cm
- ),
- repeating-linear-gradient(
- 180deg,
-
-
- transparent 0,
- transparent 0.5cm
- );
- background-position: 100% 0.5cm;
- background-repeat: no-repeat;
- background-size: 15px 100%, 10px 100%;
- }
- .right {
- top: 0;
- right: 0;
- height: 100%;
- width: 20px;
- cursor: ew-resize;
- }
- `;
- const editLayerStyle = css`
- pointer-events: none;
- position: absolute;
- left: 0;
- top: 0;
- width: 100%;
- height: 100%;
- z-index: 1000;
- `;
- const cardList = css`
- width: 120px;
- height: 100%;
- background:
- overflow-x: hidden;
- pointer-events: auto;
- display: flex;
- flex-direction: column;
- align-items: center;
- position: absolute;
- padding-bottom: 120px;
- .card-item {
- flex-shrink: 0;
- width: 80px;
- height: 80px;
- background:
- border-radius: 4px 4px 4px 4px;
- cursor: pointer;
- overflow: hidden;
- color: white;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- border-radius: 4px;
- z-index: 1;
- transition: box-shadow 0.2s ease-in-out;
- }
- &.active {
- &:before {
- box-shadow:
- }
- }
- .deleteitem {
- z-index: 1000;
- opacity: 0;
- font-size: 20px;
- }
- &:hover {
- .deleteitem {
- opacity: 1;
- background: rgba(0, 0, 0, 0.8);
- }
- }
- }
- `;
- const viewportStyle = css`
- width: calc(100% - 120px);
- height: 100%;
- left: 120px;
- top: 0px;
- overflow: hidden;
- `;
|