From db8604cb26485d40eb9b191939a20d2dac4431b4 Mon Sep 17 00:00:00 2001 From: Vibe Studio Date: Wed, 21 Jan 2026 08:48:42 +0000 Subject: [PATCH] Update from Vibe Studio --- src/pages/spellcheck/index.tsx | 194 +++++++++++++++++++++++++++++++++ src/router/index.tsx | 4 + 2 files changed, 198 insertions(+) create mode 100644 src/pages/spellcheck/index.tsx diff --git a/src/pages/spellcheck/index.tsx b/src/pages/spellcheck/index.tsx new file mode 100644 index 0000000..de623c7 --- /dev/null +++ b/src/pages/spellcheck/index.tsx @@ -0,0 +1,194 @@ +import React, { useState } from 'react'; +import { PageHeader, Form, Input, Card, Button, message, Spin } from 'antd'; +import { fetchSpellCheck } from '@/api/spellcheck'; + +const { TextArea } = Input; + +interface SpellCheckState { + originalText: string; + correctedText: string; + loading: boolean; + error: string | null; +} + +const SpellCheckPage: React.FC = () => { + const [form] = Form.useForm(); + const [state, setState] = useState({ + originalText: '', + correctedText: '', + loading: false, + error: null + }); + + /** + * 处理错别字检测与修正 + */ + const handleGenerate = async () => { + try { + // 验证输入内容 + const values = await form.validateFields(); + const userInput = values.user_input?.trim(); + + if (!userInput) { + message.error('请输入需要检测的文本内容'); + return; + } + + // 设置加载状态 + setState(prev => ({ + ...prev, + originalText: userInput, + correctedText: '', + loading: true, + error: null + })); + + // 调用API获取修正结果 + const correctedResult = await fetchSpellCheck({ user_input: userInput }); + + setState(prev => ({ + ...prev, + correctedText: correctedResult, + loading: false + })); + + message.success('错别字检测完成'); + } catch (error) { + console.error('错别字检测失败:', error); + setState(prev => ({ + ...prev, + loading: false, + error: error instanceof Error ? error.message : '检测失败,请重试' + })); + message.error('检测失败,请重试'); + } + }; + + /** + * 重置表单 + */ + const handleReset = () => { + form.resetFields(); + setState({ + originalText: '', + correctedText: '', + loading: false, + error: null + }); + }; + + return ( +
+
+ {/* 页面标题区 */} + + + {/* 参数输入区 */} + +
+ + 待检测文本 + + } + rules={[ + { required: true, message: '请输入需要检测的文本内容' }, + { min: 1, message: '文本内容不能为空' } + ]} + > +