style(web): translate the comments in the src/views directory into English

This commit is contained in:
zhaoying
2026-02-03 18:38:04 +08:00
parent a191e32f71
commit 9e195ea63b
155 changed files with 4169 additions and 586 deletions

View File

@@ -1,3 +1,14 @@
/*
* @Author: ZhaoYing
* @Date: 2026-02-03 17:44:04
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-02-03 17:44:04
*/
/**
* Prompt History Component
* Displays saved prompts with view, edit, and delete actions
*/
import React, { useRef, type MouseEvent } from 'react';
import { useTranslation } from 'react-i18next';
import { Tooltip, Space, App } from 'antd';
@@ -17,9 +28,11 @@ const History: React.FC<{ query: HistoryQuery; edit: (item: HistoryItem) => void
const detailRef = useRef<PromptDetailRef>(null)
const { message, modal } = App.useApp()
/** View prompt details */
const handleView = (item: HistoryItem) => {
detailRef.current?.handleOpen(item)
}
/** Delete prompt */
const handleDelete = (item: HistoryItem, e?: MouseEvent) => {
e?.preventDefault();
e?.stopPropagation();
@@ -39,6 +52,7 @@ const History: React.FC<{ query: HistoryQuery; edit: (item: HistoryItem) => void
})
}
/** Edit prompt */
const handleEdit = (item: HistoryItem) => {
edit(item)
}

View File

@@ -1,3 +1,14 @@
/*
* @Author: ZhaoYing
* @Date: 2026-02-03 17:44:15
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-02-03 17:44:15
*/
/**
* Prompt Editor Component
* AI-powered prompt optimization with chat interface and variable support
*/
import { type FC, useState, useRef, useEffect } from 'react';
import { Button, Form, Input, App, Row, Col } from 'antd';
import { useTranslation } from 'react-i18next';
@@ -40,6 +51,7 @@ const Prompt: FC<{ editVo: HistoryItem | null; refresh: () => void; }> = ({ edit
updateSession()
}, [editVo])
/** Update session ID */
const updateSession = () => {
console.log('updateSession')
createPromptSessions().then(res => {
@@ -48,6 +60,7 @@ const Prompt: FC<{ editVo: HistoryItem | null; refresh: () => void; }> = ({ edit
})
}
/** Send message to AI for prompt optimization */
const handleSend = () => {
if (!promptSession) return
if (!values.model_id) {
@@ -108,14 +121,17 @@ const Prompt: FC<{ editVo: HistoryItem | null; refresh: () => void; }> = ({ edit
setLoading(false)
})
}
/** Copy prompt to clipboard */
const handleCopy = () => {
if (!values.current_prompt || values?.current_prompt?.trim() === '') return
copy(values.current_prompt)
message.success(t('common.copySuccess'))
}
/** Open variable modal */
const handleAdd = () => {
aiPromptVariableModalRef.current?.handleOpen()
}
/** Apply variable to editor */
const handleVariableApply = (value: string) => {
if (editorRef.current?.insertText) {
editorRef.current.insertText(value)
@@ -123,6 +139,7 @@ const Prompt: FC<{ editVo: HistoryItem | null; refresh: () => void; }> = ({ edit
form.setFieldValue('current_prompt', (values.current_prompt || '') + value)
}
}
/** Save prompt */
const handleSave = () => {
if (!values.current_prompt || !promptSession) {
return
@@ -133,6 +150,7 @@ const Prompt: FC<{ editVo: HistoryItem | null; refresh: () => void; }> = ({ edit
})
}
/** Refresh editor and clear state */
const handleRefresh = () => {
form.setFieldValue('current_prompt', undefined)
currentPromptValueRef.current = undefined;

View File

@@ -1,3 +1,14 @@
/*
* @Author: ZhaoYing
* @Date: 2026-02-03 17:43:51
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-02-03 17:43:51
*/
/**
* Prompt Detail Modal
* Displays full prompt details with copy, edit, and delete actions
*/
import { forwardRef, useImperativeHandle, useState } from 'react';
import { Flex, Button, App } from 'antd';
import { useTranslation } from 'react-i18next';
@@ -14,16 +25,18 @@ const PromptDetail = forwardRef<PromptDetailRef, { handleEdit: (item: HistoryIte
const [visible, setVisible] = useState(false);
const [data, setData] = useState<HistoryItem>({} as HistoryItem)
// 封装取消方法,添加关闭弹窗逻辑
/** Close modal */
const handleClose = () => {
setVisible(false);
};
/** Open modal with data */
const handleOpen = (vo: HistoryItem) => {
setVisible(true);
setData(vo)
};
const handleCopy = (text = '') => {
/** Copy text to clipboard */
const handleCopy = (text = '') => {
copy(text)
message.success(t('common.copySuccess'))
}

View File

@@ -1,3 +1,14 @@
/*
* @Author: ZhaoYing
* @Date: 2026-02-03 17:43:55
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-02-03 17:43:55
*/
/**
* Prompt Save Modal
* Modal for saving prompt with title input
*/
import { forwardRef, useImperativeHandle, useState } from 'react';
import { Form, Input, App } from 'antd';
import { useTranslation } from 'react-i18next';
@@ -8,6 +19,9 @@ import { savePrompt } from '@/api/prompt'
const FormItem = Form.Item;
/**
* Component props
*/
interface PromptSaveModalProps {
refresh: () => void;
}
@@ -23,7 +37,7 @@ const PromptSaveModal = forwardRef<PromptSaveModalRef, PromptSaveModalProps>(({
const [data, setData] = useState<PromptReleaseData | null>(null)
const title = Form.useWatch(['title'], form)
// 封装取消方法,添加关闭弹窗逻辑
/** Close modal and reset form */
const handleClose = () => {
setVisible(false);
form.resetFields();
@@ -31,11 +45,12 @@ const PromptSaveModal = forwardRef<PromptSaveModalRef, PromptSaveModalProps>(({
setData(null)
};
/** Open modal with data */
const handleOpen = (vo: PromptReleaseData) => {
setData(vo)
setVisible(true);
};
// 封装保存方法,添加提交逻辑
/** Save prompt */
const handleSave = () => {
if (!title || title.trim() === '') {
message.warning(t('common.inputPlaceholder', { title: t('prompt.saveTitle') }))
@@ -57,7 +72,7 @@ const PromptSaveModal = forwardRef<PromptSaveModalRef, PromptSaveModalProps>(({
});
}
// 暴露给父组件的方法
/** Expose methods to parent component */
useImperativeHandle(ref, () => ({
handleOpen,
handleClose

View File

@@ -1,3 +1,14 @@
/*
* @Author: ZhaoYing
* @Date: 2026-02-03 17:43:58
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-02-03 17:43:58
*/
/**
* Prompt Variable Modal
* Modal for adding variables to prompt with autocomplete suggestions
*/
import { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
import { Form, AutoComplete, type AutoCompleteProps } from 'antd';
import { useTranslation } from 'react-i18next';
@@ -7,6 +18,9 @@ import RbModal from '@/components/RbModal'
const FormItem = Form.Item;
/**
* Component props
*/
interface PromptVariableModalProps {
refresh: (value: string) => void;
variables: string[];
@@ -28,6 +42,7 @@ const PromptVariableModal = forwardRef<PromptVariableModalRef, PromptVariableMod
label: `{{${key}}}`
})))
}, [variables])
/** Handle search and filter variables */
const handleSearch = (value: string) => {
const filterKeys = variables?.filter(key => key.includes(value))
@@ -44,18 +59,19 @@ const PromptVariableModal = forwardRef<PromptVariableModalRef, PromptVariableMod
}
}
// 封装取消方法,添加关闭弹窗逻辑
/** Close modal and reset form */
const handleClose = () => {
setVisible(false);
form.resetFields();
setLoading(false)
};
/** Open modal */
const handleOpen = () => {
setVisible(true);
form.resetFields();
};
// 封装保存方法,添加提交逻辑
/** Apply variable to editor */
const handleSave = () => {
const variableName = form.getFieldValue('variableName')
@@ -65,7 +81,7 @@ const PromptVariableModal = forwardRef<PromptVariableModalRef, PromptVariableMod
handleClose()
}
// 暴露给父组件的方法
/** Expose methods to parent component */
useImperativeHandle(ref, () => ({
handleOpen,
handleClose

View File

@@ -1,3 +1,14 @@
/*
* @Author: ZhaoYing
* @Date: 2026-02-03 17:44:09
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-02-03 17:44:09
*/
/**
* Prompt Management Page
* Main page with editor and history tabs for prompt optimization
*/
import { type FC, useState } from 'react';
import { type SegmentedProps, Flex } from 'antd';
import { useTranslation } from 'react-i18next';
@@ -8,6 +19,7 @@ import PromptEditor from './Prompt';
import History from './History'
import type { HistoryQuery, HistoryItem } from './types';
/** Available tab keys */
const tabs = ['editor', 'history']
const Prompt: FC = () => {
const { t } = useTranslation();
@@ -15,19 +27,23 @@ const Prompt: FC = () => {
const [query, setQuery] = useState<HistoryQuery>({});
const [editVo, setEditVo] = useState<HistoryItem | null>(null)
/** Handle tab change */
const handleChangeTab = (value: SegmentedProps['value']) => {
setActiveTab(value)
setEditVo(null)
setQuery({})
}
/** Handle search in history */
const handleSearch = (value?: string) => {
setQuery(prev => ({ ...prev, keyword: value }))
}
/** Handle edit history item */
const handleEdit = (item: HistoryItem) => {
console.log('edit', item)
setEditVo(item)
setActiveTab('editor')
}
/** Refresh editor state */
const refresh = () => {
setEditVo(null)
}

View File

@@ -1,22 +1,43 @@
/*
* @Author: ZhaoYing
* @Date: 2026-02-03 17:44:18
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-02-03 17:44:18
*/
/**
* Prompt variable modal ref interface
*/
export interface PromptVariableModalRef {
handleOpen: () => void;
}
/**
* AI prompt form data
*/
export interface AiPromptForm {
model_id?: string;
message?: string;
current_prompt?: string;
}
/**
* Prompt release data
*/
export interface PromptReleaseData {
session_id: string;
title?: string;
prompt: string;
}
/**
* History query parameters
*/
export interface HistoryQuery extends Record<string, unknown> {
search?: string;
}
/**
* History item data
*/
export interface HistoryItem {
id: string;
title: string;
@@ -25,11 +46,17 @@ export interface HistoryItem {
first_message: string;
}
/**
* Prompt detail modal ref interface
*/
export interface PromptDetailRef {
handleOpen: (vo: HistoryItem) => void;
handleClose: () => void;
}
/**
* Prompt save modal ref interface
*/
export interface PromptSaveModalRef {
handleOpen: (vo: PromptReleaseData) => void;
}