fix: 修复权重指示器显示错误的分类数量问题
- 修改 SegmentWeightIndicator 只统计实际选择的分类数量 - 对于按顺序匹配规则,只显示用户选择的分类权重统计 - 传递 segmentMatchingRule 参数以获取准确的分类选择信息 - 解决显示'4 分类'但实际只选择2个分类的问题
This commit is contained in:
parent
68124b92e9
commit
076878287d
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { CogIcon, ArrowPathIcon } from '@heroicons/react/24/outline';
|
import { CogIcon, ArrowPathIcon } from '@heroicons/react/24/outline';
|
||||||
import { TemplateSegmentWeightHelper } from '../../types/template';
|
import { TemplateSegmentWeightHelper, SegmentMatchingRuleHelper } from '../../types/template';
|
||||||
import { TemplateSegmentWeightService } from '../../services/templateSegmentWeightService';
|
import { TemplateSegmentWeightService } from '../../services/templateSegmentWeightService';
|
||||||
|
|
||||||
interface SegmentWeightIndicatorProps {
|
interface SegmentWeightIndicatorProps {
|
||||||
|
|
@ -8,6 +8,8 @@ interface SegmentWeightIndicatorProps {
|
||||||
templateId: string;
|
templateId: string;
|
||||||
/** 轨道片段ID */
|
/** 轨道片段ID */
|
||||||
trackSegmentId: string;
|
trackSegmentId: string;
|
||||||
|
/** 片段匹配规则 - 用于确定实际选择的分类 */
|
||||||
|
segmentMatchingRule?: any;
|
||||||
/** 是否禁用编辑 */
|
/** 是否禁用编辑 */
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
/** 点击编辑按钮的回调 */
|
/** 点击编辑按钮的回调 */
|
||||||
|
|
@ -25,6 +27,7 @@ interface SegmentWeightIndicatorProps {
|
||||||
export const SegmentWeightIndicator: React.FC<SegmentWeightIndicatorProps> = ({
|
export const SegmentWeightIndicator: React.FC<SegmentWeightIndicatorProps> = ({
|
||||||
templateId,
|
templateId,
|
||||||
trackSegmentId,
|
trackSegmentId,
|
||||||
|
segmentMatchingRule,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
onEditClick,
|
onEditClick,
|
||||||
onWeightsUpdated,
|
onWeightsUpdated,
|
||||||
|
|
@ -53,8 +56,27 @@ export const SegmentWeightIndicator: React.FC<SegmentWeightIndicatorProps> = ({
|
||||||
|
|
||||||
setHasCustomWeights(hasCustom);
|
setHasCustomWeights(hasCustom);
|
||||||
|
|
||||||
// 计算权重摘要
|
// 计算权重摘要 - 只统计实际选择的分类
|
||||||
const weightValues = Object.values(weights);
|
let relevantWeights: Record<string, number> = {};
|
||||||
|
|
||||||
|
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) {
|
if (weightValues.length > 0) {
|
||||||
const totalClassifications = weightValues.length;
|
const totalClassifications = weightValues.length;
|
||||||
const averageWeight = weightValues.reduce((sum, weight) => sum + weight, 0) / totalClassifications;
|
const averageWeight = weightValues.reduce((sum, weight) => sum + weight, 0) / totalClassifications;
|
||||||
|
|
@ -65,6 +87,8 @@ export const SegmentWeightIndicator: React.FC<SegmentWeightIndicatorProps> = ({
|
||||||
averageWeight: Math.round(averageWeight * 10) / 10,
|
averageWeight: Math.round(averageWeight * 10) / 10,
|
||||||
maxWeight,
|
maxWeight,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
setWeightSummary(null);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载权重信息失败:', error);
|
console.error('加载权重信息失败:', error);
|
||||||
|
|
|
||||||
|
|
@ -795,6 +795,7 @@ export const TemplateDetailModal: React.FC<TemplateDetailModalProps> = ({
|
||||||
<SegmentWeightIndicator
|
<SegmentWeightIndicator
|
||||||
templateId={currentTemplate.id}
|
templateId={currentTemplate.id}
|
||||||
trackSegmentId={segment.id}
|
trackSegmentId={segment.id}
|
||||||
|
segmentMatchingRule={segment.matching_rule}
|
||||||
onEditClick={() => toggleWeightEditor(segment.id)}
|
onEditClick={() => toggleWeightEditor(segment.id)}
|
||||||
onWeightsUpdated={handleWeightsUpdated}
|
onWeightsUpdated={handleWeightsUpdated}
|
||||||
className="inline-block"
|
className="inline-block"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue