SystemZone.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import React, { forwardRef, useState } from 'react';
  2. import { Space, Row } from 'antd';
  3. import MeButton from '../pages/security/components/MeButton';
  4. import { useSelector } from 'react-redux';
  5. import { RootState } from '@/states/store';
  6. import { isLoggedIn } from '../states/user_info';
  7. import Icon from '@/components/Icon';
  8. import { IconButton } from '@/components/IconButton';
  9. import ExitModal from '@/components/ExitModal';
  10. import LanguageSettingModal from '@/components/LanguageSettingModal';
  11. import { showNotImplemented } from '@/utils/notificationHelper';
  12. import { FormattedMessage } from 'react-intl';
  13. import { UserOutlined } from '@ant-design/icons';
  14. interface SystemZoneProps {
  15. onMenuClick?: (key: string) => void;
  16. }
  17. const SystemZone = forwardRef<HTMLDivElement, SystemZoneProps>(
  18. // eslint-disable-next-line
  19. ({ onMenuClick }, ref) => {
  20. const login = useSelector((state: RootState) => isLoggedIn(state.userInfo));
  21. const username = useSelector((state: RootState) => state.userInfo.name);
  22. const avatarUrl = useSelector((state: RootState) => state.userInfo.avatar);
  23. // 退出弹框状态管理
  24. const [exitModalVisible, setExitModalVisible] = useState(false);
  25. // 语言设置弹框状态管理
  26. const [languageModalVisible, setLanguageModalVisible] = useState(false);
  27. const handleExitClick = (): void => {
  28. setExitModalVisible(true);
  29. };
  30. const handleExitModalClose = (): void => {
  31. setExitModalVisible(false);
  32. };
  33. const handleLanguageClick = (): void => {
  34. setLanguageModalVisible(true);
  35. };
  36. const handleLanguageModalClose = (): void => {
  37. setLanguageModalVisible(false);
  38. };
  39. return (
  40. <Row
  41. ref={ref}
  42. style={{
  43. position: 'sticky',
  44. flex: '0 0 auto',
  45. bottom: 0,
  46. left: 0,
  47. width: '100%',
  48. justifyContent: 'center',
  49. padding: '16px 0',
  50. boxShadow: '0 -2px 5px rgba(0,0,0,0.1)',
  51. }}
  52. >
  53. <style>{`
  54. .system-zone-space .ant-space-item {
  55. width: 100%;
  56. }
  57. `}</style>
  58. <Space
  59. direction="vertical"
  60. align="start"
  61. style={{ width: '100%', paddingLeft: 20 }}
  62. className='system-zone-space'
  63. >
  64. <IconButton
  65. icon={
  66. <Icon
  67. module="module-common"
  68. name="btn_3DCam_AIView"
  69. userId="user-A" // 会优先查 custom/user-A/... 再回退到 base
  70. theme="default"
  71. size="2x"
  72. state="normal"
  73. //widthPx={32}// 和size 2x 保持一致
  74. />
  75. }
  76. iconPlace="left"
  77. iconSize={32} // 和size 2x 保持一致
  78. type="primary"
  79. block
  80. style={{ padding: '4px 16px' }}
  81. onClick={handleLanguageClick}
  82. >
  83. <FormattedMessage
  84. id="nav.config"
  85. defaultMessage={'nav.config'}
  86. />
  87. </IconButton>
  88. <IconButton
  89. icon={
  90. login ? (
  91. avatarUrl ? (
  92. <Icon
  93. module="module-common"
  94. name="btn_3DCam_AIView"
  95. userId="user-A"
  96. theme="default"
  97. size="2x"
  98. state="normal"
  99. url={avatarUrl}
  100. />
  101. ) : (
  102. <Icon
  103. module="module-security"
  104. name="user-not-login"
  105. userId="user-A"
  106. theme="default"
  107. size="2x"
  108. state="normal"
  109. />
  110. )
  111. ) : (
  112. <Icon
  113. module="module-common"
  114. name="user-not-login"
  115. userId="user-A"
  116. theme="default"
  117. size="2x"
  118. state="normal"
  119. />
  120. )
  121. }
  122. iconPlace="left"
  123. iconSize={32}
  124. type="primary"
  125. block
  126. style={{ padding: '4px 16px' }}
  127. onClick={() => showNotImplemented('我的')}
  128. >
  129. {login ? username : '未登录'}
  130. </IconButton>
  131. <IconButton
  132. data-testid="exit-button"
  133. icon={
  134. <Icon
  135. module="module-common"
  136. name="btn_3DCam_AIView"
  137. userId="user-A"
  138. theme="default"
  139. size="2x"
  140. state="normal"
  141. />
  142. }
  143. iconPlace="left"
  144. iconSize={32}
  145. type="primary"
  146. block
  147. style={{ padding: '4px 16px' }}
  148. onClick={handleExitClick}
  149. >
  150. <FormattedMessage
  151. id="nav.logout"
  152. defaultMessage={'nav.logout'}
  153. />
  154. </IconButton>
  155. </Space>
  156. {/* 退出选择弹框 */}
  157. <ExitModal visible={exitModalVisible} onClose={handleExitModalClose} />
  158. {/* 语言设置弹框 */}
  159. <LanguageSettingModal
  160. visible={languageModalVisible}
  161. onClose={handleLanguageModalClose}
  162. />
  163. </Row>
  164. );
  165. }
  166. );
  167. export default SystemZone;