123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- import React, { useState } from 'react';
- // 直接 import 本地图片(推荐写法)
- import Abdomen from '../assets/imgs/VirtualHuman/Abdomen.png';
- import Abdomen_dow from '../assets/imgs/VirtualHuman/Abdomen_dow.png';
- import LowerLimb_Left from '../assets/imgs/VirtualHuman/LowerLimb_Left.png';
- import LowerLimb_Left_dow from '../assets/imgs/VirtualHuman/LowerLimb_Left_dow.png';
- import LowerLimb_Right from '../assets/imgs/VirtualHuman/LowerLimb_Right.png';
- import LowerLimb_Right_dow from '../assets/imgs/VirtualHuman/LowerLimb_Right_dow.png';
- import Skull from '../assets/imgs/VirtualHuman/Skull.png';
- import Skull_dow from '../assets/imgs/VirtualHuman/Skull_dow.png';
- import Spine from '../assets/imgs/VirtualHuman/Spine.png';
- import Spine_dow from '../assets/imgs/VirtualHuman/Spine_dow.png';
- import Thorax from '../assets/imgs/VirtualHuman/Thorax.png';
- import Thorax_dow from '../assets/imgs/VirtualHuman/Thorax_dow.png';
- import UpperLimb_Left from '../assets/imgs/VirtualHuman/UpperLimb_Left.png';
- import UpperLimb_Left_dow from '../assets/imgs/VirtualHuman/UpperLimb_Left_dow.png';
- import UpperLimb_Right from '../assets/imgs/VirtualHuman/UpperLimb_Right.png';
- import UpperLimb_Right_dow from '../assets/imgs/VirtualHuman/UpperLimb_Right_dow.png';
- import { AppDispatch, RootState } from '@/states/store';
- import { useDispatch, useSelector } from 'react-redux';
- import { fetchViewsOrProtocols } from '@/states/patient/viewSelection';
- import { setCurrentBodyPart } from '@/states/bodyPartSlice';
- // import VirtualHuman from "../assets/imgs/VirtualHuman/VirtualHuman.png";
- // import VirtualHuman_dow from "../assets/imgs/VirtualHuman/VirtualHuman_dow.png";
- // 建立一个映射表,方便统一管理
- // const bodyParts = {
- // Abdomen: { normal: Abdomen, active: Abdomen_dow },
- // LowerLimb_Left: { normal: LowerLimb_Left, active: LowerLimb_Left_dow },
- // LowerLimb_Right: { normal: LowerLimb_Right, active: LowerLimb_Right_dow },
- // Skull: { normal: Skull, active: Skull_dow },
- // Spine: { normal: Spine, active: Spine_dow },
- // Thorax: { normal: Thorax, active: Thorax_dow },
- // UpperLimb_Left: { normal: UpperLimb_Left, active: UpperLimb_Left_dow },
- // UpperLimb_Right: { normal: UpperLimb_Right, active: UpperLimb_Right_dow },
- // //VirtualHuman: { normal: VirtualHuman, active: VirtualHuman_dow },
- // };
- const bodyParts = {
- Skull: {
- normal: Skull,
- active: Skull_dow,
- style: {
- top: '0px',
- left: '110px',
- width: '72px',
- height: '93px',
- zIndex: 2,
- },
- serverName: 'Human_SKULL', //服务端认识的名字
- },
- Thorax: {
- normal: Thorax,
- active: Thorax_dow,
- style: {
- top: '93px',
- left: '88px',
- width: '118px',
- height: '148px',
- zIndex: 1,
- },
- serverName: 'Human_THORAX', //服务端认识的名字
- },
- Abdomen: {
- normal: Abdomen,
- active: Abdomen_dow,
- style: {
- top: '241px',
- left: '81px',
- width: '132px',
- height: '116px',
- zIndex: 1,
- },
- serverName: 'Human_ABDOMEN', //服务端认识的名字
- },
- Spine: {
- normal: Spine,
- active: Spine_dow,
- style: {
- top: '93px',
- left: '128px',
- width: '38px',
- height: '264px',
- zIndex: 1,
- },
- serverName: 'Human_SPINE', //服务端认识的名字
- },
- UpperLimb_Left: {
- normal: UpperLimb_Left,
- active: UpperLimb_Left_dow,
- style: {
- top: '113px',
- left: '0px',
- width: '88px',
- height: '280px',
- zIndex: 1,
- },
- serverName: 'Human_UPPER LIMB', //服务端认识的名字
- },
- UpperLimb_Right: {
- normal: UpperLimb_Right,
- active: UpperLimb_Right_dow,
- style: {
- top: '113px',
- left: '206px',
- width: '88px',
- height: '280px',
- zIndex: 1,
- },
- serverName: 'Human_UPPER LIMB', //服务端认识的名字
- },
- LowerLimb_Left: {
- normal: LowerLimb_Left,
- active: LowerLimb_Left_dow,
- style: {
- top: '357px',
- left: '79px',
- width: '68px',
- height: '337px',
- zIndex: 1,
- },
- serverName: 'Human_LOWER LIMB', //服务端认识的名字
- },
- LowerLimb_Right: {
- normal: LowerLimb_Right,
- active: LowerLimb_Right_dow,
- style: {
- top: '355px',
- left: '148px',
- width: '68px',
- height: '337px',
- zIndex: 1,
- },
- serverName: 'Human_LOWER LIMB', //服务端认识的名字
- },
- };
- export default function HumanBody() {
- const [activePart, setActivePart] = useState(null);
- const dispatch = useDispatch<AppDispatch>();
- const currentPatientType = useSelector(
- (state: RootState) => state.patientType.current
- );
- const bodyPartsState = useSelector(
- (state: RootState) => state.bodyPart.byPatientType
- );
- //选择的是体位还是协议
- const selected = useSelector((state: RootState) => state.selection.selected);
- const handleClick = (part) => {
- setActivePart(part);
- // 映射表。界面上身体部位与服务定义的身体部位有个映射
- // message.info(`你点击了:${part}`);
- const selectedBodyPartId = bodyParts[part].serverName;
- const selectedBodyPart =
- bodyPartsState.find((item) => item.body_part_id == selectedBodyPartId) ||
- null;
- dispatch(setCurrentBodyPart(selectedBodyPart));
- // message.info(`得到对应的身体部位的ID:${selectedBodyPartId}`);
- dispatch(
- fetchViewsOrProtocols({
- selection: selected,
- patientType: currentPatientType?.patient_type_id ?? null,
- bodyPart: selectedBodyPartId ?? null,
- })
- );
- };
- return (
- // <div className="relative w-[300px] h-[600px] mx-auto">
- // {Object.entries(bodyParts).map(([part, images]) => {
- // const isActive = activePart === part;
- // return (
- // <img
- // key={part}
- // src={isActive ? images.active : images.normal}
- // alt={part}
- // onClick={() => handleClick(part)}
- // className="absolute top-0 left-0 w-full h-full cursor-pointer"
- // />
- // );
- // })}
- // </div>
- <div
- className="relative border border-red-500"
- style={{ width: '294px', height: '694px' }}
- >
- {/* <img
- src={VirtualHuman}
- alt="VirtualHuman"
- style={{ position: "absolute", top: 0, left: 0, width: "294px", height: "694px", zIndex: 0 }}
- /> */}
- {Object.entries(bodyParts).map(([part, { normal, active, style }]) => {
- const isActive = activePart === part;
- return (
- <img
- key={part}
- src={isActive ? active : normal}
- alt={part}
- onClick={() => handleClick(part)}
- style={{
- position: 'absolute',
- cursor: 'pointer',
- ...style,
- zIndex: isActive
- ? style.zIndex
- ? style.zIndex + 1
- : 1
- : style.zIndex,
- }}
- />
- );
- })}
- </div>
- );
- }
|