123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- import React from 'react';
- import { Button, Tooltip, Modal, message } from 'antd';
- import { useDispatch, useSelector } from 'react-redux';
- import {
- deleteWorkThunk,
- lockWorkInWorklistThunk,
- } from '@/states/patient/worklist/slices/workSlice';
- import { deleteWorkThunk as deleteWorkThunkFromHistory, lockWorkInhistorylistThunk } from '@/states/patient/worklist/slices/history';
- import { switchToSendPanel } from '@/states/patient/worklist/slices/historyPanelSwitchSlice';
- import { FormattedMessage } from 'react-intl';
- import { AppDispatch, RootState, useAppSelector } from '@/states/store';
- import Icon from '@/components/Icon';
- import DiagnosticReport from '../DiagnosticReport';
- import { Popup } from 'antd-mobile';
- import { setVisible } from '@/states/patient/DiagnosticReport/slice';
- import EditTaskModal from './EditTaskModal';
- import { openEditModal } from '@/states/patient/edit/editFormSlice';
- import { showNotImplemented } from '@/utils/notificationHelper';
- interface ActionButtonProps {
- icon: React.ReactNode;
- tooltip: React.ReactNode;
- onClick?: () => void;
- }
- const ActionButton: React.FC<ActionButtonProps> = ({
- icon,
- tooltip,
- onClick,
- }) => (
- <Tooltip title={tooltip}>
- <Button icon={icon} onClick={onClick} style={{ width: '2.5rem' }} />
- </Tooltip>
- );
- const ActionPanel: React.FC = () => {
- const dispatch = useDispatch<AppDispatch>();
- const workSelectedIds = useSelector(
- (state: RootState) => state.workSelection.selectedIds
- );
- const historySelectedIds = useSelector(
- (state: RootState) => state.historySelection.selectedIds
- );
- const visible = useSelector(
- (state: RootState) => state.diagnosticReport.visible
- );
- const themeType = useAppSelector((state) => state.theme.themeType);
- const currentKey = useSelector(
- (state: RootState) => state.BusinessFlow.currentKey
- );
- const workEntities = useSelector(
- (state: RootState) => state.workEntities.data
- );
- const workEntitiesFromHistory = useSelector(
- (state: RootState) => state.historyEntities.data
- );
- const getSelectedWorkIds = () => {
- const selectedIds =
- currentKey === 'worklist' ? workSelectedIds : historySelectedIds;
- return selectedIds;
- };
- const getDeleteThunk = (): typeof deleteWorkThunk => {
- return currentKey === 'worklist'
- ? deleteWorkThunk
- : deleteWorkThunkFromHistory;
- };
- const getLockThunk = () => {
- return currentKey === 'worklist'
- ? lockWorkInWorklistThunk
- : lockWorkInhistorylistThunk;
- };
- const getSelectedWorks = () => {
- const selectedIds = getSelectedWorkIds();
- if (currentKey === 'worklist') {
- return workEntities.find((w) => selectedIds.includes(w.StudyID));
- } else if (currentKey === 'historylist') {
- return workEntitiesFromHistory.find((w) =>
- selectedIds.includes(w.StudyID)
- );
- }
- };
- // 使用 worklist 或 history 的选中项,取决于哪个有值
- const selectedIds = getSelectedWorkIds();
- const handleDelete = () => {
- if (selectedIds.length === 0) {
- message.warning('请先选择要删除的项目');
- return;
- }
- //判断是否锁定
- const selectedWork = getSelectedWorks();
- if (selectedWork?.StudyLock === 'Locked') {
- message.warning('锁定状态不可删除');
- return;
- }
- Modal.confirm({
- title: '确认删除',
- content: `确定要删除选中的 ${selectedIds.length} 个项目吗?此操作不可撤销。`,
- okText: '确认删除',
- cancelText: '取消',
- okButtonProps: { danger: true },
- centered: true,
- onOk: () => {
- const delThunk = getDeleteThunk();
- dispatch(delThunk(selectedIds));
- },
- });
- };
- const handleSend = () => {
- dispatch(switchToSendPanel());
- };
- const handleShowReport = () => {
- dispatch(setVisible(true));
- };
- const getWorksFromWorklistOrHistory = () => {
- return currentKey === 'worklist' ? workEntities : workEntitiesFromHistory;
- };
- const handleEdit = () => {
- const selectedIds = getSelectedWorkIds();
- if (selectedIds.length === 0) {
- message.warning('请先选择要编辑的任务');
- return;
- }
- if (selectedIds.length > 1) {
- message.warning('只能编辑一个任务');
- return;
- }
- const works = getWorksFromWorklistOrHistory();
- const task = works.find((item) => item.StudyID === selectedIds[0]);
- if (task) {
- // 通过 dispatch action 传递数据到 slice
- dispatch(openEditModal(task));
- }
- };
- const handleLock = () => {
- const selectedIds = getSelectedWorkIds();
- // 2. 检查是否有选中项
- if (selectedIds.length === 0) {
- message.warning('请先选择要锁定/解锁的项目');
- return;
- }
- // 3. 获取第一个选中项的锁定状态
- const works = getWorksFromWorklistOrHistory();
- const selectedItem = works.find((item) => item.StudyID === selectedIds[0]);
- if (!selectedItem) return;
- // 4. 根据当前状态切换
- const newLockState =
- selectedItem.StudyLock === 'Locked' ? 'Unlocked' : 'Locked';
- const lockThunk = getLockThunk();
- // 为每个选中项执行锁定/解锁操作
- selectedIds.forEach((studyId) => {
- console.log(
- `锁定,触发action ,目标 studyid是 ${studyId},新状态是 ${newLockState}`
- );
- dispatch(lockThunk({ studyId, lock: newLockState }));
- });
- };
- return (
- <div className="flex flex-wrap gap-2 w-full">
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="Delete"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.deleteTask"
- defaultMessage="actionPanel.deleteTask"
- />
- }
- onClick={handleDelete}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="EditPatient"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.editPatient"
- defaultMessage="actionPanel.editPatient"
- />
- }
- onClick={handleEdit}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="Protect"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.lockTask"
- defaultMessage="actionPanel.lockTask"
- />
- }
- onClick={handleLock}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="RIS"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.risSync"
- defaultMessage="actionPanel.risSync"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="ReRegister"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.reRegister"
- defaultMessage="actionPanel.reRegister"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="btn_SaveLocally"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.saveLocal"
- defaultMessage="actionPanel.saveLocal"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="btn_Import"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.importXLS"
- defaultMessage="actionPanel.importXLS"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="Sort"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.sortList"
- defaultMessage="actionPanel.sortList"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="CloudShare"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.cloudShare"
- defaultMessage="actionPanel.cloudShare"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="Swap"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.imageExchange"
- defaultMessage="actionPanel.imageExchange"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="QRCodePrint"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.qrPrint"
- defaultMessage="actionPanel.qrPrint"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="Send"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.send"
- defaultMessage="actionPanel.send"
- />
- }
- onClick={handleSend}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="Export"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.export"
- defaultMessage="actionPanel.export"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="Import"
- userId="base"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.import"
- defaultMessage="actionPanel.import"
- />
- }
- onClick={() => showNotImplemented('')}
- />
- <ActionButton
- icon={
- <Icon
- module="module-patient"
- name="report"
- userId="base"
- theme={themeType}
- size="2x"
- state="normal"
- width={40}
- height={40}
- />
- }
- tooltip={
- <FormattedMessage
- id="actionPanel.showReport"
- defaultMessage="actionPanel.showReport"
- />
- }
- onClick={handleShowReport}
- />
- <Popup
- visible={visible}
- onMaskClick={() => dispatch(setVisible(false))}
- position="right"
- bodyStyle={{ width: '100vw', height: '100vh' }}
- >
- <DiagnosticReport />
- </Popup>
- <EditTaskModal />
- </div>
- );
- };
- export default ActionPanel;
|