feat: 更新页面样式

master
xjs 2025-04-29 17:49:29 +08:00
parent 52e849324f
commit edfc853931
5 changed files with 26 additions and 27 deletions

View File

@ -99,8 +99,8 @@ export default function Antechamber() {
}; };
return ( return (
<div className="flex flex-col items-center h-full"> <div className="flex flex-col items-center h-full">
<AntechamberHeader toRoom={toRoom} /> <AntechamberHeader />
<AntechamberScore toRoom={toRoom} /> <AntechamberScore />
<AntechamberWishList /> <AntechamberWishList />
<AntechamberFile /> <AntechamberFile />
<AntechamberReport /> <AntechamberReport />

View File

@ -1,4 +1,4 @@
import { useState, useEffect } from "react"; import { useState, useEffect, useContext } from "react";
import HelloGIF from "/icons/hello.gif"; import HelloGIF from "/icons/hello.gif";
import WhatsThing from "/icons/whatsThing.png"; import WhatsThing from "/icons/whatsThing.png";
@ -7,16 +7,16 @@ import RightIcon from "/icons/right.png";
import styles from "./index.module.css"; import styles from "./index.module.css";
import { fetchQuestions } from "@/apis/questions"; import { fetchQuestions } from "@/apis/questions";
import { useAbortController } from "@/hooks/useAbortController"; import { useAbortController } from "@/hooks/useAbortController";
import { RealtimeClientContext } from "../Provider/RealtimeClientProvider";
type Props = {
toRoom: ({initMessage,fileUrl}:{initMessage?:string,fileUrl?:string}) =>void;
};
export default function HeaderGroup({ toRoom }: Props) { export default function HeaderGroup() {
const [isRotating, setIsRotating] = useState(false); const [isRotating, setIsRotating] = useState(false);
const [displayQuestions, setDisplayQuestions] = useState<string[]>([]); const [displayQuestions, setDisplayQuestions] = useState<string[]>([]);
const [allQuestions, setAllQuestions] = useState<string[]>([]); const [allQuestions, setAllQuestions] = useState<string[]>([]);
const { handleConnect } = useContext(RealtimeClientContext);
const { getSignal } = useAbortController(); const { getSignal } = useAbortController();
// 随机获取4个问题的函数 // 随机获取4个问题的函数
@ -64,7 +64,7 @@ export default function HeaderGroup({ toRoom }: Props) {
}; };
const handleQuestion = async (question: string) => { const handleQuestion = async (question: string) => {
toRoom({initMessage:question}); handleConnect({initMessage:question});
}; };
return ( return (

View File

@ -4,12 +4,11 @@ import { useSearchParams } from 'react-router-dom';
import MyInputIcon from '/icons/myInput.png'; import MyInputIcon from '/icons/myInput.png';
import RightBlueIcon from '/icons/rightBlue.png'; import RightBlueIcon from '/icons/rightBlue.png';
import style from './index.module.css'; import style from './index.module.css';
import { RealtimeClientContext } from '../Provider/RealtimeClientProvider';
import { useContext } from 'react';
type Props = {
toRoom: ({initMessage,fileUrl}:{initMessage?:string,fileUrl?:string}) => void;
};
export default function MyInput({ toRoom }: Props) { export default function MyInput() {
const [searchParams] = useSearchParams() const [searchParams] = useSearchParams()
@ -17,9 +16,11 @@ export default function MyInput({ toRoom }: Props) {
const subjectGroup = searchParams.get('subjectGroup') || '物/化/史' const subjectGroup = searchParams.get('subjectGroup') || '物/化/史'
const expectedScore = searchParams.get('expectedScore') || 500 const expectedScore = searchParams.get('expectedScore') || 500
const { handleConnect } = useContext(RealtimeClientContext);
const handleQuestion = async () => { const handleQuestion = async () => {
toRoom({initMessage:`我的高考地点在${provinceName},我选择的科目是${subjectGroup},我的高考分数为${expectedScore}分。帮我出一个科学的参考志愿表`}); handleConnect({initMessage:`我的高考地点在${provinceName},我选择的科目是${subjectGroup},我的高考分数为${expectedScore}分。帮我出一个科学的参考志愿表`});
}; };
return ( return (

View File

@ -168,16 +168,13 @@ export const RealtimeClientProvider = ({
try { try {
if (!clientRef.current) { if (!clientRef.current) {
await initClient({ initMessage, fileInfo }); await initClient({ initMessage, fileInfo });
} else {
await handleDisconnect();
await initClient({ initMessage, fileInfo });
} }
await clientRef.current?.connect(); await clientRef.current?.connect();
await clientRef.current?.setAudioEnable(false); await clientRef.current?.setAudioEnable(false);
setAudioEnabled(false); setAudioEnabled(false);
} catch (error) { } catch (error) {
console.error(error); // console.error(error);
if (error instanceof RealtimeAPIError) { if (error instanceof RealtimeAPIError) {
switch (error.code) { switch (error.code) {
case RealtimeError.CREATE_ROOM_ERROR: case RealtimeError.CREATE_ROOM_ERROR:
@ -275,7 +272,7 @@ export const RealtimeClientProvider = ({
content: JSON.stringify([ content: JSON.stringify([
{ {
type: "text", type: "text",
text: "帮我解读这个文件,结合当下的专业行情以及对该专业未来的发展趋势,简介的给出大学建议", text: "帮我解读这个文件,结合当下的专业行情以及对该专业未来的发展趋势,简介的给出志愿建议",
}, },
{ type: "image", file_url: fileInfo.url }, { type: "image", file_url: fileInfo.url },
]), ]),
@ -294,6 +291,12 @@ export const RealtimeClientProvider = ({
client.on(EventNames.ALL, (_eventName, event: any) => { client.on(EventNames.ALL, (_eventName, event: any) => {
// AI智能体设置 // AI智能体设置
if(_eventName === 'server.error'){
// 长期不活动,服务端终结了
handleDisconnect();
}
if ( if (
event.event_type !== ChatEventType.CONVERSATION_MESSAGE_DELTA && event.event_type !== ChatEventType.CONVERSATION_MESSAGE_DELTA &&
event.event_type !== ChatEventType.CONVERSATION_MESSAGE_COMPLETED && event.event_type !== ChatEventType.CONVERSATION_MESSAGE_COMPLETED &&
@ -362,9 +365,7 @@ export const RealtimeClientProvider = ({
event.data.role !== RoleType.Assistant) event.data.role !== RoleType.Assistant)
) { ) {
// lastEvent = event; // lastEvent = event;
if(event.event_type === ChatEventType.CONVERSATION_MESSAGE_DELTA && fileParseStatusRef.current === 2){ if(event.event_type === ChatEventType.CONVERSATION_MESSAGE_DELTA && fileParseStatusRef.current === 2){
console.log("重置了");
fileParseStatusRef.current = -1; fileParseStatusRef.current = -1;
} }
return [ return [
@ -454,9 +455,6 @@ export const RealtimeClientProvider = ({
setIsConnected(true); setIsConnected(true);
}); });
client.on(EventNames.ERROR, (_error: any) => {
setIsConnected(false);
});
}, },
[clientRef.current] [clientRef.current]
); );

View File

@ -31,7 +31,7 @@ export default function RoomConversation() {
<img <img
src="/icons/conversation-bg.png" src="/icons/conversation-bg.png"
alt="background" alt="background"
className="w-[252px] h-[49px] object-contain absolute top-[-50%] z-[-1] left-[50%] translate-x-[-50%]" className="w-[252px] h-[59px] object-contain absolute top-[-50%] z-[-1] left-[50%] translate-x-[-50%] max-w-[unset]"
/> />
HeyAI HeyAI
</div> </div>
@ -54,7 +54,7 @@ export default function RoomConversation() {
: "bg-blue-500 text-white rounded-tr-none" : "bg-blue-500 text-white rounded-tr-none"
}`} }`}
> >
{typeof message.fileParseStatus === "undefined" ? ( {typeof message.fileParseStatus === "undefined" && typeof message.fileInfo === 'undefined' ? (
<ReactMarkdown remarkPlugins={[gfm]}> <ReactMarkdown remarkPlugins={[gfm]}>
{message.content} {message.content}
</ReactMarkdown> </ReactMarkdown>
@ -93,9 +93,9 @@ export default function RoomConversation() {
</div> </div>
</div> </div>
))} ))}
<div ref={messagesEndRef} /> <div ref={messagesEndRef} />
</div> </div>
<div className="text-[12px] text-[#999] font-[400] text-center mt-auto mb-[7px]">AI</div>
</div> </div>
); );
} }