Commit 0db97af0 by Liu

fix: 路由拼接参数控制权限&&推荐问样式图标

parent 2d419f61
......@@ -10,10 +10,13 @@ export function fetchQuestionList(data: any) {
/**
* 查询工具列表
* @params params.userRoles: 角色,用于按角色返回工具
* @params params.userRoles: 角色数组,用于按角色返回工具
*/
export function fetchToolList(params?: { userRoles?: string }) {
const requestBody: Record<string, string> = { toolType: '03' }
export function fetchToolList(params?: { userRoles?: string[] }) {
const requestBody: Record<string, string | string[]> = {
toolType: '03',
userRoles: [],
}
if (params?.userRoles)
requestBody.userRoles = params.userRoles
return http.post('/config-center/api/tool/mobile/v1/get_tool_list', requestBody)
......
This diff was suppressed by a .gitattributes entry.
......@@ -10,13 +10,27 @@ import { useAppDispatch, useAppSelector } from '@/store/hook'
import { fetchToolList } from '@/api/home'
import { clearCurrentToolId, createConversation, setCurrentToolId } from '@/store/conversationSlice'
function getUserRoleFromRoute() {
function getUserRolesFromRoute(): string[] {
try {
const searchParams = new URLSearchParams(window.location.search)
return searchParams.get('userRoles') || undefined
const rolesFromRepeatedKeys = searchParams.getAll('userRoles').filter(Boolean)
if (rolesFromRepeatedKeys.length)
return Array.from(new Set(rolesFromRepeatedKeys))
const commaSeparated = searchParams.get('userRoles')
if (commaSeparated) {
const roles = commaSeparated
.split(',')
.map(role => role.trim())
.filter(Boolean)
if (roles.length)
return Array.from(new Set(roles))
}
return []
}
catch {
return undefined
return []
}
}
......@@ -24,7 +38,7 @@ interface ChatEditorProps {
onChange?: (value: string) => void
onFocus?: () => void
onSubmit?: (value: string, toolId?: string) => void
onToolClick?: (isToolBtn: boolean, toolId?: string, shouldChangeStyle?: boolean) => void
onToolClick?: (isToolBtn: boolean, toolId?: string, toolName?: string, shouldChangeStyle?: boolean) => void
placeholders: string[]
showContentTips?: boolean
initialValue?: string
......@@ -47,8 +61,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 获取工具列表
const getToolList = async () => {
try {
const userRoles = getUserRoleFromRoute()
const res = await fetchToolList(userRoles ? { userRoles } : undefined)
const userRoles = getUserRolesFromRoute()
const res = await fetchToolList({ userRoles })
if (res?.data) {
// 根据 toolId 去重,防止重复渲染
const uniqueList = res.data.filter((tool: any, index: number, self: any[]) =>
......@@ -155,7 +169,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
shouldNavigate: true,
shouldSendQuestion: '',
})).unwrap()
onToolClick?.(true, undefined, false)
onToolClick?.(true, undefined, '通用模式', false)
}
catch (error) {
console.error('创建会话失败:', error)
......@@ -166,6 +180,12 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const handleToolClick = async (tool: any) => {
if (!checkAuth())
return
if (tool.toolName === '数据助手') {
sessionStorage.setItem('showToolQuestion', 'true')
}
else {
sessionStorage.removeItem('showToolQuestion')
}
dispatch(setCurrentToolId(tool.toolId))
setSelectedToolId(tool.toolId)
setIsToolBtnActive(false)
......@@ -175,7 +195,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
shouldNavigate: true,
shouldSendQuestion: '',
})).unwrap()
onToolClick?.(false, tool.toolId, true)
onToolClick?.(false, tool.toolId, tool.toolName, true)
}
catch (error) {
console.error('创建会话失败:', error)
......
......@@ -5,9 +5,10 @@ import { useEffect, useState } from 'react'
import { useDebounceFn } from 'ahooks'
import { containerVariants, itemVariants } from '../../motionAnimate'
import EmptyIcon from '@/assets/svg/empty.svg?react'
import { useAppSelector } from '@/store/hook'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import type { Conversation } from '@/types/conversation'
import { processConversationData } from '@/store/conversationSlice.helper'
import { clearCurrentToolId, setCurrentToolId } from '@/store/conversationSlice'
import { isMobile } from '@/utils'
interface HistoryBarListProps {
......@@ -19,11 +20,18 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS
const navigate = useNavigate()
const { currentConversationId, conversations } = useAppSelector(state => state.conversation)
const [allItems, setAllItems] = useState<Conversation[]>([])
const dispatch = useAppDispatch()
const handleClick = (conversation: Conversation) => {
if (isMobile()) {
onSetHistoryVisible(false)
}
if (conversation.toolId) {
dispatch(setCurrentToolId(conversation.toolId))
}
else {
dispatch(clearCurrentToolId())
}
// 直接导航到历史记录,不设置shouldSendQuestion
navigate(`/chat/${conversation.conversationId}`)
}
......
......@@ -24,6 +24,16 @@ export const ChatAnswerRecommend: React.FC<ChatAnswerRecommendProps> = ({ answer
useEffect(() => {
if (!isGet) {
isGet = true
if (typeof window === 'undefined') {
return
}
const shouldSkipFetch = sessionStorage.getItem('showToolQuestion') === 'true'
if (shouldSkipFetch) {
return // skip calling recommend API when tool question mode is enabled
}
getAnswerRecommend()
}
}, [])
......@@ -32,8 +42,8 @@ export const ChatAnswerRecommend: React.FC<ChatAnswerRecommendProps> = ({ answer
{!loading && questionList.length !== 0 && questionList.length > 0 && (
<div className="flex flex-col gap-[8px]">
{
questionList.map((item, index) => (
<Button onPress={() => onSubmitQuestion(item)} key={index} color="primary" variant="light" className="text-left bg-[#fff] w-fit max-w-full text-[#333] rounded-[8px] data-[hover=true]:bg-[#F6F6F8] data-[hover=true]:text-[#333]">
questionList.map(item => (
<Button onPress={() => onSubmitQuestion(item)} key={item} color="primary" variant="light" className="text-left bg-[#fff] w-fit max-w-full text-[#333] rounded-[8px] data-[hover=true]:bg-[#F6F6F8] data-[hover=true]:text-[#333]">
<div className="w-full sm:w-full text-nowrap text-ellipsis overflow-hidden">
{item}
</div>
......
......@@ -210,7 +210,7 @@ export const Home: React.FC = () => {
{/* 左侧区域 - 产品问答和您可以试着问我 */}
<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, #F0F8FF 0%, #FFFFFF 50%, #FFFFFF 100%)' : '', borderRadius: '24px' }}
style={{ height: shouldChangeStyle ? 'calc(-64px + 100vh)' : '500px', background: shouldChangeStyle ? 'linear-gradient(180deg, #DEF6FF 0%, #FFFFFF 50%, #FFFFFF 100%)' : '', borderRadius: '24px' }}
>
{/* {!shouldChangeStyle && (
<motion.div className="w-full sm:w-auto" {...getAnimationProps(2)}>
......@@ -229,7 +229,7 @@ export const Home: React.FC = () => {
<QuestionList
questions={otherQuestions.content}
dotColor="#CBECFF"
background="linear-gradient(180deg, #F0F8FF 0%, #FFFFFF 50%, #FFFFFF 100%)"
background="linear-gradient(180deg, #DEF6FF 0%, #FFFFFF 50%, #FFFFFF 100%)"
height={shouldChangeStyle ? '288px' : 'auto'}
title={otherQuestions.configName}
iconImg={HomeIcon2}
......
......@@ -124,7 +124,7 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
}, [updateDisplayedItems])
return (
<div
className="bg-white box-border px-[20px] py-[12px] rounded-[24px] w-full sm:w-[300px] md:w-[300px]"
className="bg-white box-border px-[20px] py-[12px] w-full sm:w-[300px] md:w-[300px]"
style={{ background, height }}
>
<h3 className="flex items-center justify-between whitespace-nowrap">
......
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