feat: StockQuoteCard 顶部导航区视觉优化

- 股票名称字号放大至 26px,字重 800,突出显示
- 添加行业标签(金融 · 银行),Badge 边框样式
- 保留指数标签(沪深300、上证180)
- Mock 数据补充 industry、industry_l1、index_tags 字段
- 类型定义新增 industry、industryL1 可选字段

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zdl
2025-12-10 11:30:18 +08:00
parent 9a77bb6f0b
commit a7ab87f7c4
4 changed files with 65 additions and 11 deletions

View File

@@ -368,6 +368,25 @@ export const stockHandlers = [
stockMap[s.code] = s.name; stockMap[s.code] = s.name;
}); });
// 行业和指数映射表
const stockIndustryMap = {
'000001': { industry_l1: '金融', industry: '银行', index_tags: ['沪深300', '上证180'] },
'600519': { industry_l1: '消费', industry: '白酒', index_tags: ['沪深300', '上证50'] },
'300750': { industry_l1: '工业', industry: '电池', index_tags: ['创业板50'] },
'601318': { industry_l1: '金融', industry: '保险', index_tags: ['沪深300', '上证50'] },
'600036': { industry_l1: '金融', industry: '银行', index_tags: ['沪深300', '上证50'] },
'000858': { industry_l1: '消费', industry: '白酒', index_tags: ['沪深300'] },
'002594': { industry_l1: '汽车', industry: '乘用车', index_tags: ['沪深300', '创业板指'] },
};
const defaultIndustries = [
{ industry_l1: '科技', industry: '软件' },
{ industry_l1: '医药', industry: '化学制药' },
{ industry_l1: '消费', industry: '食品' },
{ industry_l1: '金融', industry: '证券' },
{ industry_l1: '工业', industry: '机械' },
];
// 为每只股票生成报价数据 // 为每只股票生成报价数据
const quotesData = {}; const quotesData = {};
codes.forEach(stockCode => { codes.forEach(stockCode => {
@@ -380,6 +399,11 @@ export const stockHandlers = [
// 昨收 // 昨收
const prevClose = parseFloat((basePrice - change).toFixed(2)); const prevClose = parseFloat((basePrice - change).toFixed(2));
// 获取行业和指数信息
const codeWithoutSuffix = stockCode.replace(/\.(SH|SZ)$/i, '');
const industryInfo = stockIndustryMap[codeWithoutSuffix] ||
defaultIndustries[Math.floor(Math.random() * defaultIndustries.length)];
quotesData[stockCode] = { quotesData[stockCode] = {
code: stockCode, code: stockCode,
name: stockMap[stockCode] || `股票${stockCode}`, name: stockMap[stockCode] || `股票${stockCode}`,
@@ -393,7 +417,11 @@ export const stockHandlers = [
volume: Math.floor(Math.random() * 100000000), volume: Math.floor(Math.random() * 100000000),
amount: parseFloat((Math.random() * 10000000000).toFixed(2)), amount: parseFloat((Math.random() * 10000000000).toFixed(2)),
market: stockCode.startsWith('6') ? 'SH' : 'SZ', market: stockCode.startsWith('6') ? 'SH' : 'SZ',
update_time: new Date().toISOString() update_time: new Date().toISOString(),
// 行业和指数标签
industry_l1: industryInfo.industry_l1,
industry: industryInfo.industry,
index_tags: industryInfo.index_tags || []
}; };
}); });

View File

@@ -97,18 +97,40 @@ const StockQuoteCard: React.FC<StockQuoteCardProps> = ({
<CardBody> <CardBody>
{/* 顶部:股票名称 + 关注/分享按钮 + 更新时间 */} {/* 顶部:股票名称 + 关注/分享按钮 + 更新时间 */}
<Flex justify="space-between" align="center" mb={4}> <Flex justify="space-between" align="center" mb={4}>
{/* 左侧:名称(代码) | 指数标签 */} {/* 左侧:股票名称 + 行业标签 + 指数标签 */}
<HStack spacing={2}> <HStack spacing={3} align="center">
<Text fontSize="22px" fontWeight="bold" color={valueColor}> {/* 股票名称 - 突出显示 */}
{data.name}{data.code} <Text fontSize="26px" fontWeight="800" color={valueColor}>
{data.name}
</Text> </Text>
<Text fontSize="18px" fontWeight="normal" color={labelColor}>
({data.code})
</Text>
{/* 行业标签 */}
{(data.industryL1 || data.industry) && (
<Badge
bg="transparent"
color={labelColor}
fontSize="14px"
fontWeight="medium"
border="1px solid"
borderColor={borderColor}
px={2}
py={0.5}
borderRadius="md"
>
{data.industryL1 && data.industry
? `${data.industryL1} · ${data.industry}`
: data.industry || data.industryL1}
</Badge>
)}
{/* 指数标签 */}
{data.indexTags?.length > 0 && ( {data.indexTags?.length > 0 && (
<> <Text fontSize="14px" color={labelColor}>
<Text color={labelColor} fontSize="22px" fontWeight="light">|</Text>
<Text fontSize="16px" color={labelColor}>
{data.indexTags.join('、')} {data.indexTags.join('、')}
</Text> </Text>
</>
)} )}
</HStack> </HStack>

View File

@@ -10,6 +10,8 @@ export interface StockQuoteCardData {
name: string; // 股票名称 name: string; // 股票名称
code: string; // 股票代码 code: string; // 股票代码
indexTags: string[]; // 指数标签(如 沪深300、上证50 indexTags: string[]; // 指数标签(如 沪深300、上证50
industry?: string; // 所属行业(二级),如 "银行"
industryL1?: string; // 一级行业,如 "金融"
// 价格信息 // 价格信息
currentPrice: number; // 当前价格 currentPrice: number; // 当前价格

View File

@@ -16,6 +16,8 @@ const transformQuoteData = (apiData, stockCode) => {
name: apiData.name || apiData.stock_name || '未知', name: apiData.name || apiData.stock_name || '未知',
code: apiData.code || apiData.stock_code || stockCode, code: apiData.code || apiData.stock_code || stockCode,
indexTags: apiData.index_tags || apiData.indexTags || [], indexTags: apiData.index_tags || apiData.indexTags || [],
industry: apiData.industry || apiData.sw_industry_l2 || '',
industryL1: apiData.industry_l1 || apiData.sw_industry_l1 || '',
// 价格信息 // 价格信息
currentPrice: apiData.current_price || apiData.currentPrice || apiData.close || 0, currentPrice: apiData.current_price || apiData.currentPrice || apiData.close || 0,