HumanBody.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React, { useState } from 'react';
  2. // 直接 import 本地图片(推荐写法)
  3. import Abdomen from '../assets/imgs/VirtualHuman/Abdomen.png';
  4. import Abdomen_dow from '../assets/imgs/VirtualHuman/Abdomen_dow.png';
  5. import LowerLimb_Left from '../assets/imgs/VirtualHuman/LowerLimb_Left.png';
  6. import LowerLimb_Left_dow from '../assets/imgs/VirtualHuman/LowerLimb_Left_dow.png';
  7. import LowerLimb_Right from '../assets/imgs/VirtualHuman/LowerLimb_Right.png';
  8. import LowerLimb_Right_dow from '../assets/imgs/VirtualHuman/LowerLimb_Right_dow.png';
  9. import Skull from '../assets/imgs/VirtualHuman/Skull.png';
  10. import Skull_dow from '../assets/imgs/VirtualHuman/Skull_dow.png';
  11. import Spine from '../assets/imgs/VirtualHuman/Spine.png';
  12. import Spine_dow from '../assets/imgs/VirtualHuman/Spine_dow.png';
  13. import Thorax from '../assets/imgs/VirtualHuman/Thorax.png';
  14. import Thorax_dow from '../assets/imgs/VirtualHuman/Thorax_dow.png';
  15. import UpperLimb_Left from '../assets/imgs/VirtualHuman/UpperLimb_Left.png';
  16. import UpperLimb_Left_dow from '../assets/imgs/VirtualHuman/UpperLimb_Left_dow.png';
  17. import UpperLimb_Right from '../assets/imgs/VirtualHuman/UpperLimb_Right.png';
  18. import UpperLimb_Right_dow from '../assets/imgs/VirtualHuman/UpperLimb_Right_dow.png';
  19. import { AppDispatch, RootState } from '@/states/store';
  20. import { useDispatch, useSelector } from 'react-redux';
  21. import { fetchViewsOrProtocols } from '@/states/patient/viewSelection';
  22. import { setCurrentBodyPart } from '@/states/bodyPartSlice';
  23. // import VirtualHuman from "../assets/imgs/VirtualHuman/VirtualHuman.png";
  24. // import VirtualHuman_dow from "../assets/imgs/VirtualHuman/VirtualHuman_dow.png";
  25. // 建立一个映射表,方便统一管理
  26. // const bodyParts = {
  27. // Abdomen: { normal: Abdomen, active: Abdomen_dow },
  28. // LowerLimb_Left: { normal: LowerLimb_Left, active: LowerLimb_Left_dow },
  29. // LowerLimb_Right: { normal: LowerLimb_Right, active: LowerLimb_Right_dow },
  30. // Skull: { normal: Skull, active: Skull_dow },
  31. // Spine: { normal: Spine, active: Spine_dow },
  32. // Thorax: { normal: Thorax, active: Thorax_dow },
  33. // UpperLimb_Left: { normal: UpperLimb_Left, active: UpperLimb_Left_dow },
  34. // UpperLimb_Right: { normal: UpperLimb_Right, active: UpperLimb_Right_dow },
  35. // //VirtualHuman: { normal: VirtualHuman, active: VirtualHuman_dow },
  36. // };
  37. const bodyParts = {
  38. Skull: {
  39. normal: Skull,
  40. active: Skull_dow,
  41. style: {
  42. top: '0px',
  43. left: '110px',
  44. width: '72px',
  45. height: '93px',
  46. zIndex: 2,
  47. },
  48. serverName: 'Human_SKULL', //服务端认识的名字
  49. },
  50. Thorax: {
  51. normal: Thorax,
  52. active: Thorax_dow,
  53. style: {
  54. top: '93px',
  55. left: '88px',
  56. width: '118px',
  57. height: '148px',
  58. zIndex: 1,
  59. },
  60. serverName: 'Human_THORAX', //服务端认识的名字
  61. },
  62. Abdomen: {
  63. normal: Abdomen,
  64. active: Abdomen_dow,
  65. style: {
  66. top: '241px',
  67. left: '81px',
  68. width: '132px',
  69. height: '116px',
  70. zIndex: 1,
  71. },
  72. serverName: 'Human_ABDOMEN', //服务端认识的名字
  73. },
  74. Spine: {
  75. normal: Spine,
  76. active: Spine_dow,
  77. style: {
  78. top: '93px',
  79. left: '128px',
  80. width: '38px',
  81. height: '264px',
  82. zIndex: 1,
  83. },
  84. serverName: 'Human_SPINE', //服务端认识的名字
  85. },
  86. UpperLimb_Left: {
  87. normal: UpperLimb_Left,
  88. active: UpperLimb_Left_dow,
  89. style: {
  90. top: '113px',
  91. left: '0px',
  92. width: '88px',
  93. height: '280px',
  94. zIndex: 1,
  95. },
  96. serverName: 'Human_UPPER LIMB', //服务端认识的名字
  97. },
  98. UpperLimb_Right: {
  99. normal: UpperLimb_Right,
  100. active: UpperLimb_Right_dow,
  101. style: {
  102. top: '113px',
  103. left: '206px',
  104. width: '88px',
  105. height: '280px',
  106. zIndex: 1,
  107. },
  108. serverName: 'Human_UPPER LIMB', //服务端认识的名字
  109. },
  110. LowerLimb_Left: {
  111. normal: LowerLimb_Left,
  112. active: LowerLimb_Left_dow,
  113. style: {
  114. top: '357px',
  115. left: '79px',
  116. width: '68px',
  117. height: '337px',
  118. zIndex: 1,
  119. },
  120. serverName: 'Human_LOWER LIMB', //服务端认识的名字
  121. },
  122. LowerLimb_Right: {
  123. normal: LowerLimb_Right,
  124. active: LowerLimb_Right_dow,
  125. style: {
  126. top: '355px',
  127. left: '148px',
  128. width: '68px',
  129. height: '337px',
  130. zIndex: 1,
  131. },
  132. serverName: 'Human_LOWER LIMB', //服务端认识的名字
  133. },
  134. };
  135. export default function HumanBody() {
  136. const [activePart, setActivePart] = useState(null);
  137. const dispatch = useDispatch<AppDispatch>();
  138. const currentPatientType = useSelector(
  139. (state: RootState) => state.patientType.current
  140. );
  141. const bodyPartsState = useSelector(
  142. (state: RootState) => state.bodyPart.byPatientType
  143. );
  144. //选择的是体位还是协议
  145. const selected = useSelector((state: RootState) => state.selection.selected);
  146. const handleClick = (part) => {
  147. setActivePart(part);
  148. // 映射表。界面上身体部位与服务定义的身体部位有个映射
  149. // message.info(`你点击了:${part}`);
  150. const selectedBodyPartId = bodyParts[part].serverName;
  151. const selectedBodyPart =
  152. bodyPartsState.find((item) => item.body_part_id == selectedBodyPartId) ||
  153. null;
  154. dispatch(setCurrentBodyPart(selectedBodyPart));
  155. // message.info(`得到对应的身体部位的ID:${selectedBodyPartId}`);
  156. dispatch(
  157. fetchViewsOrProtocols({
  158. selection: selected,
  159. patientType: currentPatientType?.patient_type_id ?? null,
  160. bodyPart: selectedBodyPartId ?? null,
  161. })
  162. );
  163. };
  164. return (
  165. // <div className="relative w-[300px] h-[600px] mx-auto">
  166. // {Object.entries(bodyParts).map(([part, images]) => {
  167. // const isActive = activePart === part;
  168. // return (
  169. // <img
  170. // key={part}
  171. // src={isActive ? images.active : images.normal}
  172. // alt={part}
  173. // onClick={() => handleClick(part)}
  174. // className="absolute top-0 left-0 w-full h-full cursor-pointer"
  175. // />
  176. // );
  177. // })}
  178. // </div>
  179. <div
  180. className="relative border border-red-500"
  181. style={{ width: '294px', height: '694px' }}
  182. >
  183. {/* <img
  184. src={VirtualHuman}
  185. alt="VirtualHuman"
  186. style={{ position: "absolute", top: 0, left: 0, width: "294px", height: "694px", zIndex: 0 }}
  187. /> */}
  188. {Object.entries(bodyParts).map(([part, { normal, active, style }]) => {
  189. const isActive = activePart === part;
  190. return (
  191. <img
  192. key={part}
  193. src={isActive ? active : normal}
  194. alt={part}
  195. onClick={() => handleClick(part)}
  196. style={{
  197. position: 'absolute',
  198. cursor: 'pointer',
  199. ...style,
  200. zIndex: isActive
  201. ? style.zIndex
  202. ? style.zIndex + 1
  203. : 1
  204. : style.zIndex,
  205. }}
  206. />
  207. );
  208. })}
  209. </div>
  210. );
  211. }