@@ -4,6 +4,7 @@ import Navbar from '../components/Navbar'
|
|||||||
import {Book, Code2, Download, Edit, FileJson, FileUp, Image as ImageIcon, Plus, Search, Trash2, X} from 'lucide-react'
|
import {Book, Code2, Download, Edit, FileJson, FileUp, Image as ImageIcon, Plus, Search, Trash2, X} from 'lucide-react'
|
||||||
import {type Character, characterApi} from '../api/character'
|
import {type Character, characterApi} from '../api/character'
|
||||||
import {type RegexScript, regexScriptApi} from '../api/regex'
|
import {type RegexScript, regexScriptApi} from '../api/regex'
|
||||||
|
import {useAppStore} from '../store'
|
||||||
|
|
||||||
interface WorldBookEntry {
|
interface WorldBookEntry {
|
||||||
keys: string[]
|
keys: string[]
|
||||||
|
|||||||
@@ -7,18 +7,28 @@ import CharacterPanel from '../components/CharacterPanel'
|
|||||||
import SettingsPanel from '../components/SettingsPanel'
|
import SettingsPanel from '../components/SettingsPanel'
|
||||||
import {type Conversation, conversationApi} from '../api/conversation'
|
import {type Conversation, conversationApi} from '../api/conversation'
|
||||||
import {type Character, characterApi} from '../api/character'
|
import {type Character, characterApi} from '../api/character'
|
||||||
|
import {useAppStore} from '../store'
|
||||||
|
|
||||||
export default function ChatPage() {
|
export default function ChatPage() {
|
||||||
const [searchParams] = useSearchParams()
|
const [searchParams] = useSearchParams()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [activePanel, setActivePanel] = useState<'chat' | 'settings'>('chat')
|
const [activePanel, setActivePanel] = useState<'chat' | 'settings'>('chat')
|
||||||
const [currentConversation, setCurrentConversation] = useState<Conversation | null>(null)
|
|
||||||
const [currentCharacter, setCurrentCharacter] = useState<Character | null>(null)
|
|
||||||
const [loading, setLoading] = useState(true)
|
|
||||||
const [backgroundImage, setBackgroundImage] = useState<string>()
|
const [backgroundImage, setBackgroundImage] = useState<string>()
|
||||||
const [showSidebar, setShowSidebar] = useState(true)
|
|
||||||
const [showCharacterPanel, setShowCharacterPanel] = useState(true)
|
const [showCharacterPanel, setShowCharacterPanel] = useState(true)
|
||||||
|
|
||||||
|
// 使用 MVU store
|
||||||
|
const {
|
||||||
|
currentConversation,
|
||||||
|
currentCharacter,
|
||||||
|
loading,
|
||||||
|
sidebarOpen: showSidebar,
|
||||||
|
setCurrentConversation,
|
||||||
|
setCurrentCharacter,
|
||||||
|
setLoading,
|
||||||
|
setSidebarOpen: setShowSidebar,
|
||||||
|
setVariable,
|
||||||
|
} = useAppStore()
|
||||||
|
|
||||||
// 从URL参数获取角色ID或对话ID
|
// 从URL参数获取角色ID或对话ID
|
||||||
const characterId = searchParams.get('character')
|
const characterId = searchParams.get('character')
|
||||||
const conversationId = searchParams.get('conversation')
|
const conversationId = searchParams.get('conversation')
|
||||||
@@ -67,12 +77,18 @@ export default function ChatPage() {
|
|||||||
// 加载对话关联的角色
|
// 加载对话关联的角色
|
||||||
const charResp = await characterApi.getCharacterById(convResp.data.characterId)
|
const charResp = await characterApi.getCharacterById(convResp.data.characterId)
|
||||||
setCurrentCharacter(charResp.data)
|
setCurrentCharacter(charResp.data)
|
||||||
|
|
||||||
|
// 更新变量系统
|
||||||
|
setVariable('char', charResp.data.name)
|
||||||
}
|
}
|
||||||
// 如果有角色ID,创建新对话
|
// 如果有角色ID,创建新对话
|
||||||
else if (characterId) {
|
else if (characterId) {
|
||||||
const charResp = await characterApi.getCharacterById(Number(characterId))
|
const charResp = await characterApi.getCharacterById(Number(characterId))
|
||||||
setCurrentCharacter(charResp.data)
|
setCurrentCharacter(charResp.data)
|
||||||
|
|
||||||
|
// 更新变量系统
|
||||||
|
setVariable('char', charResp.data.name)
|
||||||
|
|
||||||
// 创建新对话
|
// 创建新对话
|
||||||
const convResp = await conversationApi.createConversation({
|
const convResp = await conversationApi.createConversation({
|
||||||
characterId: Number(characterId),
|
characterId: Number(characterId),
|
||||||
|
|||||||
Reference in New Issue
Block a user