-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(extension): base64导出支持画布局部渲染时导出&修复相对路径图片导出问题&补充文档 #2114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,43 @@ class ImageNode extends RectNode { | |
} | ||
} | ||
|
||
export default { | ||
class TestImageModel extends RectNodeModel { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 图片展示节点的定义 |
||
initNodeData(data: any) { | ||
super.initNodeData(data) | ||
this.width = 100 | ||
this.height = 75 | ||
} | ||
} | ||
|
||
class TestImageNode extends RectNode { | ||
getImageHref() { | ||
return '/images/test.jpeg' | ||
} | ||
getShape() { | ||
const { x, y, width, height } = this.props.model | ||
const href = this.getImageHref() | ||
const attrs = { | ||
x: x - (1 / 2) * width, | ||
y: y - (1 / 2) * height, | ||
width, | ||
height, | ||
href, | ||
preserveAspectRatio: 'none meet', | ||
} | ||
return h('g', {}, [h('image', { ...attrs })]) | ||
} | ||
} | ||
|
||
const defaultImageNode = { | ||
type: 'image', | ||
view: ImageNode, | ||
model: ImageModel, | ||
} | ||
|
||
export const testImage = { | ||
type: 'test-image', | ||
view: TestImageNode, | ||
model: TestImageModel, | ||
} | ||
|
||
export default defaultImageNode |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ import { | |
InputNumber, | ||
Switch, | ||
} from 'antd' | ||
import ImageNode from './imageNode' | ||
import CustomHtml from '@/components/nodes/custom-html/Html' | ||
import ImageNode, { testImage } from './imageNode' | ||
import data from './data' | ||
import { circle as circleSvgUrl, rect as rectSvgUrl } from './svg' | ||
|
||
|
@@ -89,6 +89,7 @@ export default function SnapshotExample() { | |
}) | ||
lf.register(CustomHtml) | ||
lf.register(ImageNode) | ||
lf.register(testImage) | ||
|
||
lf.setPatternItems([ | ||
{ | ||
|
@@ -103,6 +104,12 @@ export default function SnapshotExample() { | |
text: 'circle', | ||
icon: rectSvgUrl, | ||
}, | ||
{ | ||
type: 'test-image', | ||
label: 'Test Image', | ||
text: 'Test Image', | ||
icon: rectSvgUrl, | ||
}, | ||
]) | ||
|
||
lf.on('custom:button-click', (model: any) => { | ||
|
@@ -156,9 +163,18 @@ export default function SnapshotExample() { | |
// 预览 blob | ||
const previewBlob = () => { | ||
if (lfRef.current) { | ||
setBase64Data('') | ||
setBlobData('') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里setBase64改成setBlob主要是觉得base64的图片和blob的图片展示并不互斥,所以这里改成了setBlobData,在赋值前重置一下 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔这么一看感觉好像能删了,毕竟下面会直接赋值 |
||
const params: ToImageOptions = { | ||
fileType, | ||
backgroundColor, | ||
partial, | ||
width, | ||
height, | ||
padding, | ||
quality, | ||
} | ||
lfRef.current | ||
.getSnapshotBlob(backgroundColor, fileType) | ||
.getSnapshotBlob(backgroundColor, fileType, params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 导出blob支持传入ToImageOptions |
||
.then( | ||
({ | ||
data, | ||
|
@@ -177,25 +193,25 @@ export default function SnapshotExample() { | |
} | ||
|
||
// 预览 base64 | ||
const previewBase64 = () => { | ||
const previewBase64 = async () => { | ||
if (lfRef.current) { | ||
setBlobData('') | ||
lfRef.current | ||
.getSnapshotBase64(backgroundColor) | ||
.then( | ||
({ | ||
data, | ||
width, | ||
height, | ||
}: { | ||
data: string | ||
width: number | ||
height: number | ||
}) => { | ||
setBase64Data(data) | ||
console.log('width, height ', width, height) | ||
}, | ||
) | ||
setBase64Data('') | ||
const params: ToImageOptions = { | ||
fileType, | ||
backgroundColor, | ||
partial, | ||
width, | ||
height, | ||
padding, | ||
quality, | ||
} | ||
const result = await lfRef.current.getSnapshotBase64( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. base64的新调用方法 |
||
'white', | ||
'png', | ||
params, | ||
) | ||
setBase64Data(result.data) | ||
console.log('width, height ', result) | ||
} | ||
} | ||
|
||
|
@@ -303,17 +319,17 @@ export default function SnapshotExample() { | |
<div ref={containerRef} className="graph"></div> | ||
</Flex> | ||
<Row> | ||
<Col span={12}> | ||
<Col span={24}> | ||
{blobData && ( | ||
<> | ||
<h2>blobData</h2> | ||
<img key="blob" src={blobData} /> | ||
<img style={{ width: '100%' }} key="blob" src={blobData} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 之前父元素比较窄,导出图片小的时候图挤成一团,图片大的时候又得左右滚动页面看,交互太难受了所以就调整了一下布局 |
||
</> | ||
)} | ||
{base64Data && ( | ||
<> | ||
<h2>base64Data</h2> | ||
<img key="base64" src={base64Data} /> | ||
<img style={{ width: '100%' }} key="base64" src={base64Data} /> | ||
</> | ||
)} | ||
</Col> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新增了一个展示上面所示的项目路径下图片的节点