register.selected.view.list.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from 'react';
  2. import { Card, Grid, Button, Row, Flex } from 'antd';
  3. import { CloseOutlined } from '@ant-design/icons';
  4. import { getViewIconUrl } from '@/API/bodyPosition';
  5. import { Image } from 'antd';
  6. import { FormattedMessage } from 'react-intl';
  7. import { useSelector } from 'react-redux';
  8. import type { RootState } from '@/states/store';
  9. import type { View } from '@/states/patient/viewSelection';
  10. const { useBreakpoint } = Grid;
  11. // 卡片尺寸配置
  12. const getCardSize = (screens: ReturnType<typeof useBreakpoint>) => {
  13. if (screens.xl || screens.xxl) {
  14. return { width: 150, height: 100 };
  15. }
  16. if (screens.md || screens.lg) {
  17. return { width: 90, height: 60 };
  18. }
  19. return { width: 60, height: 45 };
  20. };
  21. interface SelectedProtocolListProps {
  22. style?: React.CSSProperties;
  23. className?: string;
  24. }
  25. const SelectedProtocolList: React.FC<SelectedProtocolListProps> = () => {
  26. const screens = useBreakpoint();
  27. const cardSize = getCardSize(screens);
  28. // 从redux获取selectedViews
  29. const selectedViews = useSelector(
  30. (state: RootState) => state.viewSelection.selectedViews
  31. );
  32. // 移除操作(实际项目可用props传递onRemove)
  33. const handleRemove = (id: string) => {
  34. // 这里仅做演示
  35. // 实际应通过props回调或状态管理移除
  36. alert(`移除体位ID: ${id}`);
  37. };
  38. return (
  39. <Row className="h-full overflow-auto">
  40. {selectedViews.map((item: View) => (
  41. <Card
  42. key={item.internal_id}
  43. hoverable
  44. style={{
  45. width: cardSize.width,
  46. height: cardSize.height,
  47. }}
  48. >
  49. <Flex>
  50. <Image
  51. alt="example"
  52. src={getViewIconUrl(item.view_icon_name)}
  53. style={{
  54. width: cardSize.width * 0.6,
  55. height: cardSize.height * 0.5,
  56. objectFit: 'cover',
  57. }}
  58. />
  59. <span>{item.view_name}</span>
  60. </Flex>
  61. <Button
  62. type="text"
  63. size="small"
  64. icon={<CloseOutlined />}
  65. onClick={() => handleRemove(item.internal_id)}
  66. style={{
  67. position: 'absolute',
  68. top: 2,
  69. right: 2,
  70. color: '#999',
  71. }}
  72. aria-label={String(
  73. <FormattedMessage
  74. id="register.selectedProtocol.remove"
  75. defaultMessage="register.selectedProtocol.remove"
  76. />
  77. )}
  78. />
  79. </Card>
  80. ))}
  81. </Row>
  82. );
  83. };
  84. export default SelectedProtocolList;