import React from 'react'; import * as Tooltip from '@radix-ui/react-tooltip'; import { characterInfoMap, sceneInfoMap, mockCharacterOptions, mockSceneOptions } from '@/app/model/enums'; import { motion } from 'framer-motion'; interface KeywordTextProps { text: string; className?: string; id?: string; } const KeywordText: React.FC = ({ text, className = '', id }) => { // 解析文本中的关键词 const parseText = (text: string) => { const parts: React.ReactNode[] = []; let currentIndex = 0; // 匹配 #角色# 和 [场景] const regex = /#([^#]+)#|\[([^\]]+)\]/g; let match; while ((match = regex.exec(text)) !== null) { // 添加普通文本 if (match.index > currentIndex) { parts.push(text.slice(currentIndex, match.index)); } const [fullMatch, character, scene] = match; if (character) { // 角色关键词 const info = mockCharacterOptions.find(option => option.characterId === id); if (info) { parts.push( #{character}#
{character}
{character}
{info.gender} · {info.age}岁
{info.description}
); } else { parts.push(#{character}#); } } else if (scene) { // 场景关键词 const info = mockSceneOptions.find(option => option.sceneId === id); console.log('info', info); if (info) { parts.push( [{scene}]
{scene}
{scene}
{info.location} · {info.time}
); } else { parts.push([{scene}]); } } currentIndex = match.index + fullMatch.length; } // 添加剩余文本 if (currentIndex < text.length) { parts.push(text.slice(currentIndex)); } return parts; }; return ( {parseText(text)} ); }; export default KeywordText;