index.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import ProTable, { ActionType, ProColumns } from '@jetlinks/pro-table';
  3. import { Badge, Card, Col, Row } from 'antd';
  4. import styles from './index.less';
  5. import { PermissionButton } from '@/components';
  6. import { history, useIntl } from 'umi';
  7. import {
  8. ControlOutlined,
  9. DeleteOutlined,
  10. EditOutlined,
  11. PlayCircleOutlined,
  12. PlusOutlined,
  13. StopOutlined,
  14. } from '@ant-design/icons';
  15. import { useRef, useState } from 'react';
  16. import SearchComponent from '@/components/SearchComponent';
  17. import Service from './service';
  18. import Save from './Save';
  19. import { getMenuPathByCode } from '@/utils/menu';
  20. import { useDomFullHeight } from '@/hooks';
  21. import { onlyMessage } from '@/utils/util';
  22. // import NewModbus from '../new'
  23. export const service = new Service('modbus/master');
  24. const Modbus = () => {
  25. const intl = useIntl();
  26. const actionRef = useRef<ActionType>();
  27. const [param, setParam] = useState({});
  28. const { permission } = PermissionButton.usePermission('link/Channel/Modbus');
  29. const [visible, setVisible] = useState<boolean>(false);
  30. const [current, setCurrent] = useState<Partial<OpaUa>>({});
  31. const { minHeight } = useDomFullHeight(`.modbus`, 24);
  32. const iconMap = new Map();
  33. iconMap.set('1', require('/public/images/channel/1.png'));
  34. iconMap.set('2', require('/public/images/channel/2.png'));
  35. iconMap.set('3', require('/public/images/channel/3.png'));
  36. iconMap.set('4', require('/public/images/channel/4.png'));
  37. const columns: ProColumns<OpaUa>[] = [
  38. {
  39. title: '通道名称',
  40. dataIndex: 'name',
  41. ellipsis: true,
  42. fixed: 'left',
  43. },
  44. {
  45. title: 'IP',
  46. dataIndex: 'host',
  47. },
  48. {
  49. title: '端口',
  50. dataIndex: 'port',
  51. search: false,
  52. valueType: 'digit',
  53. },
  54. {
  55. title: '状态',
  56. dataIndex: 'state',
  57. renderText: (state) => (
  58. <Badge text={state?.text} status={state?.value === 'disabled' ? 'error' : 'success'} />
  59. ),
  60. valueType: 'select',
  61. valueEnum: {
  62. disabled: {
  63. text: intl.formatMessage({
  64. id: 'pages.data.option.disabled',
  65. defaultMessage: '禁用',
  66. }),
  67. status: 'disabled',
  68. },
  69. enabled: {
  70. text: '正常',
  71. status: 'enabled',
  72. },
  73. },
  74. filterMultiple: false,
  75. },
  76. {
  77. title: '操作',
  78. valueType: 'option',
  79. align: 'center',
  80. width: 200,
  81. fixed: 'right',
  82. render: (text, record) => [
  83. <PermissionButton
  84. isPermission={permission.update}
  85. key="edit"
  86. onClick={() => {
  87. setVisible(true);
  88. setCurrent(record);
  89. }}
  90. type={'link'}
  91. style={{ padding: 0 }}
  92. tooltip={{
  93. title: intl.formatMessage({
  94. id: 'pages.data.option.edit',
  95. defaultMessage: '编辑',
  96. }),
  97. }}
  98. >
  99. <EditOutlined />
  100. </PermissionButton>,
  101. <PermissionButton
  102. type="link"
  103. key={'action'}
  104. style={{ padding: 0 }}
  105. popConfirm={{
  106. title: intl.formatMessage({
  107. id: `pages.data.option.${
  108. record.state.value !== 'disabled' ? 'disabled' : 'enabled'
  109. }.tips`,
  110. defaultMessage: '确认禁用?',
  111. }),
  112. onConfirm: async () => {
  113. if (record.state.value === 'disabled') {
  114. await service.edit({
  115. ...record,
  116. state: 'enabled',
  117. });
  118. } else {
  119. await service.edit({
  120. ...record,
  121. state: 'disabled',
  122. });
  123. }
  124. onlyMessage(
  125. intl.formatMessage({
  126. id: 'pages.data.option.success',
  127. defaultMessage: '操作成功!',
  128. }),
  129. );
  130. actionRef.current?.reload();
  131. },
  132. }}
  133. isPermission={permission.action}
  134. tooltip={{
  135. title: intl.formatMessage({
  136. id: `pages.data.option.${record.state.value !== 'disabled' ? 'disabled' : 'enabled'}`,
  137. defaultMessage: record.state.value !== 'disabled' ? '禁用' : '启用',
  138. }),
  139. }}
  140. >
  141. {record.state.value !== 'disabled' ? <StopOutlined /> : <PlayCircleOutlined />}
  142. </PermissionButton>,
  143. <PermissionButton
  144. isPermission={permission.view}
  145. style={{ padding: 0 }}
  146. key="link"
  147. type="link"
  148. tooltip={{
  149. title: '数据点绑定',
  150. }}
  151. onClick={() => {
  152. history.push(`${getMenuPathByCode('link/Channel/Modbus/Access')}?id=${record.id}`);
  153. }}
  154. >
  155. <ControlOutlined />
  156. </PermissionButton>,
  157. <PermissionButton
  158. isPermission={permission.delete}
  159. style={{ padding: 0 }}
  160. disabled={record.state.value === 'enabled'}
  161. popConfirm={{
  162. title: '确认删除',
  163. disabled: record.state.value === 'enabled',
  164. onConfirm: async () => {
  165. const resp: any = await service.remove(record.id);
  166. if (resp.status === 200) {
  167. onlyMessage(
  168. intl.formatMessage({
  169. id: 'pages.data.option.success',
  170. defaultMessage: '操作成功!',
  171. }),
  172. );
  173. actionRef.current?.reload();
  174. }
  175. },
  176. }}
  177. key="delete"
  178. type="link"
  179. >
  180. <DeleteOutlined />
  181. </PermissionButton>,
  182. ],
  183. },
  184. ];
  185. const topCard = [
  186. {
  187. numeber: '1',
  188. title: 'Modbus通道',
  189. text: '配置Modbus通道',
  190. },
  191. {
  192. numeber: '2',
  193. title: '设备接入网关',
  194. text: '创建Modbus设备接入网关',
  195. },
  196. {
  197. numeber: '3',
  198. title: '创建产品',
  199. text: '创建产品,并选择接入方式为Modbus',
  200. },
  201. {
  202. numeber: '4',
  203. title: '添加设备',
  204. text: '添加设备,单独为每一个设备进行数据点绑定',
  205. },
  206. ];
  207. return (
  208. <PageContainer>
  209. {/* <NewModbus/> */}
  210. <Card style={{ marginBottom: 10 }}>
  211. <Row gutter={[24, 24]}>
  212. {topCard.map((item) => (
  213. <Col span={6} key={item.numeber}>
  214. <Card>
  215. <div className={styles.topCard}>
  216. <div>
  217. <img src={iconMap.get(item.numeber)} />
  218. </div>
  219. <div className={styles.text}>
  220. <p className={styles.p1}>{item.title}</p>
  221. <p className={styles.p2}>{item.text}</p>
  222. </div>
  223. </div>
  224. </Card>
  225. </Col>
  226. ))}
  227. </Row>
  228. </Card>
  229. <SearchComponent<any>
  230. field={columns}
  231. target="opcua"
  232. onSearch={(data) => {
  233. // 重置分页数据
  234. actionRef.current?.reset?.();
  235. setParam(data);
  236. }}
  237. />
  238. <ProTable<OpaUa>
  239. actionRef={actionRef}
  240. params={param}
  241. columns={columns}
  242. rowKey="id"
  243. scroll={{ x: 1366 }}
  244. search={false}
  245. tableClassName={'modbus'}
  246. tableStyle={{ minHeight }}
  247. headerTitle={
  248. <PermissionButton
  249. onClick={() => {
  250. // setMode('add');
  251. setVisible(true);
  252. setCurrent({});
  253. }}
  254. isPermission={permission.add}
  255. key="add"
  256. icon={<PlusOutlined />}
  257. type="primary"
  258. >
  259. {intl.formatMessage({
  260. id: 'pages.data.option.add',
  261. defaultMessage: '新增',
  262. })}
  263. </PermissionButton>
  264. }
  265. request={async (params) =>
  266. service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
  267. }
  268. />
  269. {visible && (
  270. <Save
  271. data={current}
  272. close={() => {
  273. setVisible(false);
  274. actionRef.current?.reload();
  275. }}
  276. />
  277. )}
  278. </PageContainer>
  279. );
  280. };
  281. export default Modbus;