feat: 添加[随机匹配]选项到TemplateSegment匹配规则
- 在Rust后端SegmentMatchingRule枚举中添加RandomMatch变体 - 更新TypeScript前端类型定义和SegmentMatchingRuleHelper工具函数 - 修改SegmentMatchingRuleEditor组件支持随机匹配选项 - 添加绿色样式标识随机匹配规则 - 添加完整的单元测试覆盖新功能 遵循promptx/tauri-desktop-app-expert开发规范
This commit is contained in:
@@ -92,6 +92,8 @@ export const SegmentMatchingRuleEditor: React.FC<SegmentMatchingRuleEditorProps>
|
||||
firstClassification.name
|
||||
));
|
||||
}
|
||||
} else if (ruleType === 'random') {
|
||||
setEditingRule(SegmentMatchingRuleHelper.createRandomMatch());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -106,12 +108,20 @@ export const SegmentMatchingRuleEditor: React.FC<SegmentMatchingRuleEditorProps>
|
||||
};
|
||||
|
||||
const getCurrentRuleType = (rule: SegmentMatchingRule): string => {
|
||||
return SegmentMatchingRuleHelper.isFixedMaterial(rule) ? 'fixed' : 'ai_classification';
|
||||
if (SegmentMatchingRuleHelper.isFixedMaterial(rule)) {
|
||||
return 'fixed';
|
||||
} else if (SegmentMatchingRuleHelper.isAiClassification(rule)) {
|
||||
return 'ai_classification';
|
||||
} else if (SegmentMatchingRuleHelper.isRandomMatch(rule)) {
|
||||
return 'random';
|
||||
}
|
||||
return 'fixed'; // 默认值
|
||||
};
|
||||
|
||||
const ruleTypeOptions = [
|
||||
{ value: 'fixed', label: '固定素材' },
|
||||
{ value: 'ai_classification', label: 'AI分类素材' },
|
||||
{ value: 'random', label: '随机匹配' },
|
||||
];
|
||||
|
||||
const classificationOptions = aiClassifications.map(classification => ({
|
||||
@@ -127,7 +137,11 @@ export const SegmentMatchingRuleEditor: React.FC<SegmentMatchingRuleEditorProps>
|
||||
<span className={`px-2 py-1 rounded text-xs ${
|
||||
SegmentMatchingRuleHelper.isFixedMaterial(currentRule)
|
||||
? 'bg-gray-100 text-gray-800'
|
||||
: 'bg-blue-100 text-blue-800'
|
||||
: SegmentMatchingRuleHelper.isAiClassification(currentRule)
|
||||
? 'bg-blue-100 text-blue-800'
|
||||
: SegmentMatchingRuleHelper.isRandomMatch(currentRule)
|
||||
? 'bg-green-100 text-green-800'
|
||||
: 'bg-gray-100 text-gray-800'
|
||||
}`}>
|
||||
{SegmentMatchingRuleHelper.getDisplayName(currentRule)}
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user