index.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import { Col, message, Row, Tooltip } from 'antd';
  2. import { PermissionButton } from '@/components';
  3. import { Body, Guide } from '../components';
  4. import Statistics from '../components/Statistics';
  5. import Steps from '../components/Steps';
  6. import { getMenuPathByCode, MENUS_CODE } from '@/utils/menu';
  7. import { useHistory } from '@/hooks';
  8. import { service } from '..';
  9. import { useEffect, useState } from 'react';
  10. import { QuestionCircleOutlined } from '@ant-design/icons';
  11. import ProductChoose from '../components/ProductChoose';
  12. import DeviceChoose from '../components/DeviceChoose';
  13. const Device = () => {
  14. const productPermission = PermissionButton.usePermission('device/Product').permission;
  15. const devicePermission = PermissionButton.usePermission('device/Instance').permission;
  16. const rulePermission = PermissionButton.usePermission('rule-engine/Instance').permission;
  17. const [productCount, setProductCount] = useState<number>(0);
  18. const [deviceCount, setDeviceCount] = useState<number>(0);
  19. const [productVisible, setProductVisible] = useState<boolean>(false);
  20. const [deviceVisible, setDeviceVisible] = useState<boolean>(false);
  21. const getProductCount = async () => {
  22. const resp = await service.productCount({});
  23. if (resp.status === 200) {
  24. setProductCount(resp.result);
  25. }
  26. };
  27. const getDeviceCount = async () => {
  28. const resp = await service.deviceCount();
  29. if (resp.status === 200) {
  30. setDeviceCount(resp.result);
  31. }
  32. };
  33. useEffect(() => {
  34. getProductCount();
  35. getDeviceCount();
  36. }, []);
  37. const history = useHistory();
  38. // // 跳转
  39. const guideList = [
  40. {
  41. key: 'product',
  42. name: '创建产品',
  43. english: 'STP 1',
  44. auth: !!productPermission.add,
  45. url: 'device/Product',
  46. param: {
  47. save: true,
  48. },
  49. },
  50. {
  51. key: 'device',
  52. name: '创建设备',
  53. english: 'STP 2',
  54. auth: !!devicePermission.add,
  55. url: 'device/Instance',
  56. param: {
  57. save: true,
  58. },
  59. },
  60. {
  61. key: 'rule-engine',
  62. name: '规则引擎',
  63. english: 'STP 3',
  64. auth: !!rulePermission.add,
  65. url: 'rule-engine/Instance',
  66. param: {
  67. save: true,
  68. },
  69. },
  70. ];
  71. return (
  72. <Row gutter={24}>
  73. <Col span={14}>
  74. <Guide
  75. title="物联网引导"
  76. data={guideList}
  77. // jump={(auth: boolean, url: string, param: string) => {
  78. // pageJump(auth, url, param);
  79. // }}
  80. />
  81. </Col>
  82. <Col span={10}>
  83. <Statistics
  84. data={[
  85. {
  86. name: '产品数量',
  87. value: productCount,
  88. children: '',
  89. },
  90. {
  91. name: '设备数量',
  92. value: deviceCount,
  93. children: '',
  94. },
  95. ]}
  96. title="设备统计"
  97. extra={
  98. <div style={{ fontSize: 14, fontWeight: 400 }}>
  99. <a
  100. onClick={() => {
  101. const url = getMenuPathByCode(MENUS_CODE['device/DashBoard']);
  102. if (!!url) {
  103. history.push(`${url}`);
  104. } else {
  105. message.warning('暂无权限,请联系管理员');
  106. }
  107. }}
  108. >
  109. 详情
  110. </a>
  111. </div>
  112. }
  113. />
  114. </Col>
  115. <Col span={24}>
  116. <Body title={'平台架构图'} english={'PLATFORM ARCHITECTURE DIAGRAM'} />
  117. </Col>
  118. <Col span={24}>
  119. <Steps
  120. title={
  121. <span>
  122. 设备接入推荐步骤
  123. <Tooltip title={'不同的设备因为通信协议的不同,存在接入步骤的差异'}>
  124. <QuestionCircleOutlined style={{ paddingLeft: 12 }} />
  125. </Tooltip>
  126. </span>
  127. }
  128. data={[
  129. {
  130. title: '创建产品',
  131. content:
  132. '产品是设备的集合,通常指一组具有相同功能的设备。物联设备必须通过产品进行接入方式配置。',
  133. onClick: () => {
  134. const path = getMenuPathByCode('device/Product');
  135. if (path && !!productPermission.add) {
  136. history.push(`${path}`, {
  137. save: true,
  138. });
  139. } else {
  140. message.warning('暂无权限,请联系管理员');
  141. }
  142. },
  143. },
  144. {
  145. title: '配置产品接入方式',
  146. content:
  147. '通过产品对同一类型的设备进行统一的接入方式配置。请参照设备铭牌说明选择匹配的接入方式。',
  148. onClick: () => {
  149. if (!!productPermission.update) {
  150. setProductVisible(true);
  151. } else {
  152. message.warning('暂无权限,请联系管理员');
  153. }
  154. },
  155. },
  156. {
  157. title: '添加测试设备',
  158. content: '添加单个设备,用于验证产品模型是否配置正确。',
  159. onClick: () => {
  160. const path = getMenuPathByCode('device/Instance');
  161. if (path && !!devicePermission.add) {
  162. history.push(`${path}`, {
  163. save: true,
  164. });
  165. } else {
  166. message.warning('暂无权限,请联系管理员');
  167. }
  168. },
  169. },
  170. {
  171. title: '功能调试',
  172. content: '对添加的测试设备进行功能调试,验证能否连接到平台,设备功能是否配置正确。',
  173. onClick: () => {
  174. if (!!devicePermission.update) {
  175. setDeviceVisible(true);
  176. } else {
  177. message.warning('暂无权限,请联系管理员');
  178. }
  179. },
  180. },
  181. {
  182. title: '批量添加设备',
  183. content: '批量添加同一产品下的设备',
  184. onClick: () => {
  185. const path = getMenuPathByCode('device/Instance');
  186. if (path && !!devicePermission.import) {
  187. history.push(`${path}`, {
  188. import: true,
  189. });
  190. } else {
  191. message.warning('暂无权限,请联系管理员');
  192. }
  193. },
  194. },
  195. ]}
  196. />
  197. </Col>
  198. <ProductChoose
  199. visible={productVisible}
  200. close={() => {
  201. setProductVisible(false);
  202. }}
  203. />
  204. <DeviceChoose
  205. visible={deviceVisible}
  206. onCancel={() => {
  207. setDeviceVisible(false);
  208. }}
  209. />
  210. </Row>
  211. );
  212. };
  213. export default Device;