Skip to content

Commit f658425

Browse files
authored
Merge branch 'main' into line-number
2 parents 832f19a + d133149 commit f658425

File tree

5 files changed

+625
-30
lines changed

5 files changed

+625
-30
lines changed

src/components/Formater/index.tsx

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import alert from '@/components/Alert';
2-
import React, { useCallback, useEffect, useState } from 'react';
3-
import { Box, Grid, Button } from '@mui/material';
4-
import { CopyToClipboard } from 'react-copy-to-clipboard';
52
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
6-
import DownloadIcon from '@mui/icons-material/Download';
73
import DeleteIcon from '@mui/icons-material/Delete';
4+
import DownloadIcon from '@mui/icons-material/Download';
85
import FileUploadIcon from '@mui/icons-material/FileUpload';
9-
import MenuItem from '@mui/material/MenuItem';
6+
import { Box, Button, Grid } from '@mui/material';
107
import FormControl from '@mui/material/FormControl';
8+
import MenuItem from '@mui/material/MenuItem';
119
import Select from '@mui/material/Select';
12-
import AceEditor from 'react-ace';
13-
import xmlFormat from 'xml-formatter';
14-
import * as prettier from 'prettier/standalone';
1510
import babelPlugin from 'prettier/plugins/babel';
16-
import yamlPlugin from 'prettier/plugins/yaml';
11+
import estree from 'prettier/plugins/estree';
1712
import htmlPlugin from 'prettier/plugins/html';
1813
import cssPlugin from 'prettier/plugins/postcss';
1914
import tsPlugin from 'prettier/plugins/typescript';
20-
import estree from 'prettier/plugins/estree';
15+
import yamlPlugin from 'prettier/plugins/yaml';
16+
import * as prettier from 'prettier/standalone';
17+
import React, { useCallback, useEffect, useState } from 'react';
18+
import AceEditor from 'react-ace';
19+
import { CopyToClipboard } from 'react-copy-to-clipboard';
20+
import xmlFormat from 'xml-formatter';
2121

2222
import 'ace-builds/src-noconflict/ext-language_tools';
23-
import 'ace-builds/src-noconflict/mode-javascript';
2423
import 'ace-builds/src-noconflict/mode-css';
25-
import 'ace-builds/src-noconflict/mode-typescript';
2624
import 'ace-builds/src-noconflict/mode-html';
27-
import 'ace-builds/src-noconflict/mode-yaml';
28-
import 'ace-builds/src-noconflict/mode-xml';
25+
import 'ace-builds/src-noconflict/mode-javascript';
2926
import 'ace-builds/src-noconflict/mode-json';
27+
import 'ace-builds/src-noconflict/mode-typescript';
28+
import 'ace-builds/src-noconflict/mode-xml';
29+
import 'ace-builds/src-noconflict/mode-yaml';
3030
import 'ace-builds/src-noconflict/theme-monokai';
3131

3232
export enum Mode {
@@ -176,21 +176,7 @@ const Formater: React.FC<FormaterProps> = ({ mock, mode, accept }) => {
176176
}, []);
177177

178178
return (
179-
<Grid
180-
sx={{
181-
mt: '24px',
182-
maxWidth: '1020px',
183-
height: '100%',
184-
'#input *': {
185-
fontFamily: 'Mono',
186-
},
187-
'#output *': {
188-
fontFamily: 'Mono',
189-
},
190-
}}
191-
container
192-
spacing={2}
193-
>
179+
<>
194180
<Grid item xs={6}>
195181
<Box
196182
sx={{
@@ -298,7 +284,7 @@ const Formater: React.FC<FormaterProps> = ({ mock, mode, accept }) => {
298284
editorProps={{ $blockScrolling: true }}
299285
/>
300286
</Grid>
301-
</Grid>
287+
</>
302288
);
303289
};
304290

src/pages/cvencode.tsx

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import React, { useState } from 'react';
2+
import { Container, Grid, TextField, Button, Box } from '@mui/material';
3+
import SendIcon from '@mui/icons-material/Send';
4+
import TranslateIcon from '@mui/icons-material/Translate';
5+
import coreValuesEncoder from '@/utils/core-values-encoder';
6+
import MainContent from '@/components/MainContent';
7+
import alertActions from '@/components/Alert';
8+
9+
const Cvencode = () => {
10+
const [text, setText] = useState('');
11+
const [encryptedText, setEncryptedText] = useState('');
12+
13+
const handleTextChange = (event: React.ChangeEvent<HTMLInputElement>) => {
14+
setText(event.target.value);
15+
};
16+
17+
const handleEncryptedTextChange = (
18+
event: React.ChangeEvent<HTMLInputElement>
19+
) => {
20+
setEncryptedText(event.target.value);
21+
};
22+
23+
const handleEncode = () => {
24+
try {
25+
const encoded = coreValuesEncoder.encode(text);
26+
setEncryptedText(encoded);
27+
} catch (error) {
28+
const err = error as Error;
29+
console.log(err);
30+
alertActions.error('加密失败!');
31+
}
32+
};
33+
34+
const handleDecode = () => {
35+
try {
36+
const decoded = coreValuesEncoder.decode(encryptedText);
37+
setText(decoded);
38+
} catch (error) {
39+
const err = error as Error;
40+
console.log(err);
41+
alertActions.error('解密失败!');
42+
}
43+
};
44+
45+
return (
46+
<MainContent>
47+
<>
48+
<Container maxWidth='lg'>
49+
<Box sx={{ my: 4 }}>
50+
<Grid container spacing={2} alignItems='center'>
51+
<Grid item xs={12} md={5}>
52+
<TextField
53+
fullWidth
54+
label='待加密文本'
55+
placeholder='请输入要加密的文本'
56+
value={text}
57+
onChange={handleTextChange}
58+
variant='outlined'
59+
multiline
60+
rows={10}
61+
inputProps={{
62+
style: { fontFamily: 'monospace' },
63+
}}
64+
/>
65+
</Grid>
66+
<Grid
67+
item
68+
xs={12}
69+
md={2}
70+
container
71+
direction='column'
72+
alignItems='center'
73+
justifyContent='space-around'
74+
>
75+
<Button
76+
variant='contained'
77+
onClick={handleEncode}
78+
startIcon={<SendIcon />}
79+
sx={{ mb: 2 }}
80+
>
81+
加密
82+
</Button>
83+
<Button
84+
variant='contained'
85+
onClick={handleDecode}
86+
startIcon={<TranslateIcon />}
87+
>
88+
解密
89+
</Button>
90+
</Grid>
91+
<Grid item xs={12} md={5}>
92+
<TextField
93+
fullWidth
94+
label='社会主义核心价值观编码'
95+
placeholder='请输入要解密的编码文本'
96+
value={encryptedText}
97+
onChange={handleEncryptedTextChange}
98+
variant='outlined'
99+
multiline
100+
rows={10}
101+
inputProps={{
102+
style: { fontFamily: 'monospace' },
103+
}}
104+
/>
105+
</Grid>
106+
</Grid>
107+
</Box>
108+
</Container>
109+
</>
110+
</MainContent>
111+
);
112+
};
113+
114+
export default Cvencode;

0 commit comments

Comments
 (0)