diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 5469c55..7d85e16 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -77,6 +77,14 @@ function App() { } /> + + + + } + /> } /> + + + + } + /> { - const isActive = location.pathname === item.href; + const isActive = location.pathname === item.href || location.pathname.startsWith(`${item.href}/`); return ( ('list') +export function Channels({ createMode = false }: { createMode?: boolean }) { + const navigate = useNavigate() + const [view, setView] = useState<'list' | 'form'>(createMode ? 'form' : 'list') const [editMode, setEditMode] = useState('form') const [modelEditorMode, setModelEditorMode] = useState('visual') const [editingKey, setEditingKey] = useState(null) @@ -426,8 +428,7 @@ export function Channels() { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['channels'] }) addToast(editingKey ? '渠道更新成功' : '渠道添加成功', 'success') - resetForm() - setView('list') + closeForm() }, onError: (error: Error) => { addToast('保存失败:' + error.message, 'error') @@ -464,7 +465,7 @@ export function Channels() { }, }) - const resetForm = () => { + const resetForm = useCallback(() => { setFormData(createDefaultChannelFormData()) setChannelKey('') setJsonValue('') @@ -474,11 +475,30 @@ export function Channels() { setModelEditorMode('visual') setEditingKey(null) setEditMode('form') + }, []) + + useEffect(() => { + if (createMode) { + resetForm() + setView('form') + return + } + + setView('list') + }, [createMode, resetForm]) + + const closeForm = () => { + resetForm() + setView('list') + + if (createMode) { + navigate('/channels', { replace: true }) + } } const handleAdd = () => { resetForm() - setView('form') + navigate('/channels/new') } const handleEdit = (channel: Channel) => { @@ -827,7 +847,7 @@ export function Channels() {
- @@ -1051,7 +1071,7 @@ export function Channels() { )}
- @@ -597,7 +617,7 @@ export function Tokens() { {/* Actions */}
-