123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- import React, { useState } from 'react';
- import { Flex } from 'antd';
- import { FormattedMessage } from 'react-intl';
- import { useSelector } from 'react-redux';
- import {
- DataState,
- getBtnAvailability,
- LocationKey,
- } from '@/domain/permissionMap';
- import { RootState } from '@/states/store';
- import { IconButton } from '@/components/IconButton';
- import Icon from '@/components/Icon';
- interface BusinessZoneProps {
- onMenuClick?: (key: string) => void;
- }
- function useItems(btnAvailability: Record<string, boolean>) {
- return [
- {
- key: 'patient_management',
- label: (
- <FormattedMessage
- id="patient"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- icon: 'Registration',
- disabled: !btnAvailability['patient_management'],
- children: [
- {
- key: 'register',
- disabled: !btnAvailability['register'],
- label: (
- <FormattedMessage
- id="register"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- icon: 'Registration',
- },
- {
- key: 'worklist',
- disabled: !btnAvailability['worklist'],
- label: (
- <FormattedMessage
- id="tasklist"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- icon: 'Worklist',
- },
- {
- key: 'historylist',
- disabled: !btnAvailability['historylist'],
- label: (
- <FormattedMessage
- id="historylist"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- icon: 'Registration',
- },
- {
- key: 'archivelist',
- disabled: !btnAvailability['archivelist'],
- label: (
- <FormattedMessage
- id="archivelist"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- icon: 'Registration',
- },
- {
- key: 'bin',
- disabled: !btnAvailability['bin'],
- label: (
- <FormattedMessage
- id="bin"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- },
- {
- key: 'outputlist',
- disabled: !btnAvailability['outputlist'],
- label: (
- <FormattedMessage
- id="outputlist"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- icon: 'Registration',
- },
- ],
- },
- // {
- // key: 'emergency',
- // icon: 'Emergency',
- // label: '急诊',
- // disabled: false,
- // },
- {
- key: 'exam',
- disabled:
- (console.log(`我要看看exam对应的值:${!btnAvailability['exam']}`),
- !btnAvailability['exam']),
- label: (
- <FormattedMessage
- id="exam"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- icon: 'Exam',
- },
- {
- type: 'divider',
- },
- {
- key: 'process',
- disabled:
- (console.log(
- `我要看看[process]对应的值:${!btnAvailability['process']}`
- ),
- !btnAvailability['process']),
- label: (
- <FormattedMessage
- id="process"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- icon: 'Process',
- },
- {
- key: 'print',
- disabled: !btnAvailability['print'],
- label: (
- <FormattedMessage
- id="print"
- defaultMessage={'语言包中没有定义patient的翻译文本'}
- />
- ),
- icon: 'Output',
- },
- ];
- }
- const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
- // eslint-disable-next-line
- const currentKey = useSelector((state: RootState) => state.BusinessFlow.currentKey);
- console.log('Current Business Flow Key:', currentKey);
- const dataState: DataState = useSelector((state: RootState) => {
- if (currentKey === 'worklist') {
- return {
- hasSelection: state.workSelection.selectedIds.length > 0,
- hasExposedImage:
- state.bodyPositionList.exposureStatus === 'Half Exposed' ||
- state.bodyPositionList.exposureStatus === 'Fully Exposed',
- };
- } else if (currentKey === 'historylist') {
- return {
- hasSelection: state.historySelection.selectedIds.length > 0,
- hasExposedImage:
- state.bodyPositionList.exposureStatus === 'Half Exposed' ||
- state.bodyPositionList.exposureStatus === 'Fully Exposed',
- };
- } else if (currentKey === 'exam') {
- return {
- // hasSelection: state.historySelection.selectedIds.length > 0,
- hasExposedImage:
- state.bodyPositionList.exposureStatus === 'Half Exposed' ||
- state.bodyPositionList.exposureStatus === 'Fully Exposed',
- };
- } else {
- return {};
- }
- });
- const btnAvailability = getBtnAvailability(
- currentKey as LocationKey,
- dataState
- );
- console.log('Button Availability:', btnAvailability);
- const items = useItems(btnAvailability);
- // const [visibleItems, setVisibleItems] = useState(items);
- const [floatingMenuVisible, setFloatingMenuVisible] = useState(false);
- // const businessZoneRef = useRef<HTMLDivElement>(null);
- // useEffect(() => {
- // const handleResize = () => {
- // if (businessZoneRef.current) {
- // const businessZoneHeight = businessZoneRef.current.offsetHeight;
- // const windowHeight = window.innerHeight;
- // const systemZoneHeight = 100; // Assuming SystemZone height is fixed
- // if (businessZoneHeight + systemZoneHeight > windowHeight) {
- // const visibleCount = Math.floor(
- // (windowHeight - systemZoneHeight) / 50
- // ); // Assuming each button height is 50px
- // setVisibleItems(items.slice(0, visibleCount));
- // } else {
- // setVisibleItems(items);
- // }
- // }
- // };
- // window.addEventListener('resize', handleResize);
- // handleResize(); // Initial check
- // return () => {
- // window.removeEventListener('resize', handleResize);
- // };
- // }, [items]);
- const handlePatientManagementClick = () => {
- setFloatingMenuVisible(!floatingMenuVisible);
- };
- const buttonClassNameGenerator = (
- itemkey: string,
- currentkey: string
- ): string => {
- const originalName =
- 'w-full max-w-full whitespace-nowrap overflow-hidden text-ellipsis min-w-0 truncate';
- if (itemkey === currentkey) {
- return originalName + ' border border-red-500 ';
- }
- return originalName;
- };
- useSelector((state: RootState) => state.permission.triggerPermissionCalc);
- return (
- // <div
- // className="grid grid-rows-[1fr] flex-grow h-0 overflow-y-auto"
- // >
- <Flex vertical className=" min-h-0 overflow-y-auto flex-grow px-1">
- {items.map((item) =>
- item.type === 'divider' ? (
- <hr
- key="divider"
- style={{
- width: '100%',
- borderTop: '1px solid #f0f0f0',
- margin: '8px 0',
- }}
- />
- ) : (
- <>
- <IconButton
- data-testid={item.key}
- onClick={
- item.key === 'patient_management'
- ? handlePatientManagementClick
- : () => onMenuClick?.(item.key ?? 'error')
- }
- iconSize={56}
- iconPlace="left"
- icon={
- <Icon
- module="module-common"
- name={item.icon ?? ''}
- userId="user-A"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- style={{
- //flex: 1,
- minWidth: 0,
- overflow: 'hidden', // 超出隐藏
- textOverflow: 'ellipsis', // 超出用省略号
- whiteSpace: 'nowrap', // 不换行
- padding: '0px',
- minHeight: '1.5rem',
- }}
- className={buttonClassNameGenerator(
- item.key as string,
- currentKey
- )}
- disabled={item.disabled}
- >
- <span
- style={{
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- whiteSpace: 'nowrap',
- display: 'block', // 或 inline-block
- flex: 1, // 占据剩余空间并允许收缩
- minWidth: 0, // 再次确保可以收缩
- }}
- >
- {item.label}
- </span>
- </IconButton>
- {item.key === 'patient_management' && floatingMenuVisible && (
- <Flex vertical className="px-1">
- {item.children?.map((child) => (
- <IconButton
- data-testid={child.key}
- iconSize={56}
- icon={
- <Icon
- module="module-common"
- name={item.icon ?? ''}
- userId="user-A"
- theme="default"
- size="2x"
- state="normal"
- />
- }
- key={child.key}
- onClick={() => onMenuClick?.(child.key)}
- className={buttonClassNameGenerator(
- item.key as string,
- currentKey
- )}
- style={{
- //flex: 1,
- minWidth: 0,
- overflow: 'hidden', // 超出隐藏
- textOverflow: 'ellipsis', // 超出用省略号
- whiteSpace: 'nowrap', // 不换行
- padding: '0px',
- }}
- disabled={item.disabled}
- >
- <span
- style={{
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- whiteSpace: 'nowrap',
- display: 'block', // 或 inline-block
- flex: 1, // 占据剩余空间并允许收缩
- minWidth: 0, // 再次确保可以收缩
- }}
- >
- {child.label}
- </span>
- </IconButton>
- ))}
- </Flex>
- )}
- </>
- )
- )}
- </Flex>
- // </div>
- );
- };
- export default BusinessZone;
|