Browse Source

🔧 fix(disability): 修复残疾人选择器中AreaSelect组件的Form上下文问题

- 在DisabledPersonSelector中导入Form和useForm
- 将AreaSelect包装在Form组件中,提供必要的表单上下文
- 清理OrderForm和测试中的调试代码
- 解决AreaSelect组件因缺少Form上下文可能导致的问题

🤖 Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 1 day ago
parent
commit
ac3878d295

+ 1 - 14
allin-packages/order-management-ui/src/components/OrderForm.tsx

@@ -100,10 +100,6 @@ export const OrderForm: React.FC<OrderFormProps> = ({
   const [selectedPersons, setSelectedPersons] = useState<DisabledPersonData[]>([]);
   const [isPersonSelectorOpen, setIsPersonSelectorOpen] = useState(false);
 
-  // 调试selectedPersons变化
-  useEffect(() => {
-    console.debug('selectedPersons变化:', selectedPersons);
-  }, [selectedPersons]);
 
   // 初始化表单 - 根据UI包开发规范,必须使用条件渲染两个独立的Form组件
   // 这里使用同一个组件,但通过reset来区分创建和编辑模式
@@ -295,19 +291,12 @@ export const OrderForm: React.FC<OrderFormProps> = ({
 
   // 处理残疾人选择
   const handlePersonSelect = (persons: DisabledPersonData | DisabledPersonData[]) => {
-    console.debug('handlePersonSelect被调用:', { persons, isArray: Array.isArray(persons) });
-
     if (Array.isArray(persons)) {
       // 多选模式
       const newPersons = persons.filter(
         person => !selectedPersons.some(p => p.id === person.id)
       );
-      console.debug('多选模式,新人员:', newPersons, '当前selectedPersons:', selectedPersons);
-      setSelectedPersons(prev => {
-        const updated = [...prev, ...newPersons];
-        console.debug('setSelectedPersons被调用,更新后的值:', updated);
-        return updated;
-      });
+      setSelectedPersons(prev => [...prev, ...newPersons]);
 
       // 更新表单值 - 根据后端API要求包含必需字段
       const currentPersons = form.getValues('orderPersons') || [];
@@ -320,12 +309,10 @@ export const OrderForm: React.FC<OrderFormProps> = ({
         role: '',
         remark: ''
       }));
-      console.debug('更新表单值,新表单人员:', newFormPersons);
       form.setValue('orderPersons', [...currentPersons, ...newFormPersons]);
     } else {
       // 单选模式
       const person = persons;
-      console.debug('单选模式,人员:', person);
       if (!selectedPersons.some(p => p.id === person.id)) {
         setSelectedPersons(prev => [...prev, person]);
 

+ 6 - 42
allin-packages/order-management-ui/tests/integration/order.integration.test.tsx

@@ -84,7 +84,6 @@ vi.mock('@d8d/allin-disability-person-management-ui', () => ({
               phone: '13800138000'
             };
             onSelect(mode === 'multiple' ? [mockPerson] : mockPerson);
-            console.debug('选择人员按钮点击,调用onSelect,准备调用onOpenChange(false)');
             onOpenChange(false);
           }}
           style={{ pointerEvents: 'auto' }} // 确保按钮可以点击
@@ -826,57 +825,22 @@ describe('订单管理集成测试', () => {
 
       // 点击选择残疾人按钮
       const selectPersonsButton = screen.getByTestId('select-persons-button');
-      console.debug('点击选择残疾人按钮前,按钮状态:', {
-        disabled: selectPersonsButton.disabled,
-        style: selectPersonsButton.style,
-        outerHTML: selectPersonsButton.outerHTML
-      });
       await userEvent.click(selectPersonsButton);
 
-      // 验证残疾人选择器打开 - 添加调试信息
+      // 验证残疾人选择器打开
       await waitFor(() => {
-        const selector = screen.getByTestId('disabled-person-selector-mock');
-        expect(selector).toBeInTheDocument();
-        console.debug('残疾人选择器已打开,DOM结构:', selector.outerHTML);
+        expect(screen.getByTestId('disabled-person-selector-mock')).toBeInTheDocument();
       });
 
       // 选择测试人员
       const selectPersonButton = screen.getByTestId('select-person-button');
-      console.debug('选择人员按钮:', selectPersonButton);
       await userEvent.click(selectPersonButton);
 
-      // 不手动关闭残疾人选择器,让handlePersonSelect中的setIsPersonSelectorOpen(false)处理
-
-      // 验证人员被添加到列表 - 添加更灵活的查找方式
+      // 验证人员被添加到列表
       await waitFor(() => {
-        // 首先检查订单表单是否仍然打开
-        const dialogTitle = screen.queryByTestId('create-order-dialog-title');
-        console.debug('订单表单对话框状态:', {
-          dialogTitle: dialogTitle?.textContent,
-          dialogTitleExists: !!dialogTitle
-        });
-
-        // 检查人员选择区域是否存在
-        const selectPersonsButton = screen.queryByTestId('select-persons-button');
-        console.debug('人员选择按钮状态:', {
-          selectPersonsButton: selectPersonsButton?.textContent,
-          selectPersonsButtonExists: !!selectPersonsButton
-        });
-
-        // 尝试多种查找方式
-        const personText = screen.queryByText('测试残疾人');
-        const disabilityTypeText = screen.queryByText('肢体残疾');
-        const disabilityLevelText = screen.queryByText('三级');
-
-        console.debug('查找结果:', {
-          personText: personText?.textContent,
-          disabilityTypeText: disabilityTypeText?.textContent,
-          disabilityLevelText: disabilityLevelText?.textContent
-        });
-
-        expect(personText).toBeInTheDocument();
-        expect(disabilityTypeText).toBeInTheDocument();
-        expect(disabilityLevelText).toBeInTheDocument();
+        expect(screen.getByText('测试残疾人')).toBeInTheDocument();
+        expect(screen.getByText('肢体残疾')).toBeInTheDocument();
+        expect(screen.getByText('三级')).toBeInTheDocument();
       });
 
       // 填写订单基本信息