|
| 1 | +import React, { useCallback, useState } from 'react'; |
| 2 | +import { Input, Button, Layout } from 'antd'; |
| 3 | +import { AssemblerBox } from './style'; |
| 4 | + |
| 5 | +const Assembler = () => { |
| 6 | + const [input, changeInput] = useState<string>(''); |
| 7 | + const handleChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => { |
| 8 | + if (!event.target.files || !event.target.files[0]) { |
| 9 | + return; |
| 10 | + } |
| 11 | + |
| 12 | + const file = event.target.files[0]; |
| 13 | + const reader = new FileReader(); |
| 14 | + |
| 15 | + // @ts-ignore |
| 16 | + reader.onloadend = (ev: ProgressEvent<FileReader>) => { |
| 17 | + if (!ev.target || ev.target.readyState !== FileReader.DONE) { |
| 18 | + return; |
| 19 | + } |
| 20 | + changeInput((ev.target.result as string) || ''); |
| 21 | + }; |
| 22 | + reader.readAsText(file); |
| 23 | + }, []); |
| 24 | + |
| 25 | + const parser = useCallback(() => { |
| 26 | + console.log('input', input); |
| 27 | + }, [input]); |
| 28 | + |
| 29 | + return ( |
| 30 | + <Layout> |
| 31 | + <Layout.Header> |
| 32 | + <h1 style={{ color: 'white' }}>assembler</h1> |
| 33 | + </Layout.Header> |
| 34 | + <Layout.Content |
| 35 | + style={{ |
| 36 | + boxSizing: 'border-box', |
| 37 | + height: 'calc(100vh - 64px)', |
| 38 | + padding: '20px', |
| 39 | + }} |
| 40 | + > |
| 41 | + <AssemblerBox> |
| 42 | + <div className="header operate"> |
| 43 | + <input type="file" onChange={handleChange} /> |
| 44 | + <Button type="primary" className="parser-btn" onClick={parser}> |
| 45 | + 编译 |
| 46 | + </Button> |
| 47 | + </div> |
| 48 | + <div className="body"> |
| 49 | + <div className="content left"> |
| 50 | + <Input.TextArea className="file-content" rows={20} disabled value={input} /> |
| 51 | + </div> |
| 52 | + <div className="content right"> |
| 53 | + <Input.TextArea className="file-content" rows={20} disabled value={input} /> |
| 54 | + </div> |
| 55 | + </div> |
| 56 | + </AssemblerBox> |
| 57 | + </Layout.Content> |
| 58 | + </Layout> |
| 59 | + ); |
| 60 | +}; |
| 61 | + |
| 62 | +export default Assembler; |
0 commit comments