index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. import { PermissionButton } from '@/components';
  2. import useHistory from '@/hooks/route/useHistory';
  3. import { getMenuPathByCode, MENUS_CODE } from '@/utils/menu';
  4. import { Col, message, Row, Tooltip } from 'antd';
  5. import Body from '../components/Body';
  6. import Guide from '../components/Guide';
  7. import Statistics from '../components/Statistics';
  8. import Steps from '../components/Steps';
  9. import { service } from '..';
  10. import { useEffect, useState } from 'react';
  11. import useSendWebsocketMessage from '@/hooks/websocket/useSendWebsocketMessage';
  12. import { map } from 'rxjs';
  13. import Pie from '../components/Pie';
  14. import { QuestionCircleOutlined } from '@ant-design/icons';
  15. import ProductChoose from '../components/ProductChoose';
  16. import DeviceChoose from '../components/DeviceChoose';
  17. const Comprehensive = () => {
  18. const [subscribeTopic] = useSendWebsocketMessage();
  19. const productPermission = PermissionButton.usePermission('device/Product').permission;
  20. const devicePermission = PermissionButton.usePermission('device/Instance').permission;
  21. const rulePermission = PermissionButton.usePermission('rule-engine/Instance').permission;
  22. const accessPermission = getMenuPathByCode(MENUS_CODE['link/AccessConfig']);
  23. const logPermission = getMenuPathByCode(MENUS_CODE['Log']);
  24. const linkPermission = getMenuPathByCode(MENUS_CODE['link/DashBoard']);
  25. const [productCount, setProductCount] = useState<number>(0);
  26. const [deviceCount, setDeviceCount] = useState<number>(0);
  27. const [cpuValue, setCpuValue] = useState<number>(0);
  28. const [jvmValue, setJvmValue] = useState<number>(0);
  29. const [productVisible, setProductVisible] = useState<boolean>(false);
  30. const [deviceVisible, setDeviceVisible] = useState<boolean>(false);
  31. const getProductCount = async () => {
  32. const resp = await service.productCount({});
  33. if (resp.status === 200) {
  34. setProductCount(resp.result);
  35. }
  36. };
  37. const getDeviceCount = async () => {
  38. const resp = await service.deviceCount();
  39. if (resp.status === 200) {
  40. setDeviceCount(resp.result);
  41. }
  42. };
  43. useEffect(() => {
  44. getProductCount();
  45. getDeviceCount();
  46. }, []);
  47. useEffect(() => {
  48. const cpuRealTime = subscribeTopic!(
  49. `operations-statistics-system-info-cpu-realTime`,
  50. `/dashboard/systemMonitor/stats/info/realTime`,
  51. {
  52. type: 'cpu',
  53. interval: '2s',
  54. agg: 'avg',
  55. },
  56. )
  57. ?.pipe(map((res) => res.payload))
  58. .subscribe((payload: any) => {
  59. setCpuValue(payload.value?.systemUsage || 0);
  60. });
  61. const jvmRealTime = subscribeTopic!(
  62. `operations-statistics-system-info-memory-realTime`,
  63. `/dashboard/systemMonitor/stats/info/realTime`,
  64. {
  65. type: 'memory',
  66. interval: '2s',
  67. agg: 'avg',
  68. },
  69. )
  70. ?.pipe(map((res) => res.payload))
  71. .subscribe((payload: any) => {
  72. setJvmValue(payload.value?.jvmHeapUsage || 0);
  73. });
  74. return () => {
  75. cpuRealTime?.unsubscribe();
  76. jvmRealTime?.unsubscribe();
  77. };
  78. }, []);
  79. const history = useHistory();
  80. // // 跳转
  81. const guideList = [
  82. {
  83. key: 'product',
  84. name: '创建产品',
  85. english: 'CREATE PRODUCT',
  86. auth: !!productPermission.add,
  87. url: 'device/Product',
  88. param: {
  89. save: true,
  90. },
  91. },
  92. {
  93. key: 'device',
  94. name: '创建设备',
  95. english: 'CREATE DEVICE',
  96. auth: !!devicePermission.add,
  97. url: 'device/Instance',
  98. param: {
  99. save: true,
  100. },
  101. },
  102. {
  103. key: 'rule-engine',
  104. name: '规则引擎',
  105. english: 'RULE ENGINE',
  106. auth: !!rulePermission.add,
  107. url: 'rule-engine/Instance',
  108. param: {
  109. save: true,
  110. },
  111. },
  112. ];
  113. const guideOpsList = [
  114. {
  115. key: 'access',
  116. name: '设备接入配置',
  117. english: 'DEVICE ACCESS CONFIGURATION',
  118. auth: !!accessPermission,
  119. url: 'link/AccessConfig',
  120. },
  121. {
  122. key: 'logger',
  123. name: '日志排查',
  124. english: 'LOG SCREEN',
  125. auth: !!logPermission,
  126. url: 'Log',
  127. param: {
  128. key: 'system',
  129. },
  130. },
  131. {
  132. key: 'realtime',
  133. name: '实时监控',
  134. english: 'REAL-TIME MONITORING',
  135. auth: !!linkPermission,
  136. url: 'link/DashBoard',
  137. param: {
  138. save: true,
  139. },
  140. },
  141. ];
  142. return (
  143. <Row gutter={24}>
  144. <Col span={14}>
  145. <Guide title="物联网引导" data={guideList} />
  146. </Col>
  147. <Col span={10}>
  148. <Statistics
  149. data={[
  150. {
  151. name: '产品数量',
  152. value: productCount,
  153. children: '',
  154. },
  155. {
  156. name: '设备数量',
  157. value: deviceCount,
  158. children: '',
  159. },
  160. ]}
  161. title="设备统计"
  162. extra={
  163. <div style={{ fontSize: 14, fontWeight: 400 }}>
  164. <a
  165. onClick={() => {
  166. const url = getMenuPathByCode(MENUS_CODE['device/DashBoard']);
  167. if (!!url) {
  168. history.push(`${url}`);
  169. } else {
  170. message.warning('暂无权限,请联系管理员');
  171. }
  172. }}
  173. >
  174. 详情
  175. </a>
  176. </div>
  177. }
  178. />
  179. </Col>
  180. <Col span={14}>
  181. <Guide title="运维引导" data={guideOpsList} />
  182. </Col>
  183. <Col span={10}>
  184. <Statistics
  185. data={[
  186. {
  187. name: 'CPU使用率',
  188. value: String(cpuValue) + '%',
  189. children: <Pie value={cpuValue} />,
  190. },
  191. {
  192. name: 'JVM内存',
  193. value: String(jvmValue) + '%',
  194. children: <Pie value={jvmValue} />,
  195. },
  196. ]}
  197. title="基础统计"
  198. extra={
  199. <div style={{ fontSize: 14, fontWeight: 400 }}>
  200. <a
  201. onClick={() => {
  202. const url = getMenuPathByCode(MENUS_CODE['link/DashBoard']);
  203. if (!!url) {
  204. history.push(`${url}`);
  205. } else {
  206. message.warning('暂无权限,请联系管理员');
  207. }
  208. }}
  209. >
  210. 详情
  211. </a>
  212. </div>
  213. }
  214. />
  215. </Col>
  216. <Col span={24}>
  217. <Body title={'平台架构图'} english={'PLATFORM ARCHITECTURE DIAGRAM'} />
  218. </Col>
  219. <Col span={24}>
  220. <Steps
  221. title={
  222. <span>
  223. 设备接入推荐步骤
  224. <Tooltip title={'不同的设备因为通信协议的不用,存在接入步骤的差异'}>
  225. <QuestionCircleOutlined style={{ paddingLeft: 12 }} />
  226. </Tooltip>
  227. </span>
  228. }
  229. data={[
  230. {
  231. title: '创建产品',
  232. content:
  233. '产品是设备的集合,通常指一组具有相同功能的设备。物联设备必须通过产品进行接入方式配置。',
  234. onClick: () => {
  235. const path = getMenuPathByCode('device/Product');
  236. if (path && !!productPermission.add) {
  237. history.push(`${path}`, {
  238. save: true,
  239. });
  240. } else {
  241. message.warning('暂无权限,请联系管理员');
  242. }
  243. },
  244. },
  245. {
  246. title: '配置产品接入方式',
  247. content:
  248. '通过产品对同一类型的所有设备进行统一的接入方式配置。请参照设备铭牌说明选择匹配的接入方式。',
  249. onClick: () => {
  250. setProductVisible(true);
  251. },
  252. },
  253. {
  254. title: '添加测试设备',
  255. content: '添加单个设备,用于验证产品模型是否配置正确。',
  256. onClick: () => {
  257. const path = getMenuPathByCode('device/Instance');
  258. if (path && !!devicePermission.add) {
  259. history.push(`${path}`, {
  260. save: true,
  261. });
  262. } else {
  263. message.warning('暂无权限,请联系管理员');
  264. }
  265. },
  266. },
  267. {
  268. title: '功能调试',
  269. content: '对添加的测试设备进行功能调试,验证能否连接到平台,设备功能是否配置正确。',
  270. onClick: () => {
  271. setDeviceVisible(true);
  272. },
  273. },
  274. {
  275. title: '批量添加设备',
  276. content: '批量添加同一产品下的设备',
  277. onClick: () => {
  278. const path = getMenuPathByCode('device/Instance');
  279. if (path && !!devicePermission.import) {
  280. history.push(`${path}`, {
  281. import: true,
  282. });
  283. } else {
  284. message.warning('暂无权限,请联系管理员');
  285. }
  286. },
  287. },
  288. ]}
  289. />
  290. </Col>
  291. <Col span={24} style={{ marginTop: 24 }}>
  292. <Steps
  293. title={
  294. <span>
  295. 运维管理推荐步骤
  296. <Tooltip title="请根据业务需要对下述步骤进行选择性操作。">
  297. <QuestionCircleOutlined style={{ paddingLeft: 12 }} />
  298. </Tooltip>
  299. </span>
  300. }
  301. data={[
  302. {
  303. title: '协议管理',
  304. content: '根据业务需求自定义开发对应的产品(设备模型)接入协议,并上传到平台。',
  305. url: require('/public/images/home/bottom-1.png'),
  306. onClick: () => {
  307. const url = getMenuPathByCode(MENUS_CODE['link/Protocol']);
  308. if (!!url) {
  309. history.push(url);
  310. } else {
  311. message.warning('暂无权限,请联系管理员');
  312. }
  313. },
  314. },
  315. {
  316. title: '证书管理',
  317. content: '统一维护平台内的证书,用于数据通信加密。',
  318. url: require('/public/images/home/bottom-6.png'),
  319. onClick: () => {
  320. const url = getMenuPathByCode(MENUS_CODE['link/Certificate']);
  321. if (!!url) {
  322. history.push(url);
  323. } else {
  324. message.warning('暂无权限,请联系管理员');
  325. }
  326. },
  327. },
  328. {
  329. title: '网络组件',
  330. content: '根据不同的传输类型配置平台底层网络组件相关参数。',
  331. url: require('/public/images/home/bottom-3.png'),
  332. onClick: () => {
  333. const url = getMenuPathByCode(MENUS_CODE['link/Type']);
  334. if (!!url) {
  335. history.push(url);
  336. } else {
  337. message.warning('暂无权限,请联系管理员');
  338. }
  339. },
  340. },
  341. {
  342. title: '设备接入网关',
  343. content: '根据不同的传输类型,关联消息协议,配置设备接入网关相关参数。',
  344. url: require('/public/images/home/bottom-4.png'),
  345. onClick: () => {
  346. const url = getMenuPathByCode(MENUS_CODE['link/Gateway']);
  347. if (!!url) {
  348. history.push(url);
  349. } else {
  350. message.warning('暂无权限,请联系管理员');
  351. }
  352. },
  353. },
  354. {
  355. title: '日志管理',
  356. content: '监控系统日志,及时处理系统异常。',
  357. url: require('/public/images/home/bottom-5.png'),
  358. onClick: () => {
  359. const url = getMenuPathByCode(MENUS_CODE['Log']);
  360. if (!!url) {
  361. history.push(url);
  362. } else {
  363. message.warning('暂无权限,请联系管理员');
  364. }
  365. },
  366. },
  367. ]}
  368. />
  369. </Col>
  370. <ProductChoose
  371. visible={productVisible}
  372. close={() => {
  373. setProductVisible(false);
  374. }}
  375. />
  376. <DeviceChoose
  377. visible={deviceVisible}
  378. onCancel={() => {
  379. setDeviceVisible(false);
  380. }}
  381. />
  382. </Row>
  383. );
  384. };
  385. export default Comprehensive;