Jiarenxiang | 38dcb05 | 2025-03-13 16:40:09 +0800 | [diff] [blame^] | 1 | import React, { useEffect } from 'react'; |
| 2 | import { useIntl } from '@umijs/max'; |
| 3 | import { Modal, Tabs } from 'antd'; |
| 4 | import type { TabsProps } from 'antd'; |
| 5 | import Highlight from 'react-highlight'; |
| 6 | import 'highlight.js/styles/base16/material.css'; |
| 7 | |
| 8 | interface PreviewTableProps { |
| 9 | open: boolean; |
| 10 | data?: any; |
| 11 | onHide: () => void; |
| 12 | } |
| 13 | |
| 14 | const PreviewTableCode: React.FC<PreviewTableProps> = (props) => { |
| 15 | const intl = useIntl(); |
| 16 | const panes: any = []; |
| 17 | const keys = Object.keys(props.data); |
| 18 | keys.forEach((key) => { |
| 19 | panes.push({ |
| 20 | key: key + '1', |
| 21 | label: key.substring(key.lastIndexOf('/') + 1, key.indexOf('.vm')), |
| 22 | children: <Highlight className="java">{props.data[key]}</Highlight>, |
| 23 | } as TabsProps); |
| 24 | }); |
| 25 | |
| 26 | useEffect(() => {}, []); |
| 27 | |
| 28 | return ( |
| 29 | <Modal |
| 30 | width={900} |
| 31 | title={intl.formatMessage({ |
| 32 | id: 'gen.preview', |
| 33 | defaultMessage: '预览', |
| 34 | })} |
| 35 | open={props.open} |
| 36 | destroyOnClose |
| 37 | footer={false} |
| 38 | onOk={() => { |
| 39 | props.onHide(); |
| 40 | }} |
| 41 | onCancel={() => { |
| 42 | props.onHide(); |
| 43 | }} |
| 44 | > |
| 45 | <Tabs defaultActiveKey="1" items={panes}></Tabs> |
| 46 | </Modal> |
| 47 | ); |
| 48 | }; |
| 49 | |
| 50 | export default PreviewTableCode; |