import React, { useEffect, useMemo, useState } from 'react'; import { Button, Input, InputNumber, Space, Switch, Table, Tag, Typography, message } from 'antd'; import { ReloadOutlined, SaveOutlined, UndoOutlined } from '@ant-design/icons'; import { SycmCard } from '../../components/Common'; import { getSystemConfig, updateSystemConfig } from '../../api/admin'; import { DEFAULT_SIDEBAR_CONFIG, parseSidebarConfig } from '../../config/sidebarNavigation'; const { Text } = Typography; const clone = (value) => JSON.parse(JSON.stringify(value)); const SidebarSettings = () => { const [config, setConfig] = useState(() => clone(DEFAULT_SIDEBAR_CONFIG)); const [loading, setLoading] = useState(false); const [saving, setSaving] = useState(false); const loadConfig = async () => { try { setLoading(true); const result = await getSystemConfig(); setConfig(parseSidebarConfig(result?.sidebar_navigation)); } catch (error) { message.error(error.response?.data?.error || '加载侧边栏设置失败'); } finally { setLoading(false); } }; useEffect(() => { loadConfig(); }, []); const rows = useMemo(() => config.entries.flatMap((entry) => [ { ...entry, rowKey: entry.key, depth: 0 }, ...(entry.children || []).map((child) => ({ ...child, rowKey: `${entry.key}:${child.key}`, parentKey: entry.key, depth: 1, type: 'item' })), ]), [config.entries]); const updateRow = (record, patch) => { setConfig((current) => ({ ...current, entries: current.entries.map((entry) => { if (!record.parentKey) return entry.key === record.key ? { ...entry, ...patch } : entry; if (entry.key !== record.parentKey) return entry; return { ...entry, children: (entry.children || []).map((child) => child.key === record.key ? { ...child, ...patch } : child), }; }), })); }; const handleSave = async () => { try { setSaving(true); await updateSystemConfig({ sidebar_navigation: JSON.stringify(config) }); message.success('侧边栏设置已保存,刷新页面后生效'); } catch (error) { message.error(error.response?.data?.error || '保存侧边栏设置失败'); } finally { setSaving(false); } }; const columns = [ { title: '菜单名称', dataIndex: 'label', width: 280, render: (value, record) => (