-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor:code and style refactor (#522)
- Loading branch information
1 parent
aa903bc
commit 24b3503
Showing
12 changed files
with
218 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
packages/react-schema-editor/src/components/FieldEditor.css
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 32 additions & 78 deletions
110
packages/react-schema-editor/src/components/SchemaCode.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,49 @@ | ||
import React, { useState } from 'react' | ||
import {Drawer, Icon, Tooltip, notification } from 'antd'; | ||
import React from 'react' | ||
import {Tooltip, Icon} from 'antd'; | ||
import MonacoEditor from 'react-monaco-editor' | ||
import moment from 'moment'; | ||
import { ISchemaCodeProps } from '../utils/types' | ||
|
||
// const options = { | ||
// selectOnLineNumbers: true | ||
// }; | ||
|
||
const styles = { | ||
icon: { | ||
fontSize: '24px', | ||
color: '#fff', | ||
marginBottom: '15px' | ||
} | ||
}; | ||
import {copySchema, downloadSchema} from '../utils/schemaTools' | ||
|
||
export const SchemaCode: React.FC<ISchemaCodeProps> = ({ | ||
schema, | ||
onChange | ||
}) => { | ||
const [showDrawer, setShowDrawer] = useState(false); | ||
|
||
if (typeof schema === 'object') { | ||
schema = JSON.stringify(schema, null, '\t') | ||
} | ||
|
||
const copySchema = () => { | ||
const oEle = document.createElement('textarea'); | ||
oEle.value = schema; | ||
document.body.appendChild(oEle); | ||
oEle.select(); | ||
document.execCommand('Copy'); | ||
oEle.style.display = 'none'; | ||
notification | ||
notification.open({ | ||
message: 'shcema复制成功', | ||
duration: 2, | ||
}); | ||
} | ||
|
||
const downloadSchema = () => { | ||
const aEle = document.createElement('a'); | ||
aEle.download = `${moment().format('YYYYMMDD-HHmmss')}schema.json`; | ||
aEle.style.display = 'none'; | ||
var blob = new Blob([schema], {type:'application/json,charset=utf-8;'}); | ||
aEle.href = URL.createObjectURL(blob); | ||
document.body.appendChild(aEle); | ||
aEle.click(); | ||
document.body.removeChild(aEle); | ||
} | ||
|
||
const aside = ( | ||
<div style={{ width: '28px', padding: '5px 0', textAlign: 'center', background: '#1890ff' }}> | ||
<Tooltip placement="left" title="预览、编辑协议"> | ||
<Icon type="codepen" onClick={() => { setShowDrawer(true) }} style={styles.icon} /> | ||
</Tooltip> | ||
<Tooltip placement="left" title="复制协议"> | ||
<Icon type="copy" onClick={copySchema} style={styles.icon} /> | ||
</Tooltip> | ||
<Tooltip placement="left" title="下载协议"> | ||
<Icon type="download" onClick={downloadSchema} style={styles.icon} /> | ||
</Tooltip> | ||
</div> | ||
); | ||
const styles = { | ||
icon: { | ||
fontSize: '20px', | ||
color: '#fff', | ||
paddingRight: '10px' | ||
} | ||
}; | ||
|
||
const ToolBar = () => { | ||
return ( | ||
<div style={{ height: '30px', lineHeight: '30px', padding: '3px 30px', textAlign: 'right', background: '#1890ff' }}> | ||
<Tooltip placement="left" title="复制协议"> | ||
<Icon type="copy" onClick={() => {copySchema(schema)}} style={styles.icon} /> | ||
</Tooltip> | ||
<Tooltip placement="left" title="下载协议"> | ||
<Icon type="download" onClick={()=> {downloadSchema(schema)}} style={styles.icon} /> | ||
</Tooltip> | ||
</div> | ||
)}; | ||
|
||
return ( | ||
<div style={{ height: '100%', }}> | ||
{ | ||
!showDrawer ? aside : null | ||
} | ||
|
||
<Drawer | ||
width="840" | ||
placement="right" | ||
visible={showDrawer} | ||
closable={false} | ||
bodyStyle={{ padding: 0, height: '100%' }} | ||
onClose={() => setShowDrawer(false)} > | ||
<div style={{ display: 'flex', flexDirection: 'row', height: '100%' }}> | ||
<MonacoEditor | ||
language="json" | ||
theme="vs-dark" | ||
onChange={(schema) => onChange(JSON.parse(schema))} | ||
value={schema} | ||
/> | ||
{ | ||
showDrawer ? aside : null | ||
} | ||
</div> | ||
</Drawer> | ||
<div> | ||
<ToolBar></ToolBar> | ||
<MonacoEditor | ||
height={500} | ||
language="json" | ||
theme="vs-dark" | ||
onChange={(schema) => onChange(JSON.parse(schema))} | ||
value={schema} | ||
/> | ||
</div> | ||
|
||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.