1
0

feat: 启动参数超时和日志保留天数改用下拉预设选择

This commit is contained in:
2026-05-08 00:26:35 +08:00
parent e719d3c8f1
commit 6b00045f4e
2 changed files with 53 additions and 13 deletions

View File

@@ -4,11 +4,34 @@ import { useStartupSettings, useSaveStartupSettings } from '@/hooks/useSettings'
import type { StartupConfig } from '@/types'
import type { SubmitContext } from 'tdesign-react/es/form/type'
const DURATION_PLACEHOLDERS = {
readTimeout: '例如 30s',
writeTimeout: '例如 30s',
connMaxLifetime: '例如 1h',
}
const TIMEOUT_OPTIONS = [
{ label: '5 秒', value: '5s' },
{ label: '10 秒', value: '10s' },
{ label: '15 秒', value: '15s' },
{ label: '30 秒', value: '30s' },
{ label: '1 分钟', value: '60s' },
{ label: '2 分钟', value: '120s' },
{ label: '5 分钟', value: '300s' },
]
const CONN_LIFETIME_OPTIONS = [
{ label: '5 分钟', value: '5m' },
{ label: '15 分钟', value: '15m' },
{ label: '30 分钟', value: '30m' },
{ label: '1 小时', value: '1h' },
{ label: '2 小时', value: '2h' },
{ label: '4 小时', value: '4h' },
]
const MAX_AGE_OPTIONS = [
{ label: '1 天', value: 1 },
{ label: '3 天', value: 3 },
{ label: '7 天', value: 7 },
{ label: '14 天', value: 14 },
{ label: '30 天', value: 30 },
{ label: '60 天', value: 60 },
{ label: '90 天', value: 90 },
]
function flattenConfig(c: StartupConfig): Record<string, unknown> {
return {
@@ -140,11 +163,11 @@ export function StartupSettingsCard() {
<Form.FormItem label='端口' name='server.port' rules={[{ required: true, message: '请输入端口' }]}>
<InputNumber min={1} max={65535} style={{ width: '100%' }} />
</Form.FormItem>
<Form.FormItem label='读超时' name='server.readTimeout' rules={[{ required: true, message: '请输入读超时' }]}>
<Input placeholder={DURATION_PLACEHOLDERS.readTimeout} />
<Form.FormItem label='读超时' name='server.readTimeout' rules={[{ required: true, message: '请选择读超时' }]}>
<Select options={TIMEOUT_OPTIONS} />
</Form.FormItem>
<Form.FormItem label='写超时' name='server.writeTimeout' rules={[{ required: true, message: '请输入写超时' }]}>
<Input placeholder={DURATION_PLACEHOLDERS.writeTimeout} />
<Form.FormItem label='写超时' name='server.writeTimeout' rules={[{ required: true, message: '请选择写超时' }]}>
<Select options={TIMEOUT_OPTIONS} />
</Form.FormItem>
<Divider />
@@ -212,9 +235,9 @@ export function StartupSettingsCard() {
<Form.FormItem
label='连接最大生命周期'
name='database.connMaxLifetime'
rules={[{ required: true, message: '请输入连接最大生命周期' }]}
rules={[{ required: true, message: '请选择连接最大生命周期' }]}
>
<Input placeholder={DURATION_PLACEHOLDERS.connMaxLifetime} />
<Select options={CONN_LIFETIME_OPTIONS} />
</Form.FormItem>
<Divider />
@@ -248,9 +271,9 @@ export function StartupSettingsCard() {
<Form.FormItem
label='最大保留天数'
name='log.maxAge'
rules={[{ required: true, message: '请输入最大保留天数' }]}
rules={[{ required: true, message: '请选择最大保留天数' }]}
>
<InputNumber min={0} suffix=' 天' style={{ width: '100%' }} />
<Select options={MAX_AGE_OPTIONS} />
</Form.FormItem>
<Form.FormItem label='压缩旧日志' name='log.compress'>
<Switch />

View File

@@ -408,6 +408,23 @@ TBD - 提供供应商、模型配置和总览的前端管理界面
- **THEN** 前端 SHALL NOT 展示配置来源标签
- **THEN** 前端 SHALL 直接展示 `database.password` 字段值
#### Scenario: 超时时间字段使用下拉预设选择
- **WHEN** 前端渲染启动参数设置表单
- **THEN** `server.readTimeout` 字段 SHALL 使用 Select 下拉组件提供以下预设选项5 秒、10 秒、15 秒、30 秒、1 分钟、2 分钟、5 分钟
- **THEN** `server.writeTimeout` 字段 SHALL 使用 Select 下拉组件,提供与 readTimeout 相同的预设选项
- **THEN** `database.connMaxLifetime` 字段 SHALL 使用 Select 下拉组件提供以下预设选项5 分钟、15 分钟、30 分钟、1 小时、2 小时、4 小时
- **THEN** duration 字段的 Select value SHALL 使用 Go duration 字符串格式(如 `"30s"``"1h"`
- **THEN** duration 字段的 Select label SHALL 使用中文单位显示(如 `"30 秒"``"1 小时"`
#### Scenario: 日志最大保留天数使用下拉预设选择
- **WHEN** 前端渲染启动参数设置表单中的 `log.maxAge` 字段
- **THEN** `log.maxAge` 字段 SHALL 使用 Select 下拉组件
- **THEN** Select SHALL 提供以下预设选项1 天、3 天、7 天、14 天、30 天、60 天、90 天
- **THEN** Select value SHALL 使用数字类型
- **THEN** Select label SHALL 使用中文单位显示(如 `"30 天"`
#### Scenario: 数据库驱动表单切换
- **WHEN** 启动参数设置中的 `database.driver``sqlite`