Commit d440b375 by 李伟康

feat(chat): 添加全局配置管理和报告功能

- 添加全局配置状态管理到应用store
- 集成外部配置加载器从远程URL获取配置
- 实现报告模块支持周报月报展示
- 更新Markdown解析器支持JSON内容提取
- 添加图表和报告渲染组件
- 修改聊天界面UI元素样式调整
- 更新发送停止清空按钮为图片图标
- 优化输入框占位符显示响应状态
- 实现重启功能替换为清空操作
- 添加设置按钮跳转到外部配置页面
- 实现建议问题批量刷新功能
- 修复输入消息类型枚举值错误
1 parent b69b06a4
...@@ -11,6 +11,7 @@ type State = { ...@@ -11,6 +11,7 @@ type State = {
showAgentLogModal: boolean showAgentLogModal: boolean
showMessageLogModal: boolean showMessageLogModal: boolean
showAppConfigureFeaturesModal: boolean showAppConfigureFeaturesModal: boolean
globalConfig: any
} }
type Action = { type Action = {
...@@ -22,6 +23,7 @@ type Action = { ...@@ -22,6 +23,7 @@ type Action = {
setShowAgentLogModal: (showAgentLogModal: boolean) => void setShowAgentLogModal: (showAgentLogModal: boolean) => void
setShowMessageLogModal: (showMessageLogModal: boolean) => void setShowMessageLogModal: (showMessageLogModal: boolean) => void
setShowAppConfigureFeaturesModal: (showAppConfigureFeaturesModal: boolean) => void setShowAppConfigureFeaturesModal: (showAppConfigureFeaturesModal: boolean) => void
setGlobalConfig: (globalConfig: any) => void
} }
export const useStore = create<State & Action>(set => ({ export const useStore = create<State & Action>(set => ({
...@@ -51,4 +53,6 @@ export const useStore = create<State & Action>(set => ({ ...@@ -51,4 +53,6 @@ export const useStore = create<State & Action>(set => ({
}), }),
showAppConfigureFeaturesModal: false, showAppConfigureFeaturesModal: false,
setShowAppConfigureFeaturesModal: showAppConfigureFeaturesModal => set(() => ({ showAppConfigureFeaturesModal })), setShowAppConfigureFeaturesModal: showAppConfigureFeaturesModal => set(() => ({ showAppConfigureFeaturesModal })),
globalConfig: undefined,
setGlobalConfig: globalConfig => set(() => ({ globalConfig })),
})) }))
...@@ -4,15 +4,24 @@ import { Markdown } from '@/app/components/base/markdown' ...@@ -4,15 +4,24 @@ import { Markdown } from '@/app/components/base/markdown'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { useChatBodyContext } from '../../body/context' import { useChatBodyContext } from '../../body/context'
const BasicContent: FC = () => { type BasicContentProps = {
const { annotation, content, isError, hasAgentThoughts } = useChatBodyContext() onJsonContentReady?: (jsonContent: any) => React.ReactNode
}
const BasicContent: FC<BasicContentProps> = ({ onJsonContentReady }) => {
const { annotation, content, isError, hasAgentThoughts } = useChatBodyContext()
if(!content.trim() || hasAgentThoughts) return null if (!content.trim() || hasAgentThoughts) return null
if (annotation?.logAnnotation) return <Markdown content={annotation?.logAnnotation.content || ''} /> if (annotation?.logAnnotation) return <Markdown content={annotation?.logAnnotation.content || ''} />
return <Markdown className={cn(isError && '!text-[#F04438]')} content={content} /> return (
<Markdown
className={cn(isError && '!text-[#F04438]')}
content={content}
onJsonContentReady={onJsonContentReady}
/>
)
} }
export default memo(BasicContent) export default memo(BasicContent)
...@@ -4,7 +4,7 @@ import { LOADING_ICON } from "@/app/components/base/chat/constants"; ...@@ -4,7 +4,7 @@ import { LOADING_ICON } from "@/app/components/base/chat/constants";
const LoadingIcon: FC = () => { const LoadingIcon: FC = () => {
return ( return (
<img src={LOADING_ICON} alt="loading" className="w-5 h-5 mr-2" /> <img src={LOADING_ICON} alt="loading" className="w-5 h-5 mr-2" style={{ border: 'none' }} />
) )
} }
export default memo(LoadingIcon) export default memo(LoadingIcon)
...@@ -3,3 +3,7 @@ ...@@ -3,3 +3,7 @@
border-radius: 16px 16px 16px 4px; border-radius: 16px 16px 16px 4px;
} }
.report-container{
margin: 16px 0;
border-radius: 16px;
}
\ No newline at end of file \ No newline at end of file
...@@ -8,6 +8,9 @@ import More from './components/more' ...@@ -8,6 +8,9 @@ import More from './components/more'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import LoadingText from './components/loading-text' import LoadingText from './components/loading-text'
import { useChatBodyContext } from '../body/context' import { useChatBodyContext } from '../body/context'
import {
Report
} from '@/app/components/base/markdown/blocks'
import s from './index.module.scss' import s from './index.module.scss'
type AnswerProps = { type AnswerProps = {
...@@ -15,8 +18,16 @@ type AnswerProps = { ...@@ -15,8 +18,16 @@ type AnswerProps = {
} }
const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => { const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => {
const { containerRef, contentRef, more, isAnswer } = useChatBodyContext() const { containerRef, contentRef, more, isAnswer } = useChatBodyContext()
const [jsonContent, setJsonContent] = useState<any>(null)
if (!isAnswer) return null if (!isAnswer) return null
const handleJsonContentReady = (content: any) => {
setJsonContent(content)
return null // 不在 BasicContent 内部渲染
}
return ( return (
<>
<div className="mb-2 flex last:mb-0"> <div className="mb-2 flex last:mb-0">
<div className="chat-answer-container group w-0 grow pb-2" ref={containerRef}> <div className="chat-answer-container group w-0 grow pb-2" ref={containerRef}>
{/* <LoadingAvatar /> */} {/* <LoadingAvatar /> */}
...@@ -32,12 +43,21 @@ const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => { ...@@ -32,12 +43,21 @@ const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => {
{/* 加载中 */} {/* 加载中 */}
<LoadingText /> <LoadingText />
{/* 内容 */} {/* 内容 */}
<BasicContent /> <BasicContent
onJsonContentReady={handleJsonContentReady}
/>
</div> </div>
</div> </div>
<More more={more} /> <More more={more} />
</div> </div>
</div> </div>
{/* 在父组件层级渲染 JSON 内容 */}
{jsonContent && (
<div className={cn(s['report-container'])}>
<Report content={jsonContent} />
</div>
)}
</>
) )
} }
export default memo(Answer) export default memo(Answer)
...@@ -89,7 +89,7 @@ const TextInput: React.FC<{ ...@@ -89,7 +89,7 @@ const TextInput: React.FC<{
s['text-input'], s['text-input'],
'body-lg-regular w-full resize-none bg-transparent p-1 leading-6 text-text-tertiary outline-none', 'body-lg-regular w-full resize-none bg-transparent p-1 leading-6 text-text-tertiary outline-none',
)} )}
placeholder={t('common.chat.inputPlaceholder') || ''} placeholder={isResponding ? '正在生成回复...' : t('common.chat.inputPlaceholder') || ''}
autoFocus autoFocus
maxRows={maxRow} maxRows={maxRow}
onResize={handleTextareaResize} onResize={handleTextareaResize}
......
'use client'
import { useEffect } from 'react'
import { useStore } from '@/app/components/app/store'
const CONFIG_URL = 'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=glsk-ai-data-assistant-config&env=develop'
export function ConfigLoader() {
const setGlobalConfig = useStore(state => state.setGlobalConfig)
useEffect(() => {
async function loadConfig() {
try {
const response = await fetch(CONFIG_URL)
const data = await response.json()
setGlobalConfig(data)
} catch (error) {
console.error('获取配置失败:', error)
}
}
loadConfig()
}, [setGlobalConfig])
return null
}
...@@ -3,6 +3,8 @@ import { useToastContext } from '@/app/components/base/toast' ...@@ -3,6 +3,8 @@ import { useToastContext } from '@/app/components/base/toast'
import { FC, memo, useCallback, useState } from 'react' import { FC, memo, useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useChatRespondingContext, useChatContext } from '@/app/components/base/chat/chat-with-history/context' import { useChatRespondingContext, useChatContext } from '@/app/components/base/chat/chat-with-history/context'
import { AI_DATA_CLEAR } from '@/app/components/base/chat/constants'
const ReStart: FC = () => { const ReStart: FC = () => {
const { t } = useTranslation() const { t } = useTranslation()
const { notify } = useToastContext() const { notify } = useToastContext()
...@@ -37,15 +39,7 @@ const ReStart: FC = () => { ...@@ -37,15 +39,7 @@ const ReStart: FC = () => {
/> />
)} )}
<div className="fixed-button" onClick={handleRestart}> <div className="fixed-button" onClick={handleRestart}>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg"> <img src={AI_DATA_CLEAR} alt="Clear" title="Clear" className='footer-icon' />
<path
d="M3 10.25V15.5H15V10.25M3 10.25H15M3 10.25V6.875H7.5V2.5H10.5V6.875H15V10.25M11.25 15.5V13.25"
stroke="#0A3479"
stroke-width="1.3"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
清空 清空
</div> </div>
</> </>
......
import { FC, memo } from 'react' import { FC, memo } from 'react'
import { useMessageContext } from '../../context' import { useMessageContext } from '../../context'
import { useChatRespondingContext, useChatContext } from '@/app/components/base/chat/chat-with-history/context' import { useChatRespondingContext, useChatContext } from '@/app/components/base/chat/chat-with-history/context'
import { AI_DATA_SEND, AI_DATA_STOP } from '@/app/components/base/chat/constants'
const Send: FC = () => { const Send: FC = () => {
const { handleSend } = useMessageContext() const { handleSend } = useMessageContext()
const { isResponding } = useChatRespondingContext() const { isResponding } = useChatRespondingContext()
const { onStopResponding: stopResponding } = useChatContext() const { onStopResponding: stopResponding } = useChatContext()
if (isResponding) if (isResponding) return <img src={AI_DATA_STOP} onClick={stopResponding} alt="Stop" title="Stop" className='send-icon' />
return (
<svg onClick={stopResponding} width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_d_84_1038)">
<path
d="M1.33337 20C1.33337 11.1634 8.49682 4 17.3334 4C26.1699 4 33.3334 11.1634 33.3334 20C33.3334 28.8366 26.1699 36 17.3334 36C8.49682 36 1.33337 28.8366 1.33337 20Z"
fill="url(#paint0_linear_84_1038)"
/>
<rect x="11.3334" y="14" width="12" height="12" rx="1.6" fill="white" />
</g>
<defs>
<filter
id="filter0_d_84_1038"
x="4.07696e-05"
y="0"
width="40"
height="40"
filterUnits="userSpaceOnUse"
color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix
in="SourceAlpha"
type="matrix"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
result="hardAlpha"
/>
<feOffset dx="2.66667" />
<feGaussianBlur stdDeviation="2" />
<feColorMatrix type="matrix" values="0 0 0 0 0.514423 0 0 0 0 0.741026 0 0 0 0 1 0 0 0 0.4 0" />
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_84_1038" />
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_84_1038" result="shape" />
</filter>
<linearGradient
id="paint0_linear_84_1038"
x1="17.3334"
y1="4"
x2="25.3976"
y2="33.8191"
gradientUnits="userSpaceOnUse">
<stop stop-color="#4F72FF" />
<stop offset="0.5" stop-color="#4EA9FE" />
<stop offset="1" stop-color="#4CE0FC" />
</linearGradient>
</defs>
</svg>
)
return ( return <img src={AI_DATA_SEND} onClick={handleSend} alt="Send" title="Send" className='send-icon' />
<svg onClick={handleSend} width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_d_16_201)">
<path
d="M1.33331 20C1.33331 11.1634 8.49676 4 17.3333 4C26.1699 4 33.3333 11.1634 33.3333 20C33.3333 28.8366 26.1699 36 17.3333 36C8.49676 36 1.33331 28.8366 1.33331 20Z"
fill="url(#paint0_linear_16_201)"
/>
<path
d="M16.4153 12.8361C16.7935 12.0796 17.8731 12.0796 18.2514 12.8361L24.2759 24.8851C24.6774 25.6882 23.9271 26.5833 23.0663 26.3283L17.6249 24.716C17.4346 24.6596 17.232 24.6596 17.0417 24.716L11.6004 26.3283C10.7395 26.5833 9.98921 25.6882 10.3907 24.8851L16.4153 12.8361Z"
fill="white"
/>
</g>
<defs>
<filter
id="filter0_d_16_201"
x="-2.02656e-05"
y="0"
width="40"
height="40"
filterUnits="userSpaceOnUse"
color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix
in="SourceAlpha"
type="matrix"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
result="hardAlpha"
/>
<feOffset dx="2.66667" />
<feGaussianBlur stdDeviation="2" />
<feColorMatrix type="matrix" values="0 0 0 0 0.514423 0 0 0 0 0.741026 0 0 0 0 1 0 0 0 0.4 0" />
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_16_201" />
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_16_201" result="shape" />
</filter>
<linearGradient
id="paint0_linear_16_201"
x1="17.3333"
y1="4"
x2="25.3975"
y2="33.8191"
gradientUnits="userSpaceOnUse">
<stop stop-color="#4F72FF" />
<stop offset="0.5" stop-color="#4EA9FE" />
<stop offset="1" stop-color="#4CE0FC" />
</linearGradient>
</defs>
</svg>
)
} }
export default memo(Send) export default memo(Send)
import { FC, memo } from 'react' import { FC, memo } from 'react'
const ReStart: FC = () => { import { useStore } from '@/app/components/app/store'
import { AI_DATA_SETTING ,GET_PARAMS} from '@/app/components/base/chat/constants'
const Setting: FC = () => {
const handleSettingClick = () => {
const sessionId = GET_PARAMS.get('sessionId')
const { globalConfig } = useStore.getState()
if (!globalConfig) {
console.warn('全局配置尚未加载')
return
}
const { settingUrl } = globalConfig
if (settingUrl) {
window.open(`${settingUrl}?sessionId=${sessionId}`)
} else {
console.warn('配置中未设置 settingUrl')
}
}
return ( return (
<> <>
<div className="fixed-button"> <div className="fixed-button" onClick={handleSettingClick}>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg"> <img src={AI_DATA_SETTING} alt="Setting" title="Setting" className='footer-icon' />
<path
d="M16.1173 8.32712C16.2354 8.5317 16.2976 8.76377 16.2976 9C16.2976 9.23623 16.2354 9.4683 16.1173 9.67288L13.1412 14.8271C13.0231 15.0317 12.8532 15.2016 12.6486 15.3197C12.444 15.4378 12.212 15.5 11.9757 15.5L6.02414 15.5C5.78792 15.5 5.55586 15.4378 5.35128 15.3197C5.14671 15.2016 4.97683 15.0317 4.85872 14.8271L1.88258 9.67288C1.76446 9.4683 1.70228 9.23623 1.70228 9C1.70228 8.76377 1.76446 8.5317 1.88258 8.32712L4.85872 3.17288C4.97683 2.9683 5.14671 2.79842 5.35128 2.68031C5.55586 2.56219 5.78792 2.50001 6.02414 2.5L11.9757 2.5C12.212 2.50001 12.444 2.56219 12.6486 2.68031C12.8532 2.79842 13.0231 2.9683 13.1412 3.17288L16.1173 8.32712ZM14.9519 9L11.9757 3.84576L6.02414 3.84576L3.048 9L6.02414 14.1542L11.9757 14.1542L14.9519 9ZM11.6915 9C11.6915 9.71383 11.4079 10.3984 10.9031 10.9032C10.3984 11.4079 9.71378 11.6915 8.99994 11.6915C8.28611 11.6915 7.60151 11.4079 7.09676 10.9032C6.592 10.3984 6.30843 9.71383 6.30843 9C6.30843 8.28617 6.592 7.60157 7.09676 7.09681C7.60151 6.59206 8.28611 6.30849 8.99994 6.30849C9.71378 6.30849 10.3984 6.59206 10.9031 7.09681C11.4079 7.60157 11.6915 8.28617 11.6915 9ZM10.3457 9C10.3457 8.82327 10.3109 8.64828 10.2433 8.485C10.1756 8.32173 10.0765 8.17337 9.95154 8.04841C9.82657 7.92344 9.67822 7.82431 9.51494 7.75668C9.35167 7.68905 9.17667 7.65424 8.99994 7.65424C8.82322 7.65424 8.64822 7.68905 8.48495 7.75668C8.32167 7.82431 8.17331 7.92344 8.04835 8.04841C7.92339 8.17337 7.82426 8.32173 7.75663 8.485C7.689 8.64828 7.65419 8.82327 7.65419 9C7.65419 9.35692 7.79597 9.69922 8.04835 9.95159C8.30073 10.204 8.64303 10.3458 8.99994 10.3458C9.35686 10.3458 9.69916 10.204 9.95154 9.95159C10.2039 9.69922 10.3457 9.35692 10.3457 9Z"
fill="#0A3479"
/>
</svg>
设置 设置
</div> </div>
</> </>
) )
} }
export default memo(ReStart) export default memo(Setting)
...@@ -5,6 +5,7 @@ import StopResponding from './components/stopResponding' ...@@ -5,6 +5,7 @@ import StopResponding from './components/stopResponding'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import ReStart from './components/operation/restart' import ReStart from './components/operation/restart'
import Setting from './components/operation/setting' import Setting from './components/operation/setting'
import { ConfigLoader } from './components/operation/config-loader'
import s from './index.module.scss' import s from './index.module.scss'
type FooterProps = { type FooterProps = {
...@@ -16,6 +17,8 @@ type FooterProps = { ...@@ -16,6 +17,8 @@ type FooterProps = {
const Footer: FC<FooterProps> = ({ isMobile, chatFooterRef, chatFooterInnerRef }) => { const Footer: FC<FooterProps> = ({ isMobile, chatFooterRef, chatFooterInnerRef }) => {
return ( return (
<div className={cn('absolute bottom-0 flex justify-center bg-chat-input-mask pb-4 w-full',s['footer-mask'])} ref={chatFooterRef}> <div className={cn('absolute bottom-0 flex justify-center bg-chat-input-mask pb-4 w-full',s['footer-mask'])} ref={chatFooterRef}>
{/* 配置加载器 */}
<ConfigLoader />
<div <div
ref={chatFooterInnerRef} ref={chatFooterInnerRef}
className={cn('relative', `mx-auto w-full max-w-[800px] ${isMobile ? 'px-2' : 'px-4'}`)}> className={cn('relative', `mx-auto w-full max-w-[800px] ${isMobile ? 'px-2' : 'px-4'}`)}>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* @FilePath: \ai-assistant\app\components\base\chat\chat\question\init-questions.tsx * @FilePath: \ai-assistant\app\components\base\chat\chat\question\init-questions.tsx
*/ */
import type { FC } from 'react' import type { FC } from 'react'
import {useMemo } from 'react' import { useMemo, useState, useCallback } from 'react'
import InitSuggest from './init-suggest' import InitSuggest from './init-suggest'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { useChatConfigContext } from '../../chat-with-history/context/chat-config-context' import { useChatConfigContext } from '../../chat-with-history/context/chat-config-context'
...@@ -17,7 +17,14 @@ import { AI_TIPS } from '@/app/components/base/chat/constants' ...@@ -17,7 +17,14 @@ import { AI_TIPS } from '@/app/components/base/chat/constants'
const InitQuestions: FC = () => { const InitQuestions: FC = () => {
const { suggested_questions = [] } = useChatConfigContext() const { suggested_questions = [] } = useChatConfigContext()
const [refreshFlag, setRefreshFlag] = useState(0)
if (!suggested_questions.length) return null if (!suggested_questions.length) return null
const handleRefresh = useCallback(() => {
setRefreshFlag(prev => prev + 1)
}, [])
return useMemo(() => { return useMemo(() => {
const suggestedQuestions = suggested_questions const suggestedQuestions = suggested_questions
.filter(q => !!q && q.trim()) .filter(q => !!q && q.trim())
...@@ -30,7 +37,7 @@ const InitQuestions: FC = () => { ...@@ -30,7 +37,7 @@ const InitQuestions: FC = () => {
<div className={cn(s['suggested-questions-list'], 'group w-0 grow')}> <div className={cn(s['suggested-questions-list'], 'group w-0 grow')}>
<div className={cn('flex', s['suggested-questions-list-tips'])}> <div className={cn('flex', s['suggested-questions-list-tips'])}>
试试这样提问: 试试这样提问:
<div className={cn(s['change-btn'], 'flex')}> <div className={cn(s['change-btn'], 'flex')} onClick={handleRefresh}>
换一批 换一批
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path <path
...@@ -58,6 +65,6 @@ const InitQuestions: FC = () => { ...@@ -58,6 +65,6 @@ const InitQuestions: FC = () => {
</div> </div>
</div> </div>
) )
}, [suggested_questions]) }, [suggested_questions, refreshFlag])
} }
export default InitQuestions export default InitQuestions
...@@ -56,5 +56,6 @@ ...@@ -56,5 +56,6 @@
} }
&-icon { &-icon {
flex-shrink: 0; flex-shrink: 0;
margin-left: auto;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -24,3 +24,12 @@ export const CLEAR_BUTTON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai ...@@ -24,3 +24,12 @@ export const CLEAR_BUTTON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai
export const LOADING_ICON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/loading-icon.png?v=1' export const LOADING_ICON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/loading-icon.png?v=1'
export const AI_TIPS = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-tips.png' export const AI_TIPS = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-tips.png'
export const AI_DATA_SEND = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-send.png'
export const AI_DATA_STOP = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-stop.png'
export const AI_DATA_CLEAR = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-clear.png'
export const AI_DATA_SETTING = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-setting.png'
export const GET_PARAMS = __params
...@@ -77,7 +77,7 @@ export type InputMessageProp = { ...@@ -77,7 +77,7 @@ export type InputMessageProp = {
export enum InputMessageType { export enum InputMessageType {
BY_HAND = '0', BY_HAND = '0',
BY_AUTO = '1', BY_AUTO = '1',
QUESTION_IN_WELCOME = '2', QUESTION_IN_WELCOME = '1',
BY_PRACTICE = '3', BY_PRACTICE = '3',
QUESTION_IN_ANSWER = '4', QUESTION_IN_ANSWER = '4',
BY_SUGGEST = '5', BY_SUGGEST = '5',
......
import { FC, useMemo } from 'react' import { FC } from 'react'
import ReactECharts from 'echarts-for-react' import ReactECharts from 'echarts-for-react'
type ChartProps = { type ChartProps = {
content: string content: any | null
} }
interface ChartData {
is_chart?: string
chart?: Array<{
type?: string
name?: string[]
data?: number[]
metric?: string
}>
}
const Chart: FC<ChartProps> = ({ content }) => { const Chart: FC<ChartProps> = ({ content }) => {
const chartData: ChartData | null = useMemo(() => { const chartData = content
try { if (!chartData || !chartData.chart?.[0]) {
const cleanContent = content.replace(/^```json\s*|\s*```$/g, '').trim()
return JSON.parse(cleanContent)
} catch (e) {
console.error('Failed to parse chart JSON:', e)
return null
}
}, [content])
if (!chartData || !chartData.is_chart || !chartData.chart?.[0]) {
return null return null
} }
if (chartData.is_chart == 'N') return null if (chartData.is_chart == 'N') return null
......
...@@ -17,3 +17,4 @@ export { default as MarkdownButton } from './button' ...@@ -17,3 +17,4 @@ export { default as MarkdownButton } from './button'
export { default as MarkdownForm } from './form' export { default as MarkdownForm } from './form'
export { default as Think } from './think' export { default as Think } from './think'
export {default as Chart} from './chart' export {default as Chart} from './chart'
export {default as Report} from './report'
.report-box {
background: linear-gradient(180deg, #edf5ff 0%, #fff 19.65%, #fff 100%);
border-radius: 16px;
}
.report-type-title {
display: flex;
align-items: center;
gap: 8px;
color: #133368;
font-size: 16px;
font-weight: 500;
padding: 12px 12px 8px;
.block {
line-height: 24px;
height: 24px;
color: #4f72ff;
font-size: 13px;
font-weight: 400;
padding: 0 10px;
border-radius: 32px;
background: rgba(79, 114, 255, 0.1);
}
&:before {
content: '';
border-top: 1px solid #e0e0e0;
width: 6px;
height: 20px;
border-radius: 584px;
background: linear-gradient(165deg, #4f72ff 10.64%, #4ea9fd 50%, #4ce0fc 89.36%);
box-shadow: 2px 0 3px 0 rgba(131, 189, 255, 0.4);
display: block;
}
}
\ No newline at end of file \ No newline at end of file
import { FC, useRef, useEffect, useState } from 'react'
import { useStore } from '@/app/components/app/store'
import dayjs from 'dayjs'
import cn from '@/utils/classnames'
import s from './index.module.scss'
type ReportProps = {
content: any | null
}
const Report: FC<ReportProps> = ({ content }) => {
const { globalConfig } = useStore.getState()
const { report_end_date, report_start_date, report_type } = content
const reportType = report_type == '周报' ? 1 : 2
const iframeRef = useRef<HTMLIFrameElement>(null)
const [iframeHeight, setIframeHeight] = useState(500) // 默认高度
const reportDateText = () => {
if (!report_start_date) return ''
if (reportType === 2) {
// 月报:2026-01-10 转成 2026 年 1 月
return dayjs(report_start_date).format('YYYY年M月')
} else if (reportType === 1) {
// 周报:2026-01-10 转成 2026 年第 2 周
const date = dayjs(report_start_date)
const year = date.year()
// 计算是该年的第几周
const startOfYear = dayjs(`${year}-01-01`)
const weekNumber = Math.ceil((date.diff(startOfYear, 'day') + 1 + startOfYear.day()) / 7)
return `${year}年第${weekNumber}周`
}
return ''
}
if (!globalConfig) {
console.warn('全局配置尚未加载')
return null
}
let { reportUrl } = globalConfig
reportUrl += `?reportStartDate=${report_start_date}&reportEndDate=${report_end_date}&reportType=${reportType}`
const handleIframeLoad = () => {
if (iframeRef.current) {
try {
// 获取 iframe 内部文档的高度
const iframeDoc = iframeRef.current.contentDocument || iframeRef.current.contentWindow?.document
if (iframeDoc?.body) {
const height = Math.max(
iframeDoc.body.scrollHeight,
iframeDoc.body.offsetHeight,
iframeDoc.documentElement.scrollHeight,
iframeDoc.documentElement.offsetHeight,
)
setIframeHeight(height)
}
} catch (error) {
console.warn('无法获取 iframe 高度,可能由于跨域限制:', error)
// 跨域时使用默认高度或估算高度
setIframeHeight(800)
}
}
}
return (
<div className={cn(s['report-box'])}>
{reportUrl && (
<div className={cn(s['report-type-title'])}>
展业{report_type}
<div className={cn(s['block'])}>{reportDateText()}</div>
</div>
)}
{reportUrl ? (
<iframe
ref={iframeRef}
src={reportUrl}
title="报告预览"
width="100%"
height={iframeHeight}
onLoad={handleIframeLoad}
style={{ border: 'none', display: 'block', borderRadius: '16px' }}
/>
) : null}
</div>
)
}
export default Report
...@@ -75,25 +75,20 @@ export const Think = ({ children, ...props }: any) => { ...@@ -75,25 +75,20 @@ export const Think = ({ children, ...props }: any) => {
{isComplete ? `${t('common.chat.thought')}\t(${elapsedTime.toFixed(1)}s)` : `${t('common.chat.thinking')}`} {isComplete ? `${t('common.chat.thought')}\t(${elapsedTime.toFixed(1)}s)` : `${t('common.chat.thinking')}`}
{isComplete ? ( {isComplete ? (
<div className={cn(s['arrow'], 'transition-transform duration-500 group-open:rotate-180')}> <div className={cn(s['arrow'], 'transition-transform duration-500 group-open:rotate-180')}>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg"> <img src="https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-arrow.png" alt="arrow" />
<path
d="M4.5 7.5L9 12L13.5 7.5"
stroke="#0A3479"
stroke-opacity="0.6"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div> </div>
) : ( ) : (
'' ''
)} )}
</div> </div>
</summary> </summary>
{displayContent ? (
<div className="ml-2 border-l border-components-panel-border p-3 text-text-secondary think-class"> <div className="ml-2 border-l border-components-panel-border p-3 text-text-secondary think-class">
{displayContent} {displayContent}
</div> </div>
) : (
null
)}
</details> </details>
) )
} }
......
...@@ -3,9 +3,22 @@ ...@@ -3,9 +3,22 @@
overflow-y: auto; overflow-y: auto;
height: 100%; height: 100%;
} }
.streaming_text { .streaming_text {
transition: opacity 3s ease, transform 3s ease; transition: opacity 3s ease, transform 3s ease;
} }
.arrow{
.arrow {
margin-left: auto; margin-left: auto;
width: 18px;
height: 18px;
}
.arrow img {
border: none !important;
}
.report-container {
width: calc(100vw - 52px);
} }
\ No newline at end of file \ No newline at end of file
...@@ -8,7 +8,19 @@ import RehypeRaw from 'rehype-raw' ...@@ -8,7 +8,19 @@ import RehypeRaw from 'rehype-raw'
import { flow } from 'lodash-es' import { flow } from 'lodash-es'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { customUrlTransform, preprocessLaTeX, preprocessThinkTag } from './markdown-utils' import { customUrlTransform, preprocessLaTeX, preprocessThinkTag } from './markdown-utils'
import { Audio, Code, Img, Link, MarkdownButton, MarkdownForm, Paragraph, Script, Think, Video, Chart } from './blocks' import {
Audio,
Code,
Img,
Link,
MarkdownButton,
MarkdownForm,
Paragraph,
Script,
Think,
Video,
Chart,
} from './blocks'
import { useMemo } from 'react' import { useMemo } from 'react'
/** /**
...@@ -24,32 +36,47 @@ type MarkdownProps = { ...@@ -24,32 +36,47 @@ type MarkdownProps = {
className?: string className?: string
customDisallowedElements?: string[] customDisallowedElements?: string[]
operationClassName?: string operationClassName?: string
onJsonContentReady?: (jsonContent: any) => React.ReactNode
} }
type MarkdownContent = { type MarkdownContent = {
mainContent: string mainContent: string
jsonContent?: string jsonContent?: any
} }
export function Markdown(props: MarkdownProps) { export function Markdown(props: MarkdownProps) {
const processedContent = flow([preprocessThinkTag, preprocessLaTeX])(props.content) const processedContent = flow([preprocessThinkTag, preprocessLaTeX])(props.content)
const contentObj: MarkdownContent = useMemo(() => { const contentObj: MarkdownContent = useMemo(() => {
const jsonCodeBlockRegex = /```json\s*[\s\S]*?```/g const jsonCodeBlockRegex = /```json\s*[\s\S]*?```/g
const match = jsonCodeBlockRegex.exec(processedContent) const match = jsonCodeBlockRegex.exec(processedContent)
if (match && match.index !== undefined) { if (match && match.index !== undefined) {
const mainContent = processedContent.substring(0, match.index) const mainContent = processedContent.substring(0, match.index)
const jsonContent = processedContent.substring(match.index) // 提取第一个 ```json 块的内容
return { mainContent, jsonContent } const jsonBlock = match[0]
// 移除 ```json 和 ``` 标记
const jsonContent = jsonBlock
.replace(/^```json\s*/, '')
.replace(/\s*```$/, '')
.trim()
try {
const parsedJson = JSON.parse(jsonContent)
return { mainContent, jsonContent: parsedJson }
} catch (e) {
console.error('JSON 解析失败:', e)
console.error('原始 JSON 内容:', jsonContent)
// JSON 解析失败时,将整个内容作为 mainContent
return { mainContent: processedContent }
}
} }
return { mainContent: processedContent } return { mainContent: processedContent }
}, [processedContent]) }, [processedContent])
const latexContent = contentObj.mainContent const latexContent = contentObj.mainContent
return ( return (
<>
<div className={cn('markdown-body ', '!text-text-primary', props.className)}> <div className={cn('markdown-body ', '!text-text-primary', props.className)}>
<ReactMarkdown <ReactMarkdown
remarkPlugins={[RemarkGfm, [RemarkMath, { singleDollarTextMath: false }], RemarkBreaks]} remarkPlugins={[RemarkGfm, [RemarkMath, { singleDollarTextMath: false }], RemarkBreaks]}
...@@ -99,10 +126,13 @@ export function Markdown(props: MarkdownProps) { ...@@ -99,10 +126,13 @@ export function Markdown(props: MarkdownProps) {
{/* Markdown detect has problem. */} {/* Markdown detect has problem. */}
{latexContent} {latexContent}
</ReactMarkdown> </ReactMarkdown>
{contentObj.jsonContent && contentObj.jsonContent.is_chart == 'Y' ? (
{contentObj.jsonContent && ( <Chart content={contentObj.jsonContent} />
<Chart content={contentObj.jsonContent || ''} /> ) : null}
)}
</div> </div>
{props.onJsonContentReady && contentObj.jsonContent ? (
<>{props.onJsonContentReady(contentObj.jsonContent)}</>
) : null}
</>
) )
} }
...@@ -32,7 +32,6 @@ export const viewport: Viewport = { ...@@ -32,7 +32,6 @@ export const viewport: Viewport = {
const LocaleLayout = async ({ children }: { children: React.ReactNode }) => { const LocaleLayout = async ({ children }: { children: React.ReactNode }) => {
const locale = await getLocaleOnServer() const locale = await getLocaleOnServer()
return ( return (
<html lang={locale ?? 'en'} className="h-full" suppressHydrationWarning> <html lang={locale ?? 'en'} className="h-full" suppressHydrationWarning>
<head> <head>
......
...@@ -706,7 +706,7 @@ button:focus-within { ...@@ -706,7 +706,7 @@ button:focus-within {
background-color: #f5f9ff; background-color: #f5f9ff;
} }
.layout-bg::after{ .layout-bg::after {
content: ""; content: "";
background: url('https://img02.glsx.com.cn/weapp/resource/saas/ai/layout-bg.png'); background: url('https://img02.glsx.com.cn/weapp/resource/saas/ai/layout-bg.png');
width: 100vw; width: 100vw;
...@@ -736,10 +736,20 @@ button:focus-within { ...@@ -736,10 +736,20 @@ button:focus-within {
font-size: 13px; font-size: 13px;
} }
.think-class{ .think-class {
font-size: 13px; font-size: 13px;
color: #13336899; color: #13336899;
} }
.m-h-48{
.m-h-48 {
min-height: 48px; min-height: 48px;
} }
.send-icon {
width: 32px;
height: 32px;
}
.footer-icon{
width: 18px;
height: 18px;
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!