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 />