index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. // 视频设备列表
  2. import { PageContainer } from '@ant-design/pro-layout';
  3. import { useRef, useState } from 'react';
  4. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  5. import { Button, Tooltip } from 'antd';
  6. import {
  7. DeleteOutlined,
  8. EditOutlined,
  9. EyeOutlined,
  10. PartitionOutlined,
  11. PlusOutlined,
  12. SyncOutlined,
  13. } from '@ant-design/icons';
  14. import type { DeviceItem } from '@/pages/media/Device/typings';
  15. import { useHistory, useIntl } from 'umi';
  16. import { BadgeStatus, PermissionButton, ProTableCard } from '@/components';
  17. import { StatusColorEnum } from '@/components/BadgeStatus';
  18. import SearchComponent from '@/components/SearchComponent';
  19. import MediaDevice from '@/components/ProTableCard/CardItems/mediaDevice';
  20. import { getMenuPathByCode, getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
  21. import Service from './service';
  22. import { onlyMessage } from '@/utils/util';
  23. export const service = new Service('media/device');
  24. export const providerType = {
  25. 'gb28181-2016': 'GB/T28181',
  26. 'fixed-media': '固定地址',
  27. };
  28. export const ProviderValue = {
  29. GB281: 'gb28181-2016',
  30. FIXED: 'fixed-media',
  31. };
  32. const Device = () => {
  33. const intl = useIntl();
  34. const actionRef = useRef<ActionType>();
  35. const [queryParam, setQueryParam] = useState({});
  36. const history = useHistory<Record<string, string>>();
  37. const { permission } = PermissionButton.usePermission('media/Device');
  38. /**
  39. * table 查询参数
  40. * @param data
  41. */
  42. const searchFn = (data: any) => {
  43. setQueryParam(data);
  44. };
  45. const deleteItem = async (id: string) => {
  46. const response: any = await service.remove(id);
  47. if (response.status === 200) {
  48. onlyMessage(
  49. intl.formatMessage({
  50. id: 'pages.data.option.success',
  51. defaultMessage: '操作成功!',
  52. }),
  53. );
  54. actionRef.current?.reload();
  55. }
  56. };
  57. /**
  58. * 更新通道
  59. * @param id 视频设备ID
  60. */
  61. const updateChannel = async (id: string) => {
  62. const resp = await service.updateChannels(id);
  63. if (resp.status === 200) {
  64. actionRef.current?.reload();
  65. onlyMessage('通道更新成功');
  66. } else {
  67. onlyMessage('通道更新失败', 'error');
  68. }
  69. };
  70. const columns: ProColumns<DeviceItem>[] = [
  71. {
  72. dataIndex: 'id',
  73. title: 'ID',
  74. ellipsis: true,
  75. fixed: 'left',
  76. },
  77. {
  78. dataIndex: 'name',
  79. ellipsis: true,
  80. title: intl.formatMessage({
  81. id: 'pages.table.name',
  82. defaultMessage: '名称',
  83. }),
  84. },
  85. {
  86. dataIndex: 'provider',
  87. title: '接入方式',
  88. render: (_, row) => {
  89. return providerType[row.provider];
  90. },
  91. valueType: 'select',
  92. valueEnum: {
  93. [ProviderValue.FIXED]: {
  94. text: '固定地址',
  95. status: ProviderValue.FIXED,
  96. },
  97. [ProviderValue.GB281]: {
  98. text: 'GB/T28181',
  99. status: ProviderValue.GB281,
  100. },
  101. },
  102. filterMultiple: false,
  103. },
  104. {
  105. dataIndex: 'channelNumber',
  106. title: intl.formatMessage({
  107. id: 'pages.media.device.channelNumber',
  108. defaultMessage: '通道数量',
  109. }),
  110. valueType: 'digit',
  111. hideInSearch: true,
  112. },
  113. {
  114. dataIndex: 'manufacturer',
  115. ellipsis: true,
  116. title: intl.formatMessage({
  117. id: 'pages.media.device.manufacturer',
  118. defaultMessage: '设备厂家',
  119. }),
  120. },
  121. // {
  122. // dataIndex: 'model',
  123. // title: intl.formatMessage({
  124. // id: 'pages.media.device.model',
  125. // defaultMessage: '型号',
  126. // }),
  127. // },
  128. // {
  129. // dataIndex: 'firmware',
  130. // title: intl.formatMessage({
  131. // id: 'pages.media.device.firmware',
  132. // defaultMessage: '固件版本',
  133. // }),
  134. // },
  135. {
  136. dataIndex: 'state',
  137. title: intl.formatMessage({
  138. id: 'pages.searchTable.titleStatus',
  139. defaultMessage: '状态',
  140. }),
  141. render: (_, record) => (
  142. <BadgeStatus
  143. status={record.state.value}
  144. statusNames={{
  145. online: StatusColorEnum.success,
  146. offline: StatusColorEnum.error,
  147. notActive: StatusColorEnum.warning,
  148. }}
  149. text={record.state.text}
  150. />
  151. ),
  152. valueType: 'select',
  153. valueEnum: {
  154. notActive: {
  155. text: intl.formatMessage({
  156. id: 'pages.device.instance.status.notActive',
  157. defaultMessage: '禁用',
  158. }),
  159. status: 'notActive',
  160. },
  161. offline: {
  162. text: intl.formatMessage({
  163. id: 'pages.device.instance.status.offLine',
  164. defaultMessage: '离线',
  165. }),
  166. status: 'offline',
  167. },
  168. online: {
  169. text: intl.formatMessage({
  170. id: 'pages.device.instance.status.onLine',
  171. defaultMessage: '在线',
  172. }),
  173. status: 'online',
  174. },
  175. },
  176. filterMultiple: false,
  177. },
  178. {
  179. title: intl.formatMessage({
  180. id: 'pages.data.option',
  181. defaultMessage: '操作',
  182. }),
  183. valueType: 'option',
  184. align: 'center',
  185. width: 200,
  186. fixed: 'right',
  187. render: (text, record) => [
  188. <PermissionButton
  189. key="edit"
  190. tooltip={{
  191. title: intl.formatMessage({
  192. id: 'pages.data.option.edit',
  193. defaultMessage: '编辑',
  194. }),
  195. }}
  196. isPermission={permission.update}
  197. style={{ padding: 0 }}
  198. type={'link'}
  199. onClick={() => {
  200. const url = getMenuPathByCode(MENUS_CODE[`media/Device/Save`]);
  201. history.push(url + `?id=${record.id}`);
  202. }}
  203. >
  204. <EditOutlined />
  205. </PermissionButton>,
  206. <PermissionButton
  207. tooltip={{
  208. title: '查看通道',
  209. }}
  210. style={{ padding: 0 }}
  211. type={'link'}
  212. onClick={() => {
  213. history.push(
  214. `${getMenuPathByCode(MENUS_CODE['media/Device/Channel'])}?id=${record.id}&type=${
  215. record.provider
  216. }`,
  217. );
  218. }}
  219. isPermission={true}
  220. key={'view'}
  221. >
  222. <PartitionOutlined />
  223. </PermissionButton>,
  224. <Tooltip key={'deviceDetail'} title={'查看'}>
  225. <Button
  226. style={{ padding: 0 }}
  227. type={'link'}
  228. onClick={() => {
  229. history.push(
  230. `${getMenuPathByParams(MENUS_CODE['device/Instance/Detail'], record.id)}`,
  231. );
  232. }}
  233. >
  234. <EyeOutlined />
  235. </Button>
  236. </Tooltip>,
  237. <PermissionButton
  238. tooltip={
  239. record.state.value === 'offline' ||
  240. record.state.value === 'notActive' ||
  241. record.provider === providerType['fixed-media']
  242. ? {
  243. title:
  244. record.provider === providerType['fixed-media']
  245. ? '固定地址无法更新通道'
  246. : record.state.value === 'offline'
  247. ? '设备已离线'
  248. : record.state.value === 'notActive'
  249. ? '设备已禁用'
  250. : '',
  251. }
  252. : undefined
  253. }
  254. key={'updateChannel'}
  255. isPermission={permission.update}
  256. disabled={
  257. record.state.value === 'offline' ||
  258. record.state.value === 'notActive' ||
  259. record.provider === providerType['fixed-media']
  260. }
  261. style={{ padding: 0 }}
  262. type={'link'}
  263. onClick={() => {
  264. updateChannel(record.id);
  265. }}
  266. >
  267. <SyncOutlined />
  268. </PermissionButton>,
  269. <PermissionButton
  270. key={'delete'}
  271. tooltip={{
  272. title: record.state.value === 'online' ? '在线设备无法删除' : '删除',
  273. }}
  274. popConfirm={{
  275. title: (
  276. <div style={{ width: 100 }}>
  277. {intl.formatMessage({
  278. id:
  279. record.state.value !== 'offline'
  280. ? 'pages.device.instance.deleteTip'
  281. : 'page.table.isDelete',
  282. defaultMessage: '是否删除?',
  283. })}
  284. </div>
  285. ),
  286. onConfirm: async () => {
  287. if (record.state.value !== 'online') {
  288. await deleteItem(record.id);
  289. } else {
  290. onlyMessage('在线设备不能进行删除操作', 'error');
  291. }
  292. },
  293. }}
  294. type={'link'}
  295. style={{ padding: 0 }}
  296. isPermission={permission.delete}
  297. disabled={record.state.value === 'online'}
  298. >
  299. <DeleteOutlined />
  300. </PermissionButton>,
  301. ],
  302. },
  303. ];
  304. return (
  305. <PageContainer>
  306. <SearchComponent field={columns} onSearch={searchFn} target="media-device" />
  307. <ProTableCard<DeviceItem>
  308. columns={columns}
  309. actionRef={actionRef}
  310. options={{ fullScreen: true }}
  311. params={queryParam}
  312. columnEmptyText={''}
  313. scroll={{ x: 1366 }}
  314. request={(params = {}) =>
  315. service.query({
  316. ...params,
  317. sorts: [
  318. {
  319. name: 'createTime',
  320. order: 'desc',
  321. },
  322. ],
  323. })
  324. }
  325. rowKey="id"
  326. search={false}
  327. headerTitle={[
  328. <PermissionButton
  329. onClick={() => {
  330. const url = getMenuPathByCode(MENUS_CODE[`media/Device/Save`]);
  331. history.push(url);
  332. }}
  333. key="button"
  334. icon={<PlusOutlined />}
  335. type="primary"
  336. isPermission={permission.add}
  337. >
  338. {intl.formatMessage({
  339. id: 'pages.data.option.add',
  340. defaultMessage: '新增',
  341. })}
  342. </PermissionButton>,
  343. ]}
  344. cardRender={(record) => (
  345. <MediaDevice
  346. {...record}
  347. // detail={
  348. // <div
  349. // style={{ fontSize: 18, padding: 8 }}
  350. // onClick={() => {
  351. // history.push(
  352. // `${getMenuPathByParams(MENUS_CODE['device/Instance/Detail'], record.id)}`,
  353. // );
  354. // }}
  355. // >
  356. // <EyeOutlined />
  357. // </div>
  358. // }
  359. showMask={false}
  360. actions={[
  361. <PermissionButton
  362. key="edit"
  363. isPermission={permission.update}
  364. onClick={() => {
  365. const url = getMenuPathByCode(MENUS_CODE[`media/Device/Save`]);
  366. history.push(url + `?id=${record.id}`);
  367. }}
  368. type={'link'}
  369. style={{ padding: 0 }}
  370. >
  371. <EditOutlined />
  372. {intl.formatMessage({
  373. id: 'pages.data.option.edit',
  374. defaultMessage: '编辑',
  375. })}
  376. </PermissionButton>,
  377. <Button
  378. key={'viewChannel'}
  379. onClick={() => {
  380. history.push(
  381. `${getMenuPathByCode(MENUS_CODE['media/Device/Channel'])}?id=${
  382. record.id
  383. }&type=${record.provider}`,
  384. );
  385. }}
  386. >
  387. <PartitionOutlined />
  388. 查看通道
  389. </Button>,
  390. <PermissionButton
  391. key={'updateChannel'}
  392. isPermission={permission.update}
  393. tooltip={
  394. record.state.value !== 'online' || record.provider === providerType['fixed-media']
  395. ? {
  396. title:
  397. record.provider === providerType['fixed-media']
  398. ? '固定地址无法更新通道'
  399. : record.state.value === 'offline'
  400. ? '设备已离线'
  401. : record.state.value === 'notActive'
  402. ? '设备已禁用'
  403. : '',
  404. }
  405. : undefined
  406. }
  407. disabled={
  408. record.state.value !== 'online' || record.provider === providerType['fixed-media']
  409. }
  410. onClick={() => {
  411. updateChannel(record.id);
  412. }}
  413. >
  414. <SyncOutlined />
  415. 更新通道
  416. </PermissionButton>,
  417. <PermissionButton
  418. key="delete"
  419. popConfirm={{
  420. title: intl.formatMessage({
  421. id:
  422. record.state.value !== 'online'
  423. ? 'page.table.isDelete'
  424. : 'pages.device.instance.deleteTip',
  425. defaultMessage: '是否删除?',
  426. }),
  427. onConfirm: async () => {
  428. if (record.state.value !== 'online') {
  429. await deleteItem(record.id);
  430. } else {
  431. onlyMessage('在线设备不能进行删除操作', 'error');
  432. }
  433. },
  434. }}
  435. tooltip={
  436. record.state.value === 'online' ? { title: '在线设备无法删除' } : undefined
  437. }
  438. type={'link'}
  439. style={{ padding: 0 }}
  440. isPermission={permission.delete}
  441. disabled={record.state.value === 'online'}
  442. >
  443. <DeleteOutlined />
  444. </PermissionButton>,
  445. ]}
  446. />
  447. )}
  448. />
  449. {/* <Save
  450. model={!current ? 'add' : 'edit'}
  451. data={current}
  452. close={() => {
  453. setVisible(false);
  454. }}
  455. reload={() => {
  456. actionRef.current?.reload();
  457. }}
  458. visible={visible}
  459. /> */}
  460. </PageContainer>
  461. );
  462. };
  463. export default Device;