|
@@ -1,7 +1,12 @@
|
|
|
-import React, { useState, useEffect, useRef } from 'react';
|
|
|
+import React, { useState } from 'react';
|
|
|
import { Space } from 'antd';
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
import { useSelector } from 'react-redux';
|
|
|
+import {
|
|
|
+ DataState,
|
|
|
+ getBtnAvailability,
|
|
|
+ LocationKey,
|
|
|
+} from '@/domain/permissionMap';
|
|
|
import {
|
|
|
AlertOutlined,
|
|
|
AppstoreOutlined,
|
|
@@ -10,15 +15,14 @@ import {
|
|
|
SettingOutlined,
|
|
|
} from '@ant-design/icons';
|
|
|
import MeButton from '../pages/security/components/MeButton';
|
|
|
+import { RootState } from '@/states/store';
|
|
|
|
|
|
interface BusinessZoneProps {
|
|
|
onMenuClick?: (key: string) => void;
|
|
|
}
|
|
|
|
|
|
-const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
- // eslint-disable-next-line
|
|
|
- const currentKey = useSelector((state: any) => state.BusinessFlow.currentKey);
|
|
|
- const items = [
|
|
|
+function useItems(btnAvailability: Record<string, boolean>) {
|
|
|
+ return [
|
|
|
{
|
|
|
key: 'patient_management',
|
|
|
label: (
|
|
@@ -28,9 +32,11 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
/>
|
|
|
),
|
|
|
icon: <MailOutlined />,
|
|
|
+ disabled: !btnAvailability['patient_management'],
|
|
|
children: [
|
|
|
{
|
|
|
key: 'register',
|
|
|
+ disabled: !btnAvailability['register'],
|
|
|
label: (
|
|
|
<FormattedMessage
|
|
|
id="register"
|
|
@@ -40,6 +46,7 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
},
|
|
|
{
|
|
|
key: 'worklist',
|
|
|
+ disabled: !btnAvailability['worklist'],
|
|
|
label: (
|
|
|
<FormattedMessage
|
|
|
id="tasklist"
|
|
@@ -49,6 +56,7 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
},
|
|
|
{
|
|
|
key: 'historylist',
|
|
|
+ disabled: !btnAvailability['historylist'],
|
|
|
label: (
|
|
|
<FormattedMessage
|
|
|
id="historylist"
|
|
@@ -58,6 +66,7 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
},
|
|
|
{
|
|
|
key: 'archivelist',
|
|
|
+ disabled: !btnAvailability['archivelist'],
|
|
|
label: (
|
|
|
<FormattedMessage
|
|
|
id="archivelist"
|
|
@@ -67,6 +76,7 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
},
|
|
|
{
|
|
|
key: 'bin',
|
|
|
+ disabled: !btnAvailability['bin'],
|
|
|
label: (
|
|
|
<FormattedMessage
|
|
|
id="bin"
|
|
@@ -76,6 +86,7 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
},
|
|
|
{
|
|
|
key: 'outputlist',
|
|
|
+ disabled: !btnAvailability['outputlist'],
|
|
|
label: (
|
|
|
<FormattedMessage
|
|
|
id="outputlist"
|
|
@@ -89,9 +100,13 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
key: 'emergency',
|
|
|
icon: <AlertOutlined />,
|
|
|
label: '急诊',
|
|
|
+ disabled: false,
|
|
|
},
|
|
|
{
|
|
|
key: 'exam',
|
|
|
+ disabled:
|
|
|
+ (console.log(`我要看看exam对应的值:${!btnAvailability['exam']}`),
|
|
|
+ !btnAvailability['exam']),
|
|
|
label: (
|
|
|
<FormattedMessage
|
|
|
id="exam"
|
|
@@ -105,6 +120,11 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
},
|
|
|
{
|
|
|
key: 'process',
|
|
|
+ disabled:
|
|
|
+ (console.log(
|
|
|
+ `我要看看[process]对应的值:${!btnAvailability['process']}`
|
|
|
+ ),
|
|
|
+ !btnAvailability['process']),
|
|
|
label: (
|
|
|
<FormattedMessage
|
|
|
id="process"
|
|
@@ -115,6 +135,7 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
},
|
|
|
{
|
|
|
key: 'print',
|
|
|
+ disabled: !btnAvailability['print'],
|
|
|
label: (
|
|
|
<FormattedMessage
|
|
|
id="print"
|
|
@@ -124,36 +145,74 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
icon: <PrinterOutlined />,
|
|
|
},
|
|
|
];
|
|
|
+}
|
|
|
|
|
|
- const [visibleItems, setVisibleItems] = useState(items);
|
|
|
+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);
|
|
|
+ // 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
|
|
|
+ // 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);
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
+ // 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
|
|
|
+ // window.addEventListener('resize', handleResize);
|
|
|
+ // handleResize(); // Initial check
|
|
|
|
|
|
- return () => {
|
|
|
- window.removeEventListener('resize', handleResize);
|
|
|
- };
|
|
|
- }, [items]);
|
|
|
+ // return () => {
|
|
|
+ // window.removeEventListener('resize', handleResize);
|
|
|
+ // };
|
|
|
+ // }, [items]);
|
|
|
|
|
|
const handlePatientManagementClick = () => {
|
|
|
setFloatingMenuVisible(!floatingMenuVisible);
|
|
@@ -166,7 +225,7 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
>
|
|
|
<div className="overflow-y-auto">
|
|
|
<Space direction="vertical">
|
|
|
- {visibleItems.map((item) =>
|
|
|
+ {items.map((item) =>
|
|
|
item.type === 'divider' ? (
|
|
|
<hr
|
|
|
key="divider"
|
|
@@ -193,6 +252,10 @@ const BusinessZone: React.FC<BusinessZoneProps> = ({ onMenuClick }) => {
|
|
|
: () => onMenuClick?.(item.key ?? 'error')
|
|
|
}
|
|
|
username={item.label}
|
|
|
+ disabled={
|
|
|
+ (console.log(`${item.key}=======${item.disabled}`),
|
|
|
+ item.disabled)
|
|
|
+ }
|
|
|
/>
|
|
|
{item.key === 'patient_management' && floatingMenuVisible && (
|
|
|
<Space direction="vertical" style={{ marginLeft: 20 }}>
|