Commit 7632c25c by weiw

fix:根据环境变量控制显示的图标

parent d42546d4
This diff was suppressed by a .gitattributes entry.
......@@ -136,7 +136,7 @@ export const Chat: React.FC = () => {
abortControllerRef.current = new AbortController()
let fetchUrl = `/conversation/api/conversation/mobile/v1/submit_question_stream`
const proxy = import.meta.env.MODE === 'dev' ? '/api' : '/dev-sdream-api'
const proxy = import.meta.env.MODE !== 'prod' ? '/api' : '/dev-sdream-api'
fetchUrl = proxy + fetchUrl
fetchStreamResponse(
......
......@@ -6,6 +6,7 @@ import { ChatAnswerRecommend } from './ChatAnswerRecommend'
import { ChatMaxCount } from './ChatMaxCount'
import type { Answer, ChatRecord } from '@/types/chat'
import AvatarBot from '@/assets/avatarBot.png'
import AIIcon from '@/assets/ai-icon.png'
import { useAppDispatch } from '@/store/hook'
import { setIsAsking } from '@/store/chatSlice'
import SdreamLoading from '@/components/SdreamLoading'
......@@ -24,6 +25,7 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
const [innerRecord, setInnerRecord] = useState<ChatRecord>(record)
const [isTyping, setIsTyping] = useState(false)
const dispatch = useAppDispatch()
const viteOutputObj = import.meta.env.VITE_OUTPUT_OBJ || 'open'
const handleTyping = () => {
setIsTyping(true)
......@@ -53,21 +55,40 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
index === showIndex && (
<div className="chatItemBotContainer w-full" key={`${item.recordId}-${index}`}>
<div className="flex">
<Avatar className="sm:mr-[20px] hidden sm:block flex-shrink-0" src={AvatarBot} />
<Avatar
className="sm:mr-[20px] hidden sm:block flex-shrink-0"
src={viteOutputObj === 'inner' ? AIIcon : AvatarBot}
/>
<div
style={{ background: '#F7FAFD' }}
className="rounded-[20px] box-border px-[16px] py-[12px] sm:px-[24px] sm:py-[20px] relative"
>
{(item.answer?.length || item.cardList?.length)
? (
<div className="content">
{item.isShow && <ChatAnswerShower onSubmitQuestion={onSubmitQuestion} isLastAnswer={isLastAnswer} answer={item} />}
{!item.isShow && !item.isChatMaxCount && <ChatAnswerParser onSubmitQuestion={onSubmitQuestion} isLastAnswer={isLastAnswer} isStopTyping={item.isStopTyping} onTyping={handleTyping} onComplate={() => handleComplate(item)} answer={item} />}
{!item.isShow && item.isChatMaxCount && <ChatMaxCount />}
</div>
)
: <SdreamLoading />}
{item.answer?.length || item.cardList?.length
? (
<div className="content">
{item.isShow && (
<ChatAnswerShower
onSubmitQuestion={onSubmitQuestion}
isLastAnswer={isLastAnswer}
answer={item}
/>
)}
{!item.isShow && !item.isChatMaxCount && (
<ChatAnswerParser
onSubmitQuestion={onSubmitQuestion}
isLastAnswer={isLastAnswer}
isStopTyping={item.isStopTyping}
onTyping={handleTyping}
onComplate={() => handleComplate(item)}
answer={item}
/>
)}
{!item.isShow && item.isChatMaxCount && <ChatMaxCount />}
</div>
)
: (
<SdreamLoading />
)}
</div>
<div className="hidden sm:block w-[65px] flex-shrink-0"></div>
</div>
......@@ -79,11 +100,9 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
</div>
)}
{isLastAnswer
&& !item.isChatMaxCount
&& isShowRecommend
&& recommendUseAnswer
&& <ChatAnswerRecommend onSubmitQuestion={onSubmitQuestion} answer={recommendUseAnswer} />}
{isLastAnswer && !item.isChatMaxCount && isShowRecommend && recommendUseAnswer && (
<ChatAnswerRecommend onSubmitQuestion={onSubmitQuestion} answer={recommendUseAnswer} />
)}
<div className="h-[20px] sm:h-[32px] w-full"></div>
</div>
)
......
import { Avatar } from '@heroui/react'
import { motion } from 'framer-motion'
import AvatarBot from '@/assets/avatarBot.png'
import AIIcon from '@/assets/ai-icon.png'
export const ChatWelcome: React.FC = () => {
const viteOutputObj = import.meta.env.VITE_OUTPUT_OBJ || 'open'
return (
<div className="chatWelcomeContainer w-full">
<div className="h-[20px] sm:h-[32px] w-full"></div>
<div className="flex">
<Avatar className="mr-[12px] hidden sm:block flex-shrink-0" src={AvatarBot} />
<Avatar className="mr-[12px] hidden sm:block flex-shrink-0" src={viteOutputObj === 'inner' ? AIIcon : AvatarBot} />
<motion.div
className="sm:ml-[20px] rounded-[20px] box-border px-[16px] py-[16px] sm:px-[24px] sm:py-[20px]"
style={{ background: '#F7FAFD' }}
......
......@@ -11,8 +11,7 @@ import { createConversation, fetchConversations } from '@/store/conversationSlic
import { useAppDispatch } from '@/store/hook'
import { fetchQuestionList } from '@/api/home'
import SdreamLoading from '@/components/SdreamLoading'
// import { fetchLoginByToken } from '@/api/common'
import { fetchLoginByUid } from '@/api/common'
import { fetchLoginByToken, fetchLoginByUid } from '@/api/common'
function getAnimationProps(delay: number) {
return {
......@@ -41,6 +40,7 @@ function getAnimationProps(delay: number) {
}
export const Home: React.FC = () => {
const viteOutputObj = import.meta.env.VITE_OUTPUT_OBJ || 'open'
const [isLoading, setIsLoading] = useState(false)
const dispatch = useAppDispatch()
const location = useLocation()
......@@ -86,11 +86,11 @@ export const Home: React.FC = () => {
}
}
}
catch (error) {
catch (error) {
// 可以在这里添加错误处理逻辑
console.error('Failed to fetch chat records:', error)
}
finally {
finally {
setIsLoading(false)
}
}, [])
......@@ -119,27 +119,35 @@ export const Home: React.FC = () => {
if (hasFetched.current) {
return
}
hasFetched.current = true
const url = new URL(window.location.href)
// 获取查询参数
const searchParams = new URLSearchParams(url.search)
const _loginCode = searchParams.get('loginCode')
// const res = await fetchLoginByToken(loginCode)
// 模拟登录 可以用来测试
const res = await fetchLoginByUid('123123')
let res = {} as any
if (viteOutputObj === 'inner') {
res = await fetchLoginByToken(_loginCode)
}
else {
// 模拟登录 可以用来测试
res = await fetchLoginByUid('123123')
}
if (res.data) {
setToken(res.data.token)
// 主动触发 storage 事件,确保其他组件能监听到变化
window.dispatchEvent(new StorageEvent('storage', {
key: '__TOKEN__',
oldValue: token,
newValue: res.data.token,
url: window.location.href,
storageArea: localStorage,
}))
window.dispatchEvent(
new StorageEvent('storage', {
key: '__TOKEN__',
oldValue: token,
newValue: res.data.token,
url: window.location.href,
storageArea: localStorage,
}),
)
await getQuestionList()
initConversation()
......@@ -151,7 +159,7 @@ export const Home: React.FC = () => {
if (!token) {
login()
}
else {
else {
getQuestionList()
initConversation()
dispatch(fetchConversations())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment