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"