Commit 7632c25c by weiw

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

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