Commit 9336bcb8 by Liu

fix:策略分析时展示效果

parent a3dec971
...@@ -40,11 +40,16 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -40,11 +40,16 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const [searchParams, setSearchParams] = useSearchParams() const [searchParams, setSearchParams] = useSearchParams()
const location = useLocation() const location = useLocation()
const toolIdFromUrl = searchParams.get('toolId') const toolIdFromUrl = searchParams.get('toolId')
const isFromTactics = searchParams.get('from') === 'tactics'
const fromCollect = location.state?.fromCollect const fromCollect = location.state?.fromCollect
// 获取工具列表 // 获取工具列表
const getToolList = async () => { const getToolList = async () => {
try { try {
if (isFromTactics) {
setToolList([])
return
}
// 从路由中获取 userRoles 参数 // 从路由中获取 userRoles 参数
const userRoles = getUserRolesForApi() const userRoles = getUserRolesForApi()
// 调用真实 API 获取工具列表 // 调用真实 API 获取工具列表
......
...@@ -40,10 +40,15 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -40,10 +40,15 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const [searchParams, setSearchParams] = useSearchParams() const [searchParams, setSearchParams] = useSearchParams()
const location = useLocation() const location = useLocation()
const toolIdFromUrl = searchParams.get('toolId') const toolIdFromUrl = searchParams.get('toolId')
const isFromTactics = searchParams.get('from') === 'tactics'
const fromCollect = location.state?.fromCollect const fromCollect = location.state?.fromCollect
// 获取工具列表 // 获取工具列表
const getToolList = async () => { const getToolList = async () => {
if (isFromTactics) {
setToolList([])
return
}
try { try {
// 从路由中获取 userRoles 参数 // 从路由中获取 userRoles 参数
const userRoles = getUserRolesForApi() const userRoles = getUserRolesForApi()
...@@ -291,8 +296,10 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -291,8 +296,10 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 组件加载时和路由参数变化时获取工具列表 // 组件加载时和路由参数变化时获取工具列表
useEffect(() => { useEffect(() => {
if (isFromTactics)
return
getToolList() getToolList()
}, [location.pathname, location.search]) }, [isFromTactics, location.pathname, location.search])
// 监听 sessionStorage 中的 showToolQuestion // 监听 sessionStorage 中的 showToolQuestion
useEffect(() => { useEffect(() => {
......
...@@ -43,6 +43,7 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => { ...@@ -43,6 +43,7 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => {
const [isHistoryVisible, setHistoryVisible] = useState(false) const [isHistoryVisible, setHistoryVisible] = useState(false)
const location = useLocation() const location = useLocation()
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const isFromTactics = new URLSearchParams(location.search).get('from') === 'tactics'
const [navBarVisibleLocal] = useSessionStorageState<string | undefined>( const [navBarVisibleLocal] = useSessionStorageState<string | undefined>(
'__NAV_BAR_VISIBLE_LOCAL__', '__NAV_BAR_VISIBLE_LOCAL__',
{ {
...@@ -64,34 +65,35 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => { ...@@ -64,34 +65,35 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => {
return ( return (
<motion.main className={styles.layoutMain}> <motion.main className={styles.layoutMain}>
{/* hidden */} {/* hidden */}
<motion.div {!isFromTactics && (
animate={navBarVisibleLocal === '0' ? isHistoryVisible ? 'shrunk' : 'expanded' : 'navTween'} <motion.div
variants={contentVariants} animate={navBarVisibleLocal === '0' ? isHistoryVisible ? 'shrunk' : 'expanded' : 'navTween'}
className={`fixed right-[-12px] top-[10px] z-[49] h-auto sm:relative flex sm:h-full items-center ${isHistoryVisible && !isMobile() ? 'w-[340px]' : 'w-[90px]'} box-border`} variants={contentVariants}
> className={`fixed right-[-12px] top-[10px] z-[49] h-auto sm:relative flex sm:h-full items-center ${isHistoryVisible && !isMobile() ? 'w-[340px]' : 'w-[90px]'} box-border`}
>
<Navbar
isHistoryVisible={isHistoryVisible}
onSetHistoryVisible={setHistoryVisible}
/>
<Navbar <HistoryBar isVisible={isHistoryVisible} onSetHistoryVisible={setHistoryVisible} />
isHistoryVisible={isHistoryVisible} {!isHistoryVisible && (
onSetHistoryVisible={setHistoryVisible} <motion.div
/> initial="hidden"
animate="visible"
<HistoryBar isVisible={isHistoryVisible} onSetHistoryVisible={setHistoryVisible} /> variants={{
{!isHistoryVisible && ( hidden: {
<motion.div x: -5,
initial="hidden" opacity: 0,
animate="visible" },
variants={{ }}
hidden: { className={`${styles.sidebarArrow} side-bar-arrow h-[42px] flex items-center`}
x: -5, >
opacity: 0, <MingcuteArrowsRightFill className="text-[#818d91]" />
}, </motion.div>
}} )}
className={`${styles.sidebarArrow} side-bar-arrow h-[42px] flex items-center`} </motion.div>
> )}
<MingcuteArrowsRightFill className="text-[#818d91]" />
</motion.div>
)}
</motion.div>
<motion.div <motion.div
variants={contentVariants} variants={contentVariants}
animate={navBarVisibleLocal === '0' ? '' : 'mainTween'} animate={navBarVisibleLocal === '0' ? '' : 'mainTween'}
......
...@@ -55,6 +55,7 @@ export const Chat: React.FC = () => { ...@@ -55,6 +55,7 @@ export const Chat: React.FC = () => {
const [currentToolName, setCurrentToolName] = useState<string | undefined>(undefined) const [currentToolName, setCurrentToolName] = useState<string | undefined>(undefined)
// 使用 ref 保存从 location.state 传递的 toolId,避免被异步操作覆盖 // 使用 ref 保存从 location.state 传递的 toolId,避免被异步操作覆盖
const toolIdFromStateRef = useRef<string | null | undefined>(undefined) const toolIdFromStateRef = useRef<string | null | undefined>(undefined)
const isFromTactics = searchParams.get('from') === 'tactics'
// 当外部系统直接以 /chat/:id 链接进入(没有 location.state,且 URL 中也没有 toolId)时, // 当外部系统直接以 /chat/:id 链接进入(没有 location.state,且 URL 中也没有 toolId)时,
// 视为一次新的会话入口:重置为通用模式,清除历史遗留的工具模式状态 // 视为一次新的会话入口:重置为通用模式,清除历史遗留的工具模式状态
...@@ -510,6 +511,8 @@ export const Chat: React.FC = () => { ...@@ -510,6 +511,8 @@ export const Chat: React.FC = () => {
// 根据 currentToolId 获取对应的 toolName // 根据 currentToolId 获取对应的 toolName
useEffect(() => { useEffect(() => {
const getToolNameFromToolId = async () => { const getToolNameFromToolId = async () => {
if (isFromTactics)
return
if (currentToolId) { if (currentToolId) {
try { try {
// 使用mock数据(已注释) // 使用mock数据(已注释)
...@@ -534,7 +537,7 @@ export const Chat: React.FC = () => { ...@@ -534,7 +537,7 @@ export const Chat: React.FC = () => {
} }
} }
getToolNameFromToolId() getToolNameFromToolId()
}, [currentToolId]) }, [currentToolId, isFromTactics])
// 监听工具按钮点击事件,更新 ChatWelcome 提示语和 toolId // 监听工具按钮点击事件,更新 ChatWelcome 提示语和 toolId
useEffect(() => { useEffect(() => {
......
...@@ -46,6 +46,7 @@ export const Home: React.FC = () => { ...@@ -46,6 +46,7 @@ export const Home: React.FC = () => {
const [isDataLoaded, setIsDataLoaded] = useState(false) const [isDataLoaded, setIsDataLoaded] = useState(false)
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const location = useLocation() const location = useLocation()
const isFromTactics = new URLSearchParams(location.search).get('from') === 'tactics'
const hasFetched = useRef(false) const hasFetched = useRef(false)
// 使用 useState // 使用 useState
const [otherQuestions, setOtherQuestions] = useState<any>({ content: [] }) const [otherQuestions, setOtherQuestions] = useState<any>({ content: [] })
...@@ -262,44 +263,54 @@ export const Home: React.FC = () => { ...@@ -262,44 +263,54 @@ export const Home: React.FC = () => {
<div className="h-full w-full"> <div className="h-full w-full">
<div className="box flex flex-col h-full w-full"> <div className="box flex flex-col h-full w-full">
<div className="flex-1 items-center pt-[24px] sm:pt-[32px] scrollbar-hide"> <div className="flex-1 items-center pt-[24px] sm:pt-[32px] scrollbar-hide">
{isFromTactics && (
<div className="flex items-center text-right justify-end">
<div>清空历史</div>
<div>重新分析</div>
</div>
)}
<div className="w-full"> <div className="w-full">
<div className="flex justify-center gap-[20px]"> <div className="flex justify-center gap-[20px]">
{/* 左侧区域 - 产品问答和您可以试着问我 */} {!isFromTactics && (
<div <>
className="flex flex-col gap-[20px] items-center overflow-y-auto scrollbar-hide" {/* 左侧区域 - 产品问答和您可以试着问我 */}
style={{ height: shouldChangeStyle ? 'calc(-64px + 100vh)' : '500px', background: shouldChangeStyle ? 'linear-gradient(180deg, #DEF6FF 0%, #FFFFFF 50%, #FFFFFF 100%)' : '', borderRadius: '24px' }} <div
> className="flex flex-col gap-[20px] items-center overflow-y-auto scrollbar-hide"
{/* {!shouldChangeStyle && ( style={{ height: shouldChangeStyle ? 'calc(-64px + 100vh)' : '500px', background: shouldChangeStyle ? 'linear-gradient(180deg, #DEF6FF 0%, #FFFFFF 50%, #FFFFFF 100%)' : '', borderRadius: '24px' }}
<motion.div className="w-full sm:w-auto" {...getAnimationProps(2)}> >
<QuestionList {/* {!shouldChangeStyle && (
questions={productQuestions.content} <motion.div className="w-full sm:w-auto" {...getAnimationProps(2)}>
dotColor="#D4CCFF" <QuestionList
background="linear-gradient(180deg, #EBE6FF 0%, #FFFFFF 50%, #FFFFFF 100%)" questions={productQuestions.content}
title={productQuestions.configName} dotColor="#D4CCFF"
iconImg={HomeIcon1} background="linear-gradient(180deg, #EBE6FF 0%, #FFFFFF 50%, #FFFFFF 100%)"
isToolBtn={shouldChangeStyle} title={productQuestions.configName}
isLoaded={isDataLoaded} iconImg={HomeIcon1}
/> isToolBtn={shouldChangeStyle}
</motion.div> isLoaded={isDataLoaded}
)} */} />
<motion.div className="w-full sm:w-auto" {...getAnimationProps(3)}> </motion.div>
<QuestionList )} */}
questions={otherQuestions.content} <motion.div className="w-full sm:w-auto" {...getAnimationProps(3)}>
dotColor="#CBECFF" <QuestionList
background="linear-gradient(180deg, #DEF6FF 0%, #FFFFFF 50%, #FFFFFF 100%)" questions={otherQuestions.content}
height={shouldChangeStyle ? '288px' : 'auto'} dotColor="#CBECFF"
title={otherQuestions.configName} background="linear-gradient(180deg, #DEF6FF 0%, #FFFFFF 50%, #FFFFFF 100%)"
iconImg={HomeIcon2} height={shouldChangeStyle ? '288px' : 'auto'}
isToolBtn={shouldChangeStyle} title={otherQuestions.configName}
isLoaded={isDataLoaded} iconImg={HomeIcon2}
/> isToolBtn={shouldChangeStyle}
</motion.div> isLoaded={isDataLoaded}
{shouldChangeStyle && ( />
<div className="w-full flex justify-center mt-auto pb-[24px]"> </motion.div>
<img src={SmartIce} alt="Smart Ice" className="w-[260px] h-[218px] mt-[-12px] object-contain" /> {shouldChangeStyle && (
<div className="w-full flex justify-center mt-auto pb-[24px]">
<img src={SmartIce} alt="Smart Ice" className="w-[260px] h-[218px] mt-[-12px] object-contain" />
</div>
)}
</div> </div>
)} </>
</div> )}
{/* 右侧区域 */} {/* 右侧区域 */}
<div className="hidden sm:flex flex-1 h-full"> <div className="hidden sm:flex flex-1 h-full">
<div <div
......
import React from 'react' import React from 'react'
import { Route, Routes } from 'react-router-dom' import { Route, Routes } from 'react-router-dom'
import { Home } from '../pages/Home' import { Home } from '../pages/Home'
import { Chat } from '../pages/Chat' import { Chat as ChatDefault } from '../pages/Chat'
import { Chat as ChatTactics } from '../pages/ChatTactics'
import { Collect } from '../pages/Collect' import { Collect } from '../pages/Collect'
import { Tools } from '../pages/Tools' import { Tools } from '../pages/Tools'
import { Protocol } from '../pages/Protocol' import { Protocol } from '../pages/Protocol'
import { withRouteChangeHandler } from './RouteChangeHandler' import { withRouteChangeHandler } from './RouteChangeHandler'
const ChatEntry: React.FC = () => {
const params = new URLSearchParams(window.location.search)
const isFromTactics = params.get('from') === 'tactics'
return isFromTactics ? <ChatTactics /> : <ChatDefault />
}
const AppRoutesComponent: React.FC = () => { const AppRoutesComponent: React.FC = () => {
return ( return (
<Routes> <Routes>
<Route path="/" element={<Home />}> <Route path="/" element={<Home />}>
<Route path="/chat/:id" element={<Chat />} /> <Route path="/chat/:id" element={<ChatEntry />} />
</Route> </Route>
<Route path="/home" element={<Home />}></Route> <Route path="/home" element={<Home />}></Route>
<Route path="/collect" element={<Collect />} /> <Route path="/collect" element={<Collect />} />
......
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