更新人物检测组件,新增triggerSuccess属性以优化未识别出人像的提示逻辑。同时,调整扫描状态以支持超时和失败状态,提升用户体验和代码可读性。

This commit is contained in:
北枳 2025-08-13 03:16:18 +08:00
parent c5a4b6d731
commit a0b4d75548
2 changed files with 12 additions and 8 deletions

View File

@ -45,6 +45,7 @@ type Props = {
videoSrc?: string;
detections: PersonDetection[];
triggerScan: boolean;
triggerSuccess: boolean;
onScanStart?: (currentTime?: number) => void;
onScanTimeout?: () => void;
onScanExit?: () => void; // 扫描退出回调
@ -59,6 +60,7 @@ export const PersonDetectionScene: React.FC<Props> = ({
videoSrc,
detections,
triggerScan,
triggerSuccess,
onScanStart,
onScanTimeout,
onScanExit,
@ -375,8 +377,8 @@ export const PersonDetectionScene: React.FC<Props> = ({
{/* 人物识别框和浮签 */}
<AnimatePresence>
{detections.length === 0 && (
<div className="absolute inset-0 flex items-center justify-center">
{detections.length === 0 && triggerSuccess && (
<div className="absolute inset-0 flex items-center justify-center bg-black/40 backdrop-blur-sm">
<span className="text-white text-sm"></span>
</div>
)}

View File

@ -37,7 +37,7 @@ export function ShotTabContent({
const [selectedIndex, setSelectedIndex] = useState(currentSketchIndex);
const [detections, setDetections] = useState<PersonDetection[]>([]);
const [scanState, setScanState] = useState<'idle' | 'scanning' | 'detected'>('idle');
const [scanState, setScanState] = useState<'idle' | 'scanning' | 'detected' | 'failed' | 'timeout'>('idle');
const [isScanFailed, setIsScanFailed] = useState(false);
const [isLoadingLibrary, setIsLoadingLibrary] = useState(false);
const [isReplaceLibraryOpen, setIsReplaceLibraryOpen] = useState(false);
@ -82,10 +82,10 @@ export function ShotTabContent({
}
};
// 处理扫描超时/失败
// 处理扫描超时
const handleScanTimeout = () => {
setIsScanFailed(true);
setScanState('detected');
setScanState('timeout');
setDetections([]);
};
@ -97,9 +97,10 @@ export function ShotTabContent({
// 处理检测到结果
const handleDetectionsChange = (newDetections: PersonDetection[]) => {
if (newDetections.length > 0 && scanState === 'scanning') {
setScanState('detected');
}
// console.log('handleDetectionsChange', newDetections);
// if (newDetections.length > 0 && scanState === 'scanning') {
// setScanState('detected');
// }
};
// 处理人物点击 打开角色库
@ -317,6 +318,7 @@ export function ShotTabContent({
videoSrc={shotData[selectedIndex]?.videoUrl[0]}
detections={detections}
triggerScan={scanState === 'scanning'}
triggerSuccess={scanState === 'detected'}
onScanTimeout={handleScanTimeout}
onScanExit={handleScanExit}
onDetectionsChange={handleDetectionsChange}