mirror of https://github.com/Mai-with-u/MaiBot.git
feat(dashboard): integrate DynamicConfigForm for ChatSection POC
- Register ChatSectionHook as 'replace' mode field hook - Replace ChatSection rendering with DynamicConfigForm - Use hardcoded minimal schema (POC - API integration pending) - Preserve all existing state management and auto-save logic - TypeScript compilation: ✓ PASSED Complete Task 11 (Wave 3) Ref: WebUI config visualization refactor planpull/1496/head
parent
3fcf02866a
commit
c58ad64352
|
|
@ -69,6 +69,11 @@ import { useAutoSave, useConfigAutoSave } from './bot/hooks'
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
|
// 导入动态表单和 Hook 系统
|
||||||
|
import { DynamicConfigForm } from '@/components/dynamic-form'
|
||||||
|
import { fieldHooks } from '@/lib/field-hooks'
|
||||||
|
import { ChatSectionHook } from '@/routes/config/bot/hooks'
|
||||||
|
|
||||||
// ==================== 常量定义 ====================
|
// ==================== 常量定义 ====================
|
||||||
/** Toast 显示前的延迟时间 (毫秒) */
|
/** Toast 显示前的延迟时间 (毫秒) */
|
||||||
const TOAST_DISPLAY_DELAY = 500
|
const TOAST_DISPLAY_DELAY = 500
|
||||||
|
|
@ -308,6 +313,13 @@ function BotConfigPageContent() {
|
||||||
loadConfig()
|
loadConfig()
|
||||||
}, [loadConfig])
|
}, [loadConfig])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fieldHooks.register('chat', ChatSectionHook, 'replace')
|
||||||
|
return () => {
|
||||||
|
fieldHooks.unregister('chat')
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
// 使用模块化的 useAutoSave hook
|
// 使用模块化的 useAutoSave hook
|
||||||
const { triggerAutoSave, cancelPendingAutoSave } = useAutoSave(
|
const { triggerAutoSave, cancelPendingAutoSave } = useAutoSave(
|
||||||
initialLoadRef.current,
|
initialLoadRef.current,
|
||||||
|
|
@ -652,7 +664,24 @@ function BotConfigPageContent() {
|
||||||
|
|
||||||
{/* 聊天配置 */}
|
{/* 聊天配置 */}
|
||||||
<TabsContent value="chat" className="space-y-4">
|
<TabsContent value="chat" className="space-y-4">
|
||||||
{chatConfig && <ChatSection config={chatConfig} onChange={setChatConfig} />}
|
{chatConfig && (
|
||||||
|
<DynamicConfigForm
|
||||||
|
schema={{
|
||||||
|
className: 'ChatConfig',
|
||||||
|
classDoc: '聊天配置',
|
||||||
|
fields: [],
|
||||||
|
nested: {},
|
||||||
|
}}
|
||||||
|
values={{ chat: chatConfig }}
|
||||||
|
onChange={(field, value) => {
|
||||||
|
if (field === 'chat') {
|
||||||
|
setChatConfig(value as ChatConfig)
|
||||||
|
setHasUnsavedChanges(true)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
hooks={fieldHooks}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|
||||||
{/* 表达配置 */}
|
{/* 表达配置 */}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue