From 076878287de0c83de5dd6e8696cf6961a64cf994 Mon Sep 17 00:00:00 2001 From: imeepos Date: Fri, 25 Jul 2025 17:30:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9D=83=E9=87=8D?= =?UTF-8?q?=E6=8C=87=E7=A4=BA=E5=99=A8=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E5=88=86=E7=B1=BB=E6=95=B0=E9=87=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 SegmentWeightIndicator 只统计实际选择的分类数量 - 对于按顺序匹配规则,只显示用户选择的分类权重统计 - 传递 segmentMatchingRule 参数以获取准确的分类选择信息 - 解决显示'4 分类'但实际只选择2个分类的问题 --- .../template/SegmentWeightIndicator.tsx | 30 +++++++++++++++++-- .../template/TemplateDetailModal.tsx | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/components/template/SegmentWeightIndicator.tsx b/apps/desktop/src/components/template/SegmentWeightIndicator.tsx index d6b0249..b867e2c 100644 --- a/apps/desktop/src/components/template/SegmentWeightIndicator.tsx +++ b/apps/desktop/src/components/template/SegmentWeightIndicator.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { CogIcon, ArrowPathIcon } from '@heroicons/react/24/outline'; -import { TemplateSegmentWeightHelper } from '../../types/template'; +import { TemplateSegmentWeightHelper, SegmentMatchingRuleHelper } from '../../types/template'; import { TemplateSegmentWeightService } from '../../services/templateSegmentWeightService'; interface SegmentWeightIndicatorProps { @@ -8,6 +8,8 @@ interface SegmentWeightIndicatorProps { templateId: string; /** 轨道片段ID */ trackSegmentId: string; + /** 片段匹配规则 - 用于确定实际选择的分类 */ + segmentMatchingRule?: any; /** 是否禁用编辑 */ disabled?: boolean; /** 点击编辑按钮的回调 */ @@ -25,6 +27,7 @@ interface SegmentWeightIndicatorProps { export const SegmentWeightIndicator: React.FC = ({ templateId, trackSegmentId, + segmentMatchingRule, disabled = false, onEditClick, onWeightsUpdated, @@ -53,8 +56,27 @@ export const SegmentWeightIndicator: React.FC = ({ setHasCustomWeights(hasCustom); - // 计算权重摘要 - const weightValues = Object.values(weights); + // 计算权重摘要 - 只统计实际选择的分类 + let relevantWeights: Record = {}; + + if (segmentMatchingRule && SegmentMatchingRuleHelper.isPriorityOrder(segmentMatchingRule)) { + // 对于按顺序匹配规则,只统计选择的分类 + const selectedCategoryIds = typeof segmentMatchingRule === 'object' && 'PriorityOrder' in segmentMatchingRule + ? segmentMatchingRule.PriorityOrder.category_ids + : []; + + // 只包含选择的分类的权重 + relevantWeights = Object.fromEntries( + Object.entries(weights).filter(([classificationId]) => + selectedCategoryIds.includes(classificationId) + ) + ); + } else { + // 对于其他规则类型,使用所有权重 + relevantWeights = weights; + } + + const weightValues = Object.values(relevantWeights); if (weightValues.length > 0) { const totalClassifications = weightValues.length; const averageWeight = weightValues.reduce((sum, weight) => sum + weight, 0) / totalClassifications; @@ -65,6 +87,8 @@ export const SegmentWeightIndicator: React.FC = ({ averageWeight: Math.round(averageWeight * 10) / 10, maxWeight, }); + } else { + setWeightSummary(null); } } catch (error) { console.error('加载权重信息失败:', error); diff --git a/apps/desktop/src/components/template/TemplateDetailModal.tsx b/apps/desktop/src/components/template/TemplateDetailModal.tsx index e9c474c..ae58cee 100644 --- a/apps/desktop/src/components/template/TemplateDetailModal.tsx +++ b/apps/desktop/src/components/template/TemplateDetailModal.tsx @@ -795,6 +795,7 @@ export const TemplateDetailModal: React.FC = ({ toggleWeightEditor(segment.id)} onWeightsUpdated={handleWeightsUpdated} className="inline-block"