Skip to content

Commit

Permalink
feat: toggle rule cliplINE
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhcc365 committed Jun 17, 2024
1 parent 097be6a commit 0f4ff8f
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 302 deletions.
2 changes: 1 addition & 1 deletion src/assets/iconfont/iconfont.js

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions src/pages/EditPage/Content/BottomTools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { observer } from "mobx-react-lite";
// import { MainTools } from "@/pages/EditPage/components/Tools/Tools";
import { stores as store } from "@/pages/EditPage/store/main";
import Icon from "@/HbsUI/Icon";

import "./index.less";

const BottomTools = () => {
/** 尺子 */
const toggleRuler = () => {
store.canvasStore.toggleRuler();
};

/** 隐藏|显示 安全线 */
const toggleClipLine = () => {
store.canvasStore.toggleClipLine();
};

/** 出血线 */
const toggleSafeLine = () => {
store.canvasStore.toggleSafeLine();
};

return (
<>
<div className="section-bottom-tool">
<div onClick={toggleSafeLine}>
<Icon fontSize={18} color="grey" icon="jiandao" />
</div>
<div onClick={toggleClipLine}>
<Icon fontSize={18} icon="dunpaibaowei_o" />
</div>
<div onClick={toggleRuler}>
<Icon fontSize={18} icon="ruler" />
</div>
</div>
</>
);
};

export default observer(BottomTools);
2 changes: 1 addition & 1 deletion src/pages/EditPage/Content/TopTools.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.section-top-tool {
position: absolute;
justify-content: flex-end;
top: 0;
bottom: 0;
right: 0;
background: #fff;
width: 100%;
Expand Down
8 changes: 4 additions & 4 deletions src/pages/EditPage/Content/TopTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import "./TopTools.less";
const TopTools = () => {
return (
<>
{store?.canvasStore?.activeType ? (
{/* {store?.canvasStore?.activeType ? (
<div className="section-top-tool">
<MainTools />
</div>
) : (
<div className="section-top-tool">{store?.canvasStore?.activeType}</div>
)}
) : ( */}
<div className="section-top-tool">{store?.canvasStore?.activeType}</div>
{/* )} */}
</>
);
};
Expand Down
19 changes: 19 additions & 0 deletions src/pages/EditPage/Content/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.section-bottom-tool{
position: absolute;
bottom: 0;
right: 0;
width: 100%;
height: 48px;
border: 1px solid #f5f5f5;
border-top: none;
display: flex;
gap: 24px;
align-items: center;
padding: 0 24px;
color: black;
justify-content: center;
.icon{
cursor: pointer;
color: pink;
}
}
32 changes: 15 additions & 17 deletions src/pages/EditPage/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useRef, useEffect } from "react";
import * as fabric from "fabric";
import TopTools from "./TopTools";
import BottomTools from "./BottomTools";
import { observer } from "mobx-react-lite";
import { stores as store } from "@/pages/EditPage/store/main";
// import { FabricCanvas } from "@/extension/fabricCanvas";
Expand All @@ -9,29 +10,25 @@ const MainContent = () => {
const canvasBoxRef = useRef<HTMLInputElement>(null);
const canvasEl = useRef<HTMLCanvasElement>(null);

const handleEnter = () => {
console.log("-->回车");
};
// const handleEnter = () => {
// console.log("-->回车");
// };

const onKeyDown = (e: { code: any }) => {
const code = e.code;
switch (code) {
case "Enter":
handleEnter();
break;
default:
break;
}
};
// const onKeyDown = (e: { code: any }) => {
// const code = e.code;
// switch (code) {
// case "Enter":
// handleEnter();
// break;
// default:
// break;
// }
// };

useEffect(() => {
const wrapperWidth = canvasBoxRef.current?.getBoundingClientRect().width;
const wrapperHeight = canvasBoxRef.current?.getBoundingClientRect().height;

console.log("===>", canvasBoxRef.current, wrapperHeight, wrapperWidth);

const options = {
backgroundColor: "pink",
absolutePositioned: true,
selectable: false,
width: wrapperWidth,
Expand Down Expand Up @@ -66,6 +63,7 @@ const MainContent = () => {
>
<TopTools />
<canvas ref={canvasEl} />
<BottomTools />
</div>
);
};
Expand Down
34 changes: 28 additions & 6 deletions src/pages/EditPage/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const MJHeader = () => {
};

const handleRule = () => {
new FabricRuler(store.canvasStore.canvas);
// new FabricRuler(store.canvasStore.canvas);
store.canvasStore.canvas?.renderAll();
};

Expand All @@ -82,10 +82,33 @@ const MJHeader = () => {
</Button>
</div>
<div className="btns-box">
<Button onClick={handleClickPic}>下载图片</Button>
<Button onClick={handleDownloadGroup}>下载Group</Button>
<Button onClick={handleClickJson}>下载JSON</Button>
<Button onClick={handleClickJson}>下载PDF</Button>
<Button>编组</Button>
<Button>解除编组</Button>
<Button
onClick={() => {
store.canvasStore.toggleClipLine();
}}
>
出血线
</Button>
<Button
onClick={() => {
store.canvasStore.toggleSafeLine();
}}
>
安全线
</Button>
<Button
onClick={() => {
store.canvasStore.toggleRuler();
}}
>
尺子
</Button>
{/* <Button onClick={handleClickPic}>下载图片</Button> */}
{/* <Button onClick={handleDownloadGroup}>下载Group</Button> */}
{/* <Button onClick={handleClickJson}>下载JSON</Button> */}
{/* <Button onClick={handleClickJson}>下载PDF</Button> */}
{/* <Button onClick={handleOnSave}>暂存</Button> */}
<Button onClick={handleReset}>清除</Button>
<Button onClick={handleReset}>保存</Button>
Expand All @@ -100,7 +123,6 @@ const MJHeader = () => {
}}
onChange={handleFontChange}
/>
<Button onClick={handleRule}>画尺子</Button>
</div>
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions src/pages/EditPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const HomePage = () => {
<Content style={contentStyle}>
<MainContent />
</Content>
<Sider width={260} style={{ background: "#fff" }}>
工具库
</Sider>
</Layout>
</Layout>
</div>
Expand Down
Loading

0 comments on commit 0f4ff8f

Please sign in to comment.