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,12 +65,12 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => { ...@@ -64,12 +65,12 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => {
return ( return (
<motion.main className={styles.layoutMain}> <motion.main className={styles.layoutMain}>
{/* hidden */} {/* hidden */}
{!isFromTactics && (
<motion.div <motion.div
animate={navBarVisibleLocal === '0' ? isHistoryVisible ? 'shrunk' : 'expanded' : 'navTween'} animate={navBarVisibleLocal === '0' ? isHistoryVisible ? 'shrunk' : 'expanded' : 'navTween'}
variants={contentVariants} 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`} 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 <Navbar
isHistoryVisible={isHistoryVisible} isHistoryVisible={isHistoryVisible}
onSetHistoryVisible={setHistoryVisible} onSetHistoryVisible={setHistoryVisible}
...@@ -92,6 +93,7 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => { ...@@ -92,6 +93,7 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => {
</motion.div> </motion.div>
)} )}
</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,8 +263,16 @@ export const Home: React.FC = () => { ...@@ -262,8 +263,16 @@ 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 <div
className="flex flex-col gap-[20px] items-center overflow-y-auto scrollbar-hide" className="flex flex-col gap-[20px] items-center overflow-y-auto scrollbar-hide"
...@@ -300,6 +309,8 @@ export const Home: React.FC = () => { ...@@ -300,6 +309,8 @@ export const Home: React.FC = () => {
</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