update pay function
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
* 用于显示股票与事件的关联描述信息
|
* 用于显示股票与事件的关联描述信息
|
||||||
* 固定标题为"关联描述:"
|
* 固定标题为"关联描述:"
|
||||||
* 自动处理多种数据格式(字符串、对象数组)
|
* 自动处理多种数据格式(字符串、对象数组)
|
||||||
|
* 支持悬停显示来源信息
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```tsx
|
* ```tsx
|
||||||
@@ -20,7 +21,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { Box, Text, BoxProps } from '@chakra-ui/react';
|
import { Box, Text, BoxProps, Tooltip } from '@chakra-ui/react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联描述数据项类型
|
||||||
|
*/
|
||||||
|
export interface RelationDescItem {
|
||||||
|
query_part?: string;
|
||||||
|
sentences?: string;
|
||||||
|
organization?: string;
|
||||||
|
report_title?: string;
|
||||||
|
declare_date?: string;
|
||||||
|
author?: string;
|
||||||
|
match_score?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关联描述数据类型
|
* 关联描述数据类型
|
||||||
@@ -30,10 +44,7 @@ import { Box, Text, BoxProps } from '@chakra-ui/react';
|
|||||||
export type RelationDescType =
|
export type RelationDescType =
|
||||||
| string
|
| string
|
||||||
| {
|
| {
|
||||||
data: Array<{
|
data: Array<RelationDescItem>;
|
||||||
query_part?: string;
|
|
||||||
sentences?: string;
|
|
||||||
}>;
|
|
||||||
}
|
}
|
||||||
| null
|
| null
|
||||||
| undefined;
|
| undefined;
|
||||||
@@ -66,33 +77,45 @@ export const RelationDescription: React.FC<RelationDescriptionProps> = ({
|
|||||||
lineHeight = '1.7',
|
lineHeight = '1.7',
|
||||||
containerProps = {}
|
containerProps = {}
|
||||||
}) => {
|
}) => {
|
||||||
// 处理关联描述(兼容对象和字符串格式)
|
// 判断是否为对象格式(带来源信息)
|
||||||
const processedDesc = useMemo(() => {
|
const isObjectFormat = useMemo(() => {
|
||||||
|
return typeof relationDesc === 'object' && relationDesc?.data && Array.isArray(relationDesc.data);
|
||||||
|
}, [relationDesc]);
|
||||||
|
|
||||||
|
// 处理关联描述数据
|
||||||
|
const descData = useMemo(() => {
|
||||||
if (!relationDesc) return null;
|
if (!relationDesc) return null;
|
||||||
|
|
||||||
// 字符串格式:直接返回
|
// 字符串格式:直接返回
|
||||||
if (typeof relationDesc === 'string') {
|
if (typeof relationDesc === 'string') {
|
||||||
return relationDesc;
|
return { type: 'string' as const, content: relationDesc };
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对象格式:提取并拼接文本
|
// 对象格式:返回数据数组
|
||||||
if (typeof relationDesc === 'object' && relationDesc.data && Array.isArray(relationDesc.data)) {
|
if (isObjectFormat && relationDesc && typeof relationDesc === 'object') {
|
||||||
return (
|
const items = relationDesc.data.filter((item) => item.query_part);
|
||||||
relationDesc.data
|
if (items.length === 0) return null;
|
||||||
.map((item) => item.query_part || item.sentences || '')
|
return { type: 'array' as const, items };
|
||||||
.filter((s) => s)
|
|
||||||
.join(';') || null
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}, [relationDesc]);
|
}, [relationDesc, isObjectFormat]);
|
||||||
|
|
||||||
// 如果没有有效的描述内容,不渲染组件
|
// 如果没有有效的描述内容,不渲染组件
|
||||||
if (!processedDesc) {
|
if (!descData) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 格式化日期
|
||||||
|
const formatDate = (dateStr?: string) => {
|
||||||
|
if (!dateStr) return '';
|
||||||
|
try {
|
||||||
|
return new Date(dateStr).toLocaleDateString('zh-CN');
|
||||||
|
} catch {
|
||||||
|
return dateStr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
p={4}
|
p={4}
|
||||||
@@ -108,14 +131,70 @@ export const RelationDescription: React.FC<RelationDescriptionProps> = ({
|
|||||||
>
|
>
|
||||||
关联描述:
|
关联描述:
|
||||||
</Text>
|
</Text>
|
||||||
|
{descData.type === 'string' ? (
|
||||||
<Text
|
<Text
|
||||||
fontSize={fontSize}
|
fontSize={fontSize}
|
||||||
color={textColor}
|
color={textColor}
|
||||||
lineHeight={lineHeight}
|
lineHeight={lineHeight}
|
||||||
whiteSpace="pre-wrap"
|
whiteSpace="pre-wrap"
|
||||||
>
|
>
|
||||||
{processedDesc}
|
{descData.content}
|
||||||
</Text>
|
</Text>
|
||||||
|
) : (
|
||||||
|
<Text
|
||||||
|
fontSize={fontSize}
|
||||||
|
color={textColor}
|
||||||
|
lineHeight={lineHeight}
|
||||||
|
>
|
||||||
|
{descData.items.map((item, index, arr) => (
|
||||||
|
<React.Fragment key={index}>
|
||||||
|
<Tooltip
|
||||||
|
label={
|
||||||
|
<Box maxW="400px" p={2}>
|
||||||
|
{item.sentences && (
|
||||||
|
<Text fontSize="xs" mb={2} whiteSpace="pre-wrap">
|
||||||
|
{item.sentences}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
<Text fontSize="xs" color="gray.300" mt={1}>
|
||||||
|
来源:{item.organization || '未知'}
|
||||||
|
</Text>
|
||||||
|
{item.report_title && (
|
||||||
|
<Text fontSize="xs" color="gray.300" noOfLines={2}>
|
||||||
|
{item.report_title}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
{item.declare_date && (
|
||||||
|
<Text fontSize="xs" color="gray.400">
|
||||||
|
{formatDate(item.declare_date)}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
placement="top"
|
||||||
|
hasArrow
|
||||||
|
bg="rgba(20, 20, 20, 0.95)"
|
||||||
|
maxW="420px"
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
as="span"
|
||||||
|
cursor="help"
|
||||||
|
borderBottom="1px dashed"
|
||||||
|
borderBottomColor="gray.400"
|
||||||
|
_hover={{
|
||||||
|
color: 'blue.500',
|
||||||
|
borderBottomColor: 'blue.500',
|
||||||
|
}}
|
||||||
|
transition="all 0.2s"
|
||||||
|
>
|
||||||
|
{item.query_part}
|
||||||
|
</Text>
|
||||||
|
</Tooltip>
|
||||||
|
{index < arr.length - 1 && ';'}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -325,14 +325,61 @@ const StockListItem = ({
|
|||||||
>
|
>
|
||||||
AI合成
|
AI合成
|
||||||
</Tag>
|
</Tag>
|
||||||
{/* 直接渲染文字内容 */}
|
{/* 渲染 query_part,每句带来源悬停提示 */}
|
||||||
<Text
|
<Text
|
||||||
as="span"
|
as="span"
|
||||||
fontSize="sm"
|
fontSize="sm"
|
||||||
color={PROFESSIONAL_COLORS.text.primary}
|
color={PROFESSIONAL_COLORS.text.primary}
|
||||||
lineHeight="1.8"
|
lineHeight="1.8"
|
||||||
>
|
>
|
||||||
{stock.relation_desc?.data?.map(item => item.sentences || item.query_part).filter(Boolean).join(',')}
|
{stock.relation_desc?.data?.filter(item => item.query_part).map((item, index, arr) => (
|
||||||
|
<React.Fragment key={index}>
|
||||||
|
<Tooltip
|
||||||
|
label={
|
||||||
|
<Box maxW="400px" p={2}>
|
||||||
|
{item.sentences && (
|
||||||
|
<Text fontSize="xs" mb={2} whiteSpace="pre-wrap">
|
||||||
|
{item.sentences}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
<Text fontSize="xs" color="gray.300" mt={1}>
|
||||||
|
来源:{item.organization || '未知'}
|
||||||
|
</Text>
|
||||||
|
{item.report_title && (
|
||||||
|
<Text fontSize="xs" color="gray.300" noOfLines={2}>
|
||||||
|
{item.report_title}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
{item.declare_date && (
|
||||||
|
<Text fontSize="xs" color="gray.400">
|
||||||
|
{new Date(item.declare_date).toLocaleDateString('zh-CN')}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
placement="top"
|
||||||
|
hasArrow
|
||||||
|
bg="rgba(20, 20, 20, 0.95)"
|
||||||
|
color="white"
|
||||||
|
maxW="420px"
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
as="span"
|
||||||
|
cursor="help"
|
||||||
|
borderBottom="1px dashed"
|
||||||
|
borderBottomColor="gray.400"
|
||||||
|
_hover={{
|
||||||
|
color: PROFESSIONAL_COLORS.gold[500],
|
||||||
|
borderBottomColor: PROFESSIONAL_COLORS.gold[500],
|
||||||
|
}}
|
||||||
|
transition="all 0.2s"
|
||||||
|
>
|
||||||
|
{item.query_part}
|
||||||
|
</Text>
|
||||||
|
</Tooltip>
|
||||||
|
{index < arr.length - 1 && ';'}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
</Text>
|
</Text>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Reference in New Issue
Block a user