-
-
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.
feat: schema editor support json to schema (#639)
- Loading branch information
Showing
5 changed files
with
128 additions
and
58 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
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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { useState } from 'react' | ||
import { Input, Modal, Button } from 'antd' | ||
import { json2schema } from '../utils/json2schema' | ||
|
||
const { TextArea } = Input | ||
|
||
interface IJsonDialogProps { | ||
onChange: (schema: any) => void | ||
} | ||
|
||
const JsonDialog: React.FC<IJsonDialogProps> = ({ onChange }) => { | ||
const [jsonDialogVisible, setJsonDialogVisible] = useState(false) | ||
const [json, setJson] = useState('') | ||
|
||
const handleShowJsonDialog = () => { | ||
setJsonDialogVisible(true) | ||
} | ||
|
||
const handleHideJsonDialog = () => { | ||
setJsonDialogVisible(false) | ||
} | ||
|
||
const handleJsonChange = e => { | ||
const { value } = e.target | ||
setJson(value) | ||
} | ||
|
||
const handleOk = () => { | ||
try { | ||
if (!json) { | ||
return | ||
} | ||
const jsonSchema = json2schema(JSON.parse(json)) | ||
handleHideJsonDialog() | ||
onChange(jsonSchema) | ||
} catch (err) { | ||
// console.log(err) | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
<Button type="primary" onClick={handleShowJsonDialog}> | ||
快速生成 | ||
</Button> | ||
<Modal | ||
title="请输入JSON" | ||
visible={jsonDialogVisible} | ||
onOk={handleOk} | ||
onCancel={handleHideJsonDialog} | ||
> | ||
<TextArea | ||
value={json} | ||
onChange={handleJsonChange} | ||
placeholder="" | ||
autoSize={{ minRows: 10, maxRows: 10 }} | ||
/> | ||
</Modal> | ||
</div> | ||
) | ||
} | ||
|
||
export default JsonDialog |
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
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