|
|
@@ -51,6 +51,7 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
const [pregnancyStatusFieldVisible, setPregnancyStatusFieldVisible] =
|
|
|
useState(false);
|
|
|
const initializedRef = useRef(false);
|
|
|
+ const [hasFocusedInput, setHasFocusedInput] = useState(false);
|
|
|
|
|
|
// 扫码枪扫码相关状态
|
|
|
const scanInputRef = useRef<HTMLInputElement>(null);
|
|
|
@@ -282,6 +283,11 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
|
|
|
// 扫码枪扫码监听器:页面级 keydown 监听,自动切换焦点到隐藏input
|
|
|
useEffect(() => {
|
|
|
+ // 如果有聚焦输入,不监听键盘事件
|
|
|
+ if (hasFocusedInput) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const handleKeyDown = (e: KeyboardEvent) => {
|
|
|
const target = e.target as HTMLElement;
|
|
|
|
|
|
@@ -385,7 +391,7 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
window.removeEventListener('keydown', handleKeyDown);
|
|
|
window.removeEventListener('keyup', handleKeyUp);
|
|
|
};
|
|
|
- }, [processScannedData]);
|
|
|
+ }, [processScannedData, hasFocusedInput]);
|
|
|
|
|
|
/** input 事件:真正可靠地拿中文 */
|
|
|
const handleScanInput = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
@@ -426,7 +432,7 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
|
|
|
right: '48px',
|
|
|
zIndex: 1000
|
|
|
}}>
|
|
|
- <BarcodeScannerIndicator />
|
|
|
+ <BarcodeScannerIndicator onHasFocusedInputChange={setHasFocusedInput} />
|
|
|
</div>
|
|
|
{/** 宠物专用 */}
|
|
|
{productName === 'VETDROS' && (
|