Commit 8a2d3591 by Liu

fix:原有页面:新增接口地址&&切换页面路由内参数保留&&右上角操作

parent 0af1d7a8
...@@ -30,3 +30,12 @@ export function fetchToolList(params?: { userRoles?: string[] }) { ...@@ -30,3 +30,12 @@ export function fetchToolList(params?: { userRoles?: string[] }) {
export function fetchEfficiencyQuestionList(data: any) { export function fetchEfficiencyQuestionList(data: any) {
return http.post('/conversation/api/conversation/mobile/v1/generate_question', data) return http.post('/conversation/api/conversation/mobile/v1/generate_question', data)
} }
/**
* 清空记录 接口
* @params
* conversationIdList: 会话id (只传一个)
*/
export function deleteUserConversation(data: any) {
return http.post('/api/conversation/mobile/v1/delete_user_conversation', data)
}
import type React from 'react' import type React from 'react'
import { motion } from 'framer-motion' import { motion } from 'framer-motion'
import { useEffect, useRef, useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useLocation, useNavigate } from 'react-router-dom'
import { useClickAway, useSessionStorageState } from 'ahooks' import { useClickAway, useSessionStorageState } from 'ahooks'
import styles from './Navbar.module.less' import styles from './Navbar.module.less'
import { NavBarItem } from './components/NavBarItem' import { NavBarItem } from './components/NavBarItem'
...@@ -21,6 +21,7 @@ interface NavbarProps { ...@@ -21,6 +21,7 @@ interface NavbarProps {
const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, checkAuth, onSetHistoryVisible }) => { const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, checkAuth, onSetHistoryVisible }) => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const navigate = useNavigate() const navigate = useNavigate()
const location = useLocation()
const { currentConversationId, shouldNavigateToNewConversation, currentToolId } = useAppSelector(state => state.conversation) const { currentConversationId, shouldNavigateToNewConversation, currentToolId } = useAppSelector(state => state.conversation)
...@@ -103,11 +104,29 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c ...@@ -103,11 +104,29 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
useEffect(() => { useEffect(() => {
if (shouldNavigateToNewConversation && currentConversationId) { if (shouldNavigateToNewConversation && currentConversationId) {
// 如果当前有选中的 toolId,在 URL 中拼接,以便刷新页面后保留工具选择 // 获取当前 URL 的查询参数,保留除 'from' 之外的所有参数
const url = currentToolId const currentSearchParams = new URLSearchParams(location.search)
? `/chat/${currentConversationId}?toolId=${currentToolId}` const paramsToKeep = new URLSearchParams()
// 遍历当前查询参数,过滤掉 'from' 参数
currentSearchParams.forEach((value, key) => {
if (key !== 'from') {
paramsToKeep.set(key, value)
}
})
// 如果当前有选中的 toolId,添加到查询参数中
if (currentToolId) {
paramsToKeep.set('toolId', currentToolId)
}
// 构建跳转 URL
const queryString = paramsToKeep.toString()
const url = queryString
? `/chat/${currentConversationId}?${queryString}`
: `/chat/${currentConversationId}` : `/chat/${currentConversationId}`
// 通过 location.state 传递 toolId,避免在 Chat 页面被误判为“外链残留参数”而强制清空
// 通过 location.state 传递 toolId,避免在 Chat 页面被误判为"外链残留参数"而强制清空
navigate(url, { navigate(url, {
state: { state: {
toolId: currentToolId || null, toolId: currentToolId || null,
...@@ -115,7 +134,7 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c ...@@ -115,7 +134,7 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
}) })
dispatch(clearNavigationFlag()) dispatch(clearNavigationFlag())
} }
}, [shouldNavigateToNewConversation, currentConversationId, currentToolId, navigate, dispatch]) }, [shouldNavigateToNewConversation, currentConversationId, currentToolId, navigate, dispatch, location.search])
// keep latest conversation id in sessionStorage for cross-page returns (e.g., from collect) // keep latest conversation id in sessionStorage for cross-page returns (e.g., from collect)
useEffect(() => { useEffect(() => {
......
...@@ -266,12 +266,18 @@ export const Home: React.FC = () => { ...@@ -266,12 +266,18 @@ export const Home: React.FC = () => {
<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 && ( {isFromTactics && (
<div className="flex items-center justify-end gap-[20px] text-[14px] leading-[22px] text-[#2F88FF]"> <div className="flex items-center justify-end gap-[20px] text-[14px] leading-[22px] text-[#2F88FF] mb-[14px] mr-[20px]">
<div className="flex items-center gap-[6px] cursor-pointer"> <div
className="flex items-center gap-[6px] cursor-pointer"
onClick={() => window.dispatchEvent(new CustomEvent('tacticsClearHistory'))}
>
<img src={DeleteIcon} alt="清除记录" className="w-[14px] h-[14px]" /> <img src={DeleteIcon} alt="清除记录" className="w-[14px] h-[14px]" />
<span>清除记录</span> <span>清除记录</span>
</div> </div>
<div className="flex items-center gap-[6px] cursor-pointer"> <div
className="flex items-center gap-[6px] cursor-pointer"
onClick={() => window.dispatchEvent(new CustomEvent('tacticsReAnalyze'))}
>
<img src={RefreshIcon} alt="重新分析" className="w-[14px] h-[14px]" /> <img src={RefreshIcon} alt="重新分析" className="w-[14px] h-[14px]" />
<span>重新分析</span> <span>重新分析</span>
</div> </div>
......
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