Prechádzať zdrojové kódy

实现从历史进入打印;修复从historylist 导航进入处理不显示体位列表的问题;重构体位列表组件,精简结构

dengdx 1 mesiac pred
rodič
commit
138fb3c1f9

+ 63 - 0
src/domain/patient/historyToPrint.ts

@@ -0,0 +1,63 @@
+import { setBusinessFlow } from '../../states/BusinessFlowSlice';
+import store from '@/states/store';
+import { clearWorks, addWork } from '../../states/exam/examWorksCacheSlice';
+import { prepareWorksForExam } from './worklistToExam';
+import {
+  transformWorksToBodyPositions,
+  setBodyPositions,
+} from '../../states/exam/bodyPositionListSlice';
+
+/**
+ * 从历史记录进入打印页面
+ * @param selectedIds - 选中的 StudyID 数组
+ */
+const historyToPrint = async (selectedIds: string[]) => {
+  const dispatch = store.dispatch;
+
+  try {
+    if (selectedIds.length === 0) {
+      console.warn('[historyToPrint] No studies selected');
+      return;
+    }
+
+    console.log('[historyToPrint] Loading data for print page:', selectedIds);
+
+    // Clear existing works in the cache
+    await dispatch(clearWorks());
+
+    // 获取选中的 Task 对象
+    const state = store.getState();
+    const selectedTasks = state.historyEntities.data.filter((task) =>
+      selectedIds.includes(task.StudyID)
+    );
+
+    if (selectedTasks.length === 0) {
+      console.warn('[historyToPrint] No matching tasks found');
+      return;
+    }
+
+    // 使用公共函数准备数据(获取详细信息)
+    const preparedTasks = await prepareWorksForExam(selectedTasks);
+
+    // 保存到 examWorksCache
+    preparedTasks.forEach((task) => {
+      dispatch(addWork(task));
+    });
+
+    // 转换为体位列表
+    const bodyPositions = await transformWorksToBodyPositions(preparedTasks);
+    await dispatch(setBodyPositions(bodyPositions));
+
+    console.log(
+      '[historyToPrint] Data loaded successfully, navigating to print page'
+    );
+
+    // 切换到打印页面
+    await dispatch(setBusinessFlow('print'));
+  } catch (error) {
+    console.error('[historyToPrint] Error:', error);
+    throw error;
+  }
+};
+
+export default historyToPrint;

+ 31 - 2
src/layouts/BasicLayout.tsx

@@ -19,10 +19,13 @@ import MeButton from '@/pages/security/components/MeButton';
 import Profile from '@/pages/security/Profile';
 import ExamPage from '@/pages/exam/ExamPage';
 import { RootState } from '@/states/store';
+import store from '@/states/store';
 import { setBusinessFlow } from '@/states/BusinessFlowSlice';
 import ImageProcessingPage from '@/pages/view/ImageProcessingPage';
 import PrintPage from '@/pages/output/print/PrintPage';
 import { pageLayoutConfig } from '@/config/pageLayout';
+import historyToPrint from '@/domain/patient/historyToPrint';
+import { message } from 'antd';
 
 // import { Link } from 'react-router-dom';
 // import { MenuOutlined } from '@ant-design/icons';
@@ -69,8 +72,34 @@ const BasicLayout: React.FC<BasicLayoutProps> = () => {
     print: <PrintPage />,
   };
   //感知菜单项点击
-  const handleMenuClick = (key: string) => {
-    dispatch(setBusinessFlow(key));
+  const handleMenuClick = async (key: string) => {
+    // 特殊处理打印按钮
+    if (key === 'print') {
+      // 获取当前选中的记录
+      const state = store.getState();
+      const selectedIds = 
+        currentKey === 'historylist' 
+          ? state.historySelection.selectedIds 
+          : currentKey === 'worklist'
+          ? state.workSelection.selectedIds
+          : [];
+      
+      if (selectedIds.length === 0) {
+        message.warning('请先选择要打印的项目');
+        return;
+      }
+      
+      try {
+        // 调用 historyToPrint 加载数据并跳转
+        await historyToPrint(selectedIds);
+      } catch (error) {
+        console.error('[BusinessZone] Print error:', error);
+        message.error('加载打印数据失败,请重试');
+      }
+    } else {
+      // 其他按钮直接切换页面
+      dispatch(setBusinessFlow(key));
+    }
   };
 
   return (

+ 3 - 3
src/pages/exam/ContentAreaLarge.tsx

@@ -257,9 +257,9 @@ const ContentAreaLarge = () => {
 
   return (
     <Row className="w-full p-1" style={{ height: '100%', display: 'flex' }}>
-      <Col span={20} style={{ display: 'flex', flexDirection: 'column' }}>
-        <Row gutter={16} style={{ flex: 1, minHeight: 0, display: 'flex' }}>
-          <Col span={4} className="flex flex-col">
+      <Col span={20} style={{ display: 'flex', flexDirection: 'column' }} className='h-full'>
+        <Row gutter={16} style={{ flex: 1, minHeight: 0, display: 'flex' }} className='h-full'>
+          <Col span={4} className="flex flex-col h-full" >
             <BodyPositionList layout="vertical"></BodyPositionList>
           </Col>
           <Col span={20}>

+ 2 - 2
src/pages/exam/components/BodyPositionList.tsx

@@ -106,8 +106,8 @@ const BodyPositionList: React.FC<BodyPositionListProps> = ({
 
   return (
     // 父级是flex,这里是grid,grid的高度需要设置为0,并且flex-grow,这样才能不撑开grid
-    <div className={`${layout} grid grid-rows-[1fr_auto] h-0 flex-grow`}>
-      <div className="overflow-y-auto flex flex-col ">
+    <div className={`${layout} h-full flex-grow`}>
+      <div className="h-full overflow-y-auto flex flex-col ">
         {bodyPositions.map((bodyPosition, index) => (
           <div key={index} className="relative w-[50%] mx-auto">
             <ImageViewer

+ 2 - 2
src/pages/output/print/PrintPage.tsx

@@ -23,9 +23,9 @@ const PrintPage: React.FC = () => {
       </div>
 
       {/* 内容区域 */}
-      <div className="flex-1 flex gap-2 p-1 overflow-hidden">
+      <div className="flex-1 flex gap-2 p-1 overflow-hidden h-full">
         {/* 左侧:体位列表 */}
-        <div className="w-[15%] border rounded overflow-hidden">
+        <div className="w-[15%] border rounded overflow-hidden h-full">
           <BodyPositionList layout="vertical" showAddButton={false} />
         </div>