index.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import { service } from '@/pages/media/Cascade';
  2. import SearchComponent from '@/components/SearchComponent';
  3. import { CloseOutlined, DisconnectOutlined, EditOutlined } from '@ant-design/icons';
  4. import { PageContainer } from '@ant-design/pro-layout';
  5. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  6. import ProTable from '@jetlinks/pro-table';
  7. import { Button, Input, message, Popover, Space } from 'antd';
  8. import { useRef, useState } from 'react';
  9. import { useIntl, useLocation } from 'umi';
  10. import BindChannel from './BindChannel';
  11. import BadgeStatus, { StatusColorEnum } from '@/components/BadgeStatus';
  12. import { PermissionButton } from '@/components';
  13. const Channel = () => {
  14. const location: any = useLocation();
  15. const actionRef = useRef<ActionType>();
  16. const [param, setParam] = useState({});
  17. const intl = useIntl();
  18. const [visible, setVisible] = useState<boolean>(false);
  19. const [selectedRowKey, setSelectedRowKey] = useState<string[]>([]);
  20. const id = location?.query?.id || '';
  21. const [data, setData] = useState<string>('');
  22. const [popVisible, setPopvisible] = useState<string>('');
  23. const { permission } = PermissionButton.usePermission('media/Cascade');
  24. const unbind = async (list: string[]) => {
  25. const resp = await service.unbindChannel(id, list);
  26. if (resp.status === 200) {
  27. actionRef.current?.reload();
  28. message.success('操作成功!');
  29. if (list.length === 1) {
  30. const index = selectedRowKey.indexOf(list[0]);
  31. const dt = [...selectedRowKey];
  32. dt.splice(index, 1);
  33. setSelectedRowKey([...dt]);
  34. }
  35. }
  36. };
  37. const content = (record: any) => {
  38. return (
  39. <div>
  40. <Input
  41. value={data}
  42. placeholder="请输入国标ID"
  43. onChange={(e) => {
  44. setData(e.target.value);
  45. }}
  46. />
  47. <Button
  48. type="primary"
  49. style={{ marginTop: 10, width: '100%' }}
  50. onClick={async () => {
  51. if (!!data) {
  52. const resp: any = await service.editBindInfo(record.id, {
  53. gbChannelId: data,
  54. });
  55. if (resp.status === 200) {
  56. message.success('操作成功');
  57. actionRef.current?.reload();
  58. setPopvisible('');
  59. }
  60. } else {
  61. message.error('请输入国标ID');
  62. }
  63. }}
  64. >
  65. 保存
  66. </Button>
  67. </div>
  68. );
  69. };
  70. const columns: ProColumns<any>[] = [
  71. {
  72. dataIndex: 'deviceName',
  73. title: '设备名称',
  74. },
  75. {
  76. dataIndex: 'name',
  77. title: '通道名称',
  78. },
  79. {
  80. dataIndex: 'gbChannelId',
  81. title: '国标ID',
  82. tooltip: '国标级联有18位、20位两种格式。在当前页面修改不会修改视频设备-通道页面中的国标ID',
  83. render: (text: any, record: any) => (
  84. <span>
  85. {text}
  86. <Popover
  87. visible={popVisible === record.id}
  88. trigger="click"
  89. content={content(record)}
  90. title={
  91. <div
  92. style={{
  93. width: '100%',
  94. display: 'flex',
  95. justifyContent: 'space-between',
  96. alignItems: 'center',
  97. }}
  98. >
  99. <div>编辑国标ID</div>
  100. <CloseOutlined
  101. onClick={() => {
  102. setPopvisible('');
  103. setData('');
  104. }}
  105. />
  106. </div>
  107. }
  108. >
  109. <a
  110. style={{ marginLeft: 10 }}
  111. onClick={() => {
  112. setData('');
  113. setPopvisible(record.id);
  114. }}
  115. >
  116. <EditOutlined />
  117. </a>
  118. </Popover>
  119. </span>
  120. ),
  121. },
  122. {
  123. dataIndex: 'address',
  124. title: '安装地址',
  125. },
  126. {
  127. dataIndex: 'manufacturer',
  128. title: '厂商',
  129. },
  130. {
  131. dataIndex: 'status',
  132. title: '在线状态',
  133. valueType: 'select',
  134. valueEnum: {
  135. online: {
  136. text: '已连接',
  137. status: 'online',
  138. },
  139. offline: {
  140. text: '离线',
  141. status: 'offline',
  142. },
  143. },
  144. render: (text: any, record: any) => (
  145. <BadgeStatus
  146. status={record.status?.value}
  147. text={record.status?.text}
  148. statusNames={{
  149. online: StatusColorEnum.success,
  150. offline: StatusColorEnum.error,
  151. }}
  152. />
  153. ),
  154. },
  155. {
  156. title: '操作',
  157. valueType: 'option',
  158. align: 'center',
  159. width: 200,
  160. render: (text: any, record: any) => [
  161. <PermissionButton
  162. isPermission={permission.channel}
  163. key={'unbind'}
  164. type={'link'}
  165. popConfirm={{
  166. title: `确认解绑`,
  167. onConfirm: () => {
  168. unbind([record.channelId]);
  169. },
  170. }}
  171. >
  172. <DisconnectOutlined />
  173. </PermissionButton>,
  174. ],
  175. },
  176. ];
  177. return (
  178. <PageContainer>
  179. <SearchComponent<any>
  180. field={columns}
  181. target="bind-channel"
  182. onSearch={(params) => {
  183. actionRef.current?.reload();
  184. setParam({
  185. ...param,
  186. terms: params?.terms ? [...params?.terms] : [],
  187. });
  188. }}
  189. />
  190. <ProTable<any>
  191. actionRef={actionRef}
  192. params={param}
  193. columns={columns}
  194. search={false}
  195. headerTitle={'通道列表'}
  196. request={async (params) => {
  197. return service.queryBindChannel(id, {
  198. ...params,
  199. sorts: [{ name: 'name', order: 'desc' }],
  200. });
  201. }}
  202. rowKey="channelId"
  203. rowSelection={{
  204. selectedRowKeys: selectedRowKey,
  205. onChange: (selectedRowKeys) => {
  206. setSelectedRowKey(selectedRowKeys as string[]);
  207. },
  208. }}
  209. tableAlertRender={({ selectedRowKeys, onCleanSelected }) => (
  210. <Space size={24}>
  211. <span>
  212. {intl.formatMessage({
  213. id: 'pages.bindUser.bindTheNewUser.selected',
  214. defaultMessage: '已选',
  215. })}{' '}
  216. {selectedRowKeys.length}{' '}
  217. {intl.formatMessage({
  218. id: 'pages.bindUser.bindTheNewUser.item',
  219. defaultMessage: '项',
  220. })}
  221. <a style={{ marginLeft: 8 }} onClick={onCleanSelected}>
  222. {intl.formatMessage({
  223. id: 'pages.bindUser.bindTheNewUser.deselect',
  224. defaultMessage: '取消选择',
  225. })}
  226. </a>
  227. </span>
  228. </Space>
  229. )}
  230. toolBarRender={() => [
  231. <PermissionButton
  232. isPermission={permission.channel}
  233. key={'bind'}
  234. onClick={() => {
  235. setVisible(true);
  236. }}
  237. type={'primary'}
  238. >
  239. 绑定通道
  240. </PermissionButton>,
  241. <PermissionButton
  242. isPermission={permission.channel}
  243. key={'unbind'}
  244. popConfirm={{
  245. title: `确认解绑`,
  246. onConfirm: () => {
  247. if (selectedRowKey.length > 0) {
  248. unbind(selectedRowKey);
  249. setSelectedRowKey([]);
  250. } else {
  251. message.error('请先选择需要解绑的通道列表');
  252. }
  253. },
  254. }}
  255. >
  256. 批量解绑
  257. </PermissionButton>,
  258. ]}
  259. />
  260. {visible && (
  261. <BindChannel
  262. data={id}
  263. close={() => {
  264. setVisible(false);
  265. actionRef.current?.reload();
  266. }}
  267. />
  268. )}
  269. </PageContainer>
  270. );
  271. };
  272. export default Channel;