Просмотр исходного кода

Fix tree copy feature to support string-type scores

- Update score display logic to handle both number and string types
- Add null/undefined checks for more robust score lookup
- Convert number scores to string format with toFixed(2)
- Use string scores directly if already formatted
- Fixes issue where scores weren't showing in copied tree structure

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

Co-Authored-By: Claude <noreply@anthropic.com>
yangxiaohui 4 недель назад
Родитель
Сommit
bd3040c2c9
1 измененных файлов с 11 добавлено и 7 удалено
  1. 11 7
      visualization/sug_v6_1_2_8/index.js

+ 11 - 7
visualization/sug_v6_1_2_8/index.js

@@ -1274,22 +1274,26 @@ function FlowContent() {
 
         // 优先从node.data获取score,然后从nodeData获取
         let score = null;
-        if (node.data?.score !== undefined) {
+        if (node.data?.score !== undefined && node.data?.score !== null) {
           score = node.data.score;
-        } else if (node.data?.relevance_score !== undefined) {
+        } else if (node.data?.relevance_score !== undefined && node.data?.relevance_score !== null) {
           score = node.data.relevance_score;
-        } else if (nodeData.score !== undefined) {
+        } else if (nodeData.score !== undefined && nodeData.score !== null) {
           score = nodeData.score;
-        } else if (nodeData.relevance_score !== undefined) {
+        } else if (nodeData.relevance_score !== undefined && nodeData.relevance_score !== null) {
           score = nodeData.relevance_score;
         }
 
         const strategy = nodeData.strategy || node.data?.strategy || '';
 
-        // 构建当前行 - 确保score为数字且不是step/round节点时显示
+        // 构建当前行 - score可能是数字或字符串,step/round节点不显示分数
         const connector = isLastNode ? '└─' : '├─';
-        const scoreText = (nodeType !== 'step' && nodeType !== 'round' && typeof score === 'number') ?
-                         \` (分数: \${score.toFixed(2)})\` : '';
+        let scoreText = '';
+        if (nodeType !== 'step' && nodeType !== 'round' && score !== null && score !== undefined) {
+          // score可能已经是字符串格式(如 "0.05"),也可能是数字
+          const scoreStr = typeof score === 'number' ? score.toFixed(2) : score;
+          scoreText = \` (分数: \${scoreStr})\`;
+        }
         const strategyText = strategy ? \` [\${strategy}]\` : '';
 
         lines.push(\`\${prefix}\${connector} \${title}\${scoreText}\${strategyText}\`);