fix: stabilize settings form hydration
This commit is contained in:
4
frontend/package-lock.json
generated
4
frontend/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "planet-frontend",
|
||||
"version": "0.22.7",
|
||||
"version": "0.22.8",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "planet-frontend",
|
||||
"version": "0.22.7",
|
||||
"version": "0.22.8",
|
||||
"dependencies": {
|
||||
"@ant-design/icons": "^5.2.6",
|
||||
"antd": "^5.12.5",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "planet-frontend",
|
||||
"version": "0.22.7",
|
||||
"version": "0.22.8",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@ant-design/icons": "^5.2.6",
|
||||
|
||||
@@ -75,6 +75,9 @@ function Settings() {
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [savingCollectorId, setSavingCollectorId] = useState<number | null>(null)
|
||||
const [collectors, setCollectors] = useState<CollectorSettings[]>([])
|
||||
const [systemSettings, setSystemSettings] = useState<SystemSettings | null>(null)
|
||||
const [notificationSettings, setNotificationSettings] = useState<NotificationSettings | null>(null)
|
||||
const [securitySettings, setSecuritySettings] = useState<SecuritySettings | null>(null)
|
||||
const collectorTableRegionRef = useRef<HTMLDivElement | null>(null)
|
||||
const [collectorTableHeight, setCollectorTableHeight] = useState(360)
|
||||
const [systemForm] = Form.useForm<SystemSettings>()
|
||||
@@ -85,9 +88,9 @@ function Settings() {
|
||||
try {
|
||||
setLoading(true)
|
||||
const response = await axios.get('/api/v1/settings')
|
||||
systemForm.setFieldsValue(response.data.system)
|
||||
notificationForm.setFieldsValue(response.data.notifications)
|
||||
securityForm.setFieldsValue(response.data.security)
|
||||
setSystemSettings(response.data.system)
|
||||
setNotificationSettings(response.data.notifications)
|
||||
setSecuritySettings(response.data.security)
|
||||
setCollectors(response.data.collectors || [])
|
||||
} catch (error) {
|
||||
message.error('获取系统配置失败')
|
||||
@@ -101,6 +104,24 @@ function Settings() {
|
||||
fetchSettings()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading && systemSettings) {
|
||||
systemForm.setFieldsValue(systemSettings)
|
||||
}
|
||||
}, [loading, systemForm, systemSettings])
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading && notificationSettings) {
|
||||
notificationForm.setFieldsValue(notificationSettings)
|
||||
}
|
||||
}, [loading, notificationForm, notificationSettings])
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading && securitySettings) {
|
||||
securityForm.setFieldsValue(securitySettings)
|
||||
}
|
||||
}, [loading, securityForm, securitySettings])
|
||||
|
||||
useEffect(() => {
|
||||
const updateTableHeight = () => {
|
||||
const regionHeight = collectorTableRegionRef.current?.offsetHeight || 0
|
||||
@@ -257,6 +278,7 @@ function Settings() {
|
||||
{
|
||||
key: 'system',
|
||||
label: '系统显示',
|
||||
forceRender: true,
|
||||
children: (
|
||||
<SettingsPanel loading={loading}>
|
||||
<Form form={systemForm} layout="vertical" onFinish={(values) => saveSection('system', values)}>
|
||||
@@ -283,6 +305,7 @@ function Settings() {
|
||||
{
|
||||
key: 'notifications',
|
||||
label: '通知策略',
|
||||
forceRender: true,
|
||||
children: (
|
||||
<SettingsPanel loading={loading}>
|
||||
<Form form={notificationForm} layout="vertical" onFinish={(values) => saveSection('notifications', values)}>
|
||||
@@ -309,6 +332,7 @@ function Settings() {
|
||||
{
|
||||
key: 'security',
|
||||
label: '安全策略',
|
||||
forceRender: true,
|
||||
children: (
|
||||
<SettingsPanel loading={loading}>
|
||||
<Form form={securityForm} layout="vertical" onFinish={(values) => saveSection('security', values)}>
|
||||
|
||||
Reference in New Issue
Block a user