加载中...
@@ -328,4 +339,15 @@ function renderEventContent(event: GameEvent): string {
font-size: 11px;
border-bottom: 1px solid #2a2a2a;
}
+
+/* 可点击的角色名样式 */
+.event-content :deep(.clickable-avatar) {
+ cursor: pointer;
+ transition: opacity 0.15s;
+}
+
+.event-content :deep(.clickable-avatar:hover) {
+ opacity: 0.8;
+ text-decoration: underline;
+}
diff --git a/web/src/utils/eventHelper.ts b/web/src/utils/eventHelper.ts
index f47c077..3e91e37 100644
--- a/web/src/utils/eventHelper.ts
+++ b/web/src/utils/eventHelper.ts
@@ -90,16 +90,21 @@ export function avatarIdToColor(id: string): string {
return `hsl(${hue}, 70%, 65%)`;
}
+export interface AvatarColorInfo {
+ id: string;
+ color: string;
+}
+
/**
- * 根据角色列表构建 name -> color 映射表。
+ * 根据角色列表构建 name -> { id, color } 映射表。
*/
export function buildAvatarColorMap(
avatars: Array<{ id: string; name?: string }>
-): Map {
- const map = new Map();
+): Map {
+ const map = new Map();
for (const av of avatars) {
if (av.name) {
- map.set(av.name, avatarIdToColor(av.id));
+ map.set(av.name, { id: av.id, color: avatarIdToColor(av.id) });
}
}
return map;
@@ -115,10 +120,11 @@ const HTML_ESCAPE_MAP: Record = {
/**
* 高亮文本中的角色名,返回 HTML 字符串。
+ * 生成的 span 带有 data-avatar-id 属性,可用于点击跳转。
*/
export function highlightAvatarNames(
text: string,
- colorMap: Map
+ colorMap: Map
): string {
if (!text || colorMap.size === 0) return text;
@@ -127,9 +133,12 @@ export function highlightAvatarNames(
let result = text;
for (const name of names) {
- const color = colorMap.get(name)!;
+ const info = colorMap.get(name)!;
const escaped = name.replace(/[&<>"']/g, c => HTML_ESCAPE_MAP[c] || c);
- result = result.replaceAll(name, `${escaped}`);
+ result = result.replaceAll(
+ name,
+ `${escaped}`
+ );
}
return result;
}