Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions src/components/stateless/SvgPreview/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { ZoomInOutlined, ZoomOutOutlined, SyncOutlined, DownloadOutlined } from

const defaultBg = '#1e1e1e'

function SvgPreview({
function SvgPreview ({
svgSource = '',
svgUrl = '',
SvgComponent = null,
downloadName = 'diagram.svg',
background = defaultBg,
background = defaultBg
}) {
const containerRef = useRef(null)
const innerRef = useRef(null)
Expand Down Expand Up @@ -253,15 +253,15 @@ function SvgPreview({
<div style={{ height: '100%', position: 'relative' }}>
<div
ref={containerRef}
role="application"
aria-label="SVG viewer"
role='application'
aria-label='SVG viewer'
style={{
width: '100%',
height: '100%',
backgroundColor: background,
overflow: 'hidden',
cursor: isDragging ? 'grabbing' : 'grab',
position: 'relative',
position: 'relative'
}}
>
<div
Expand All @@ -270,14 +270,16 @@ function SvgPreview({
transformOrigin: '0 0',
transform: `translate(${position.x}px, ${position.y}px) scale(${scale})`,
transition: isDragging ? 'none' : 'transform 0.1s ease-out',
willChange: 'transform',
willChange: 'transform'
}}
>
{SvgComponent ? (
<SvgComponent style={{ width: '100%', height: '100%' }} />
) : (
<div dangerouslySetInnerHTML={{ __html: content ? content.replace(/<br>/g, '<br/>') : '' }} />
)}
{SvgComponent
? (
<SvgComponent style={{ width: '100%', height: '100%' }} />
)
: (
<div dangerouslySetInnerHTML={{ __html: content ? content.replace(/<br>/g, '<br/>') : '' }} />
)}
</div>
</div>

Expand All @@ -295,16 +297,16 @@ function SvgPreview({
display: 'flex',
alignItems: 'center',
gap: 8,
boxShadow: '0 6px 18px rgba(0,0,0,0.35)',
boxShadow: '0 6px 18px rgba(0,0,0,0.35)'
}}
>
<Button icon={<ZoomOutOutlined />} onClick={handleZoomOut} type="text" style={{ color: '#fff' }} />
<Button icon={<ZoomOutOutlined />} onClick={handleZoomOut} type='text' style={{ color: '#fff' }} />
<div style={{ color: '#fff', minWidth: 56, textAlign: 'center', fontWeight: 500 }}>
{Math.round(scale * 100)}%
</div>
<Button icon={<ZoomInOutlined />} onClick={handleZoomIn} type="text" style={{ color: '#fff' }} />
<Button icon={<SyncOutlined />} onClick={handleReset} type="text" style={{ color: '#fff' }} />
<Button icon={<DownloadOutlined />} onClick={handleDownload} type="primary" size="small">
<Button icon={<ZoomInOutlined />} onClick={handleZoomIn} type='text' style={{ color: '#fff' }} />
<Button icon={<SyncOutlined />} onClick={handleReset} type='text' style={{ color: '#fff' }} />
<Button icon={<DownloadOutlined />} onClick={handleDownload} type='primary' size='small'>
下载
</Button>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/pages/svgViewer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import { Card, Space, Typography } from 'antd'

const { Text } = Typography

const SVG_SOURCE = ``
const SVG_SOURCE = ''

const SvgViewer = () => {
return (
<FixTabPanel fill={true}>
<FixTabPanel fill>
<Card
title="架构图预览"
title='架构图预览'
extra={
<Space>
<Text type="secondary">提示:可以使用鼠标拖拽和方向键移动视图</Text>
<Text type='secondary'>提示:可以使用鼠标拖拽和方向键移动视图</Text>
</Space>
}
style={{ flex: 1, display: 'flex', height: '100%', flexDirection: 'column' }}
styles={{
body: { padding: 0, flex: 1, overflow: 'hidden', display: 'flex', position: 'relative' },
body: { padding: 0, flex: 1, overflow: 'hidden', display: 'flex', position: 'relative' }
}}
>
<div style={{ flex: 1, position: 'relative' }}>
<SvgPreview SvgComponent={DiagramSvg} downloadName="architecture-diagram.svg" />
<SvgPreview SvgComponent={DiagramSvg} downloadName='architecture-diagram.svg' />
{/* <SvgPreview svgSource={SVG_SOURCE} downloadName="architecture-diagram.svg" /> */}
{/* 如果需要直接作为组件渲染,可改为 <DiagramSvg/> */}
</div>
Expand Down
Loading