Forráskód Böngészése

feat (1.61.1 -> 1.61.2): 实现性别选择时动态显示妊娠状态字段

szy 5 napja
szülő
commit
4e39f55b2e

+ 11 - 2
CHANGELOG.md

@@ -2,6 +2,17 @@
 
 本项目的所有重要变更都将记录在此文件中.
 
+## [1.61.2] - 2026-01-07 17:36
+
+### 新增 (Added)
+
+- **实现性别选择时动态显示妊娠状态字段** - 根据性别选择动态显示或隐藏妊娠状态字段,并集成表单状态同步
+
+**改动文件:**
+
+- src/pages/patient/components/register.form.tsx
+- src/pages/patient/register.tsx
+
 ## [1.61.1] - 2026-01-07 16:35
 
 ### 修复 (Fixed)
@@ -13,7 +24,6 @@
 
 - src/pages/output/print/PrintControl.tsx
 
-
 ## [1.61.0] - 2026-01-07 15:41
 
 ### 优化 (Optimized)
@@ -197,7 +207,6 @@
 - src/pages/patient/DiagnosticReport/components/BaseInfo.tsx
 - src/pages/patient/DiagnosticReport/components/DepartmentModal.tsx
 
-
 ## [1.54.0] - 2026-01-06 16:57
 
 ### 新增 (Added)

+ 1 - 1
package.json

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

+ 92 - 19
src/pages/patient/components/register.form.tsx

@@ -1,4 +1,4 @@
-import React, { useEffect, useRef, useMemo } from 'react';
+import React, { useEffect, useRef, useMemo, useState } from 'react';
 import {
   Form,
   Input,
@@ -12,11 +12,14 @@ import { useIntl, FormattedMessage } from 'react-intl';
 import { registerFormFields } from '@/validation/patient/registerSchema';
 import NumberWithUnit from '@/components/NumberWithUnit';
 import dayjs, { Dayjs } from 'dayjs';
-import { useSelector } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
 import { RootState } from '@/states/store';
-import { PregnancyStatus, pregnancyStatusOptions } from '@/domain/patient/pregnancyStatus';
+import { setFormData } from '@/states/patient/register/formSlice';
+import {
+  PregnancyStatus,
+  pregnancyStatusOptions,
+} from '@/domain/patient/pregnancyStatus';
 import { getGenderOptions } from '@/domain/patient/genderOptions';
-
 interface BasicInfoFormProps {
   style?: React.CSSProperties;
   form?: FormInstance;
@@ -37,6 +40,9 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
   const productName = useSelector(
     (state: RootState) => state.product.productName
   );
+  const dispatch = useDispatch();
+  const [pregnancyStatusFieldVisible, setPregnancyStatusFieldVisible] =
+    useState(false);
 
   const intl = useIntl();
 
@@ -154,8 +160,16 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
       <Form.Item
         label={
           <FormattedMessage
-            id={productName === 'VETDROS' ? 'animal.register.patientName' : 'register.patientName'}
-            defaultMessage={productName === 'VETDROS' ? 'animal.register.patientName' : 'register.patientName'}
+            id={
+              productName === 'VETDROS'
+                ? 'animal.register.patientName'
+                : 'register.patientName'
+            }
+            defaultMessage={
+              productName === 'VETDROS'
+                ? 'animal.register.patientName'
+                : 'register.patientName'
+            }
           />
         }
         name="patient_name"
@@ -165,8 +179,14 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
       >
         <Input
           placeholder={intl.formatMessage({
-            id: productName === 'VETDROS' ? 'animal.register.patientName.placeholder' : 'register.patientName.placeholder',
-            defaultMessage: productName === 'VETDROS' ? 'animal.register.patientName.placeholder' : 'register.patientName.placeholder',
+            id:
+              productName === 'VETDROS'
+                ? 'animal.register.patientName.placeholder'
+                : 'register.patientName.placeholder',
+            defaultMessage:
+              productName === 'VETDROS'
+                ? 'animal.register.patientName.placeholder'
+                : 'register.patientName.placeholder',
           })}
         />
       </Form.Item>
@@ -192,8 +212,16 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
       <Form.Item
         label={
           <FormattedMessage
-            id={productName === 'VETDROS' ? 'animal.register.patientId' : 'register.patientId'}
-            defaultMessage={productName === 'VETDROS' ? 'animal.register.patientId' : 'register.patientId'}
+            id={
+              productName === 'VETDROS'
+                ? 'animal.register.patientId'
+                : 'register.patientId'
+            }
+            defaultMessage={
+              productName === 'VETDROS'
+                ? 'animal.register.patientId'
+                : 'register.patientId'
+            }
           />
         }
         name="patient_id"
@@ -203,8 +231,14 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
       >
         <Input
           placeholder={intl.formatMessage({
-            id: productName === 'VETDROS' ? 'animal.register.patientId.placeholder' : 'register.patientId.placeholder',
-            defaultMessage: productName === 'VETDROS' ? 'animal.register.patientId.placeholder' : 'register.patientId.placeholder',
+            id:
+              productName === 'VETDROS'
+                ? 'animal.register.patientId.placeholder'
+                : 'register.patientId.placeholder',
+            defaultMessage:
+              productName === 'VETDROS'
+                ? 'animal.register.patientId.placeholder'
+                : 'register.patientId.placeholder',
           })}
         />
       </Form.Item>
@@ -212,8 +246,16 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
       <Form.Item
         label={
           <FormattedMessage
-            id={productName === 'VETDROS' ? 'animal.register.patientSize' : 'register.patientSize'}
-            defaultMessage={productName === 'VETDROS' ? 'animal.register.patientSize' : 'register.patientSize'}
+            id={
+              productName === 'VETDROS'
+                ? 'animal.register.patientSize'
+                : 'register.patientSize'
+            }
+            defaultMessage={
+              productName === 'VETDROS'
+                ? 'animal.register.patientSize'
+                : 'register.patientSize'
+            }
           />
         }
         name="patient_size"
@@ -224,8 +266,14 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
       >
         <Select
           placeholder={intl.formatMessage({
-            id: productName === 'VETDROS' ? 'animal.register.patientSize.placeholder' : 'register.patientSize.placeholder',
-            defaultMessage: productName === 'VETDROS' ? 'animal.register.patientSize.placeholder' : 'register.patientSize.placeholder',
+            id:
+              productName === 'VETDROS'
+                ? 'animal.register.patientSize.placeholder'
+                : 'register.patientSize.placeholder',
+            defaultMessage:
+              productName === 'VETDROS'
+                ? 'animal.register.patientSize.placeholder'
+                : 'register.patientSize.placeholder',
           })}
           defaultValue="Medium"
         >
@@ -294,7 +342,25 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
         validateTrigger={registerFormFields.patient_sex.trigger}
         rules={registerFormFields.patient_sex.validation}
       >
-        <Select options={genderOptions} />
+        <Select
+          options={genderOptions}
+          onChange={(e) => {
+            const _PregnancyStatusFieldVisible = e === 'M';
+            setPregnancyStatusFieldVisible(_PregnancyStatusFieldVisible);
+            if (_PregnancyStatusFieldVisible) {
+              // 更新表单
+              form?.setFieldValue('pregnancy_status', PregnancyStatus.UNKNOWN);
+              // 手动同步更新 Redux store
+              const currentValues = form?.getFieldsValue();
+              dispatch(
+                setFormData({
+                  ...currentValues,
+                  pregnancy_status: PregnancyStatus.UNKNOWN,
+                })
+              );
+            }
+          }}
+        />
       </Form.Item>
       {/** 宠物专用 */}
       {productName === 'VETDROS' && (
@@ -318,10 +384,16 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
             })}
           >
             <Select.Option value="ALTERED">
-              {intl.formatMessage({ id: 'register.sexNeutered.altered', defaultMessage: 'ALTERED' })}
+              {intl.formatMessage({
+                id: 'register.sexNeutered.altered',
+                defaultMessage: 'ALTERED',
+              })}
             </Select.Option>
             <Select.Option value="UNALTERED">
-              {intl.formatMessage({ id: 'register.sexNeutered.unaltered', defaultMessage: 'UNALTERED' })}
+              {intl.formatMessage({
+                id: 'register.sexNeutered.unaltered',
+                defaultMessage: 'UNALTERED',
+              })}
             </Select.Option>
           </Select>
         </Form.Item>
@@ -329,6 +401,7 @@ const BasicInfoForm: React.FC<BasicInfoFormProps> = ({
       {/** 人类专用 */}
       {productName === 'DROS' && (
         <Form.Item
+          hidden={pregnancyStatusFieldVisible}
           label={
             <FormattedMessage
               id="register.pregnancyStatus"

+ 10 - 5
src/pages/patient/register.tsx

@@ -30,6 +30,7 @@ import { clearReRegister } from '@/states/patient/reregister/reregisterSlice';
 import useEffectiveBreakpoint from '../../hooks/useEffectiveBreakpoint';
 import { QRCodeScanButton } from '@/components/QRCodeScanner';
 import { executeRegisterLogic } from '@/domain/patient/registerLogic';
+import { PregnancyStatus } from '@/domain/patient/pregnancyStatus';
 dayjs.extend(utc);
 
 const { Panel } = Collapse;
@@ -42,15 +43,17 @@ const RegisterPage: React.FC = () => {
   const productName = useSelector(
     (state: RootState) => state.product.productName
   );
+  const { formData } = useSelector((state: RootState) => state.form);
   const reregisterInfo = useSelector(selectRegisterInfo);
 
   // 清理时机3:组件卸载时清理表单
   useEffect(() => {
+    form.setFieldsValue(formData);
     return () => {
       // 组件卸载时清理
-      dispatch(clearFormData());
-      form.resetFields();
-      console.log('注册页面已卸载,表单数据已清空');
+      // dispatch(clearFormData());
+      // form.resetFields();
+      // console.log('注册页面已卸载,表单数据已清空');
     };
   }, [dispatch, form]);
 
@@ -70,7 +73,9 @@ const RegisterPage: React.FC = () => {
         // 设置表单值
         const updatedInfo = {
           ...reregisterInfo,
-          patient_dob: reregisterInfo.patient_dob ? dayjs(reregisterInfo.patient_dob) : null
+          patient_dob: reregisterInfo.patient_dob
+            ? dayjs(reregisterInfo.patient_dob)
+            : null,
         };
         form.setFieldsValue(updatedInfo);
 
@@ -100,7 +105,7 @@ const RegisterPage: React.FC = () => {
     views?: View[];
   }> => {
     const result = await executeRegisterLogic({
-      getState: () => store.getState()
+      getState: () => store.getState(),
     });
     if (result.success) {
       // 清理时机1:注册成功后清理表单