Bladeren bron

fix (1.70.4 -> 1.70.5): 修复聚焦输入时禁用扫码枪键盘监听,避免用户键盘不可输入到注册表单中的文本框

- 在 BarcodeScannerIndicator 组件中添加 onHasFocusedInputChange 回调属性,实现父子组件通信
- 在 register.form.tsx 中添加 hasFocusedInput 状态管理,跟踪输入框聚焦状态
- 当有输入框聚焦时,禁用扫码枪的键盘事件监听,避免输入冲突和意外触发
- 优化扫码枪监听器的依赖数组,确保状态变化时正确更新监听行为

改动文件:
- src/components/BarcodeScannerIndicator/index.tsx
- src/pages/patient/components/register.form.tsx
- package.json
dengdx 12 uur geleden
bovenliggende
commit
dea268943b

+ 15 - 0
CHANGELOG.md

@@ -2,6 +2,21 @@
 
 
 本项目的所有重要变更都将记录在此文件中.
 本项目的所有重要变更都将记录在此文件中.
 
 
+## [1.70.5] - 2026-01-20 16:52
+
+fix (1.70.4 -> 1.70.5): 修复聚焦输入时禁用扫码枪键盘监听,避免用户键盘不可输入到注册表单中的文本框
+
+- 在 BarcodeScannerIndicator 组件中添加 onHasFocusedInputChange 回调属性,实现父子组件通信
+- 在 register.form.tsx 中添加 hasFocusedInput 状态管理,跟踪输入框聚焦状态
+- 当有输入框聚焦时,禁用扫码枪的键盘事件监听,避免输入冲突和意外触发
+- 优化扫码枪监听器的依赖数组,确保状态变化时正确更新监听行为
+
+改动文件:
+
+- src/components/BarcodeScannerIndicator/index.tsx
+- src/pages/patient/components/register.form.tsx
+- package.json
+
 ## [1.70.4] - 2026-01-20 15:28
 ## [1.70.4] - 2026-01-20 15:28
 
 
 feat (1.70.3 -> 1.71.0): 添加站点信息SN码显示和复制功能,修正系统模式标签并添加扫码枪翻译
 feat (1.70.3 -> 1.71.0): 添加站点信息SN码显示和复制功能,修正系统模式标签并添加扫码枪翻译

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "zsis",
   "name": "zsis",
-  "version": "1.70.4",
+  "version": "1.70.5",
   "private": true,
   "private": true,
   "description": "医学成像系统",
   "description": "医学成像系统",
   "main": "main.js",
   "main": "main.js",

+ 8 - 1
src/components/BarcodeScannerIndicator/index.tsx

@@ -7,12 +7,14 @@ interface BarcodeScannerIndicatorProps {
   style?: React.CSSProperties;
   style?: React.CSSProperties;
   className?: string;
   className?: string;
   inline?: boolean; // 是否为内联模式(非浮动)
   inline?: boolean; // 是否为内联模式(非浮动)
+  onHasFocusedInputChange?: (hasFocusedInput: boolean) => void;
 }
 }
 
 
 const BarcodeScannerIndicator: React.FC<BarcodeScannerIndicatorProps> = ({
 const BarcodeScannerIndicator: React.FC<BarcodeScannerIndicatorProps> = ({
   style,
   style,
   className,
   className,
-  inline = false
+  inline = false,
+  onHasFocusedInputChange
 }) => {
 }) => {
   const intl = useIntl();
   const intl = useIntl();
   const [hasFocusedInput, setHasFocusedInput] = useState(false);
   const [hasFocusedInput, setHasFocusedInput] = useState(false);
@@ -72,6 +74,11 @@ const BarcodeScannerIndicator: React.FC<BarcodeScannerIndicatorProps> = ({
     };
     };
   }, []);
   }, []);
 
 
+  // 当 hasFocusedInput 改变时通知父组件
+  useEffect(() => {
+    onHasFocusedInputChange?.(hasFocusedInput);
+  }, [hasFocusedInput, onHasFocusedInputChange]);
+
   // 点击处理:使所有输入框失焦
   // 点击处理:使所有输入框失焦
   const handleClick = () => {
   const handleClick = () => {
     const activeElement = document.activeElement as HTMLElement;
     const activeElement = document.activeElement as HTMLElement;

+ 8 - 2
src/pages/patient/components/register.form.tsx

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