index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import SearchComponent from '@/components/SearchComponent';
  3. import { useRef, useState } from 'react';
  4. import { history } from 'umi';
  5. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  6. import { PermissionButton, ProTableCard } from '@/components';
  7. import {
  8. DeleteOutlined,
  9. EditOutlined,
  10. InfoCircleOutlined,
  11. PlayCircleOutlined,
  12. PlusOutlined,
  13. StopOutlined,
  14. } from '@ant-design/icons';
  15. import { useIntl } from '@@/plugin-locale/localeExports';
  16. import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
  17. import AliyunCard from '@/components/ProTableCard/CardItems/aliyun';
  18. import Service from './service';
  19. import { Badge } from 'antd';
  20. import { onlyMessage } from '@/utils/util';
  21. export const service = new Service('device/aliyun/bridge');
  22. const AliCloud = () => {
  23. const actionRef = useRef<ActionType>();
  24. const intl = useIntl();
  25. const [searchParams, setSearchParams] = useState<any>({});
  26. const { permission } = PermissionButton.usePermission('Northbound/AliCloud');
  27. const Tools = (record: any, type: 'card' | 'table') => {
  28. return [
  29. <PermissionButton
  30. key={'update'}
  31. type={'link'}
  32. style={{ padding: 0 }}
  33. isPermission={permission.update}
  34. tooltip={
  35. type === 'table'
  36. ? {
  37. title: intl.formatMessage({
  38. id: 'pages.data.option.edit',
  39. defaultMessage: '编辑',
  40. }),
  41. }
  42. : undefined
  43. }
  44. onClick={() => {
  45. const url = `${getMenuPathByParams(MENUS_CODE['Northbound/AliCloud/Detail'], record.id)}`;
  46. history.push(url);
  47. }}
  48. >
  49. <EditOutlined />
  50. {type !== 'table' &&
  51. intl.formatMessage({
  52. id: 'pages.data.option.edit',
  53. defaultMessage: '编辑',
  54. })}
  55. </PermissionButton>,
  56. <PermissionButton
  57. key={'action'}
  58. type={'link'}
  59. style={{ padding: 0 }}
  60. isPermission={permission.action}
  61. popConfirm={{
  62. title: intl.formatMessage({
  63. id: `pages.data.option.${
  64. record?.state?.value !== 'disabled' ? 'disabled' : 'enabled'
  65. }.tips`,
  66. defaultMessage: '确认禁用?',
  67. }),
  68. onConfirm: async () => {
  69. const resp =
  70. record?.state?.value !== 'disabled'
  71. ? await service._disable(record.id)
  72. : await service._enable(record.id);
  73. if (resp.status === 200) {
  74. onlyMessage('操作成功!');
  75. actionRef.current?.reload?.();
  76. } else {
  77. onlyMessage('操作失败!', 'error');
  78. }
  79. },
  80. }}
  81. tooltip={{
  82. title: intl.formatMessage({
  83. id: `pages.data.option.${record?.state?.value !== 'disabled' ? 'disabled' : 'enabled'}`,
  84. defaultMessage: '启用',
  85. }),
  86. }}
  87. >
  88. {record?.state?.value !== 'disabled' ? <StopOutlined /> : <PlayCircleOutlined />}
  89. </PermissionButton>,
  90. <PermissionButton
  91. key={'delete'}
  92. type={'link'}
  93. style={{ padding: 0 }}
  94. isPermission={permission.delete}
  95. disabled={record.state.value === 'started'}
  96. popConfirm={{
  97. title: '确认删除?',
  98. disabled: record.state.value === 'started',
  99. onConfirm: async () => {
  100. if (record?.state?.value === 'disabled') {
  101. await service.remove(record.id);
  102. onlyMessage(
  103. intl.formatMessage({
  104. id: 'pages.data.option.success',
  105. defaultMessage: '操作成功!',
  106. }),
  107. );
  108. actionRef.current?.reload();
  109. } else {
  110. onlyMessage(intl.formatMessage({ id: 'pages.device.instance.deleteTip' }), 'error');
  111. }
  112. },
  113. }}
  114. tooltip={{
  115. title:
  116. record.state.value === 'started' ? <span>请先禁用,再删除</span> : <span>删除</span>,
  117. }}
  118. >
  119. <DeleteOutlined />
  120. </PermissionButton>,
  121. ];
  122. };
  123. const columns: ProColumns<AliCloudType>[] = [
  124. {
  125. title: '名称',
  126. dataIndex: 'name',
  127. ellipsis: true,
  128. fixed: 'left',
  129. },
  130. {
  131. title: '网桥产品',
  132. dataIndex: 'bridgeProductName',
  133. ellipsis: true,
  134. },
  135. {
  136. title: '说明',
  137. dataIndex: 'description',
  138. ellipsis: true,
  139. },
  140. {
  141. title: '状态',
  142. dataIndex: 'state',
  143. render: (text: any, record: any) => (
  144. <span>
  145. <Badge
  146. status={record?.state?.value === 'disabled' ? 'error' : 'success'}
  147. text={record?.state?.text}
  148. />
  149. </span>
  150. ),
  151. valueType: 'select',
  152. valueEnum: {
  153. disabled: {
  154. text: '停用',
  155. status: 'disabled',
  156. },
  157. enabled: {
  158. text: '正常',
  159. status: 'enabled',
  160. },
  161. },
  162. },
  163. {
  164. title: intl.formatMessage({
  165. id: 'pages.data.option',
  166. defaultMessage: '操作',
  167. }),
  168. valueType: 'option',
  169. align: 'center',
  170. width: 200,
  171. fixed: 'right',
  172. render: (text, record) => Tools(record, 'table'),
  173. },
  174. ];
  175. return (
  176. <PageContainer>
  177. <SearchComponent<AliCloudType>
  178. field={columns}
  179. target="aliyun"
  180. onSearch={(data) => {
  181. actionRef.current?.reload?.();
  182. setSearchParams(data);
  183. }}
  184. />
  185. <div style={{ backgroundColor: 'white', width: '100%', height: 60, padding: 20 }}>
  186. <div
  187. style={{
  188. padding: 10,
  189. width: '100%',
  190. color: 'rgba(0, 0, 0, 0.55)',
  191. backgroundColor: '#f6f6f6',
  192. }}
  193. >
  194. <InfoCircleOutlined style={{ marginRight: 10 }} />
  195. 将平台产品与设备数据通过API的方式同步到阿里云物联网平台
  196. </div>
  197. </div>
  198. <ProTableCard<AliCloudType>
  199. rowKey="id"
  200. search={false}
  201. scroll={{ x: 1366 }}
  202. columns={columns}
  203. actionRef={actionRef}
  204. params={searchParams}
  205. options={{ fullScreen: true }}
  206. request={(params) =>
  207. service.query({
  208. ...params,
  209. sorts: [
  210. {
  211. name: 'createTime',
  212. order: 'desc',
  213. },
  214. ],
  215. })
  216. }
  217. pagination={{ pageSize: 10 }}
  218. headerTitle={[
  219. <PermissionButton
  220. onClick={() => {
  221. const url = `${getMenuPathByParams(MENUS_CODE['Northbound/AliCloud/Detail'])}`;
  222. history.push(url);
  223. }}
  224. style={{ marginRight: 12 }}
  225. isPermission={permission.add}
  226. key="button"
  227. icon={<PlusOutlined />}
  228. type="primary"
  229. >
  230. {intl.formatMessage({
  231. id: 'pages.data.option.add',
  232. defaultMessage: '新增',
  233. })}
  234. </PermissionButton>,
  235. ]}
  236. cardRender={(record) => (
  237. <AliyunCard
  238. {...record}
  239. actions={[
  240. <PermissionButton
  241. type={'link'}
  242. onClick={() => {
  243. const url = `${getMenuPathByParams(
  244. MENUS_CODE['Northbound/AliCloud/Detail'],
  245. record.id,
  246. )}`;
  247. history.push(url);
  248. }}
  249. key={'edit'}
  250. isPermission={permission.update}
  251. >
  252. <EditOutlined />
  253. {intl.formatMessage({
  254. id: 'pages.data.option.edit',
  255. defaultMessage: '编辑',
  256. })}
  257. </PermissionButton>,
  258. <PermissionButton
  259. key={'action'}
  260. type={'link'}
  261. style={{ padding: 0 }}
  262. isPermission={permission.action}
  263. popConfirm={{
  264. title: intl.formatMessage({
  265. id: `pages.data.option.${
  266. record?.state?.value !== 'disabled' ? 'disabled' : 'enabled'
  267. }.tips`,
  268. defaultMessage: '确认禁用?',
  269. }),
  270. onConfirm: async () => {
  271. const resp =
  272. record?.state?.value !== 'disabled'
  273. ? await service._disable(record.id)
  274. : await service._enable(record.id);
  275. if (resp.status === 200) {
  276. onlyMessage('操作成功!');
  277. actionRef.current?.reload?.();
  278. } else {
  279. onlyMessage('操作失败!', 'error');
  280. }
  281. },
  282. }}
  283. >
  284. {record?.state?.value !== 'disabled' ? <StopOutlined /> : <PlayCircleOutlined />}
  285. {intl.formatMessage({
  286. id: `pages.data.option.${
  287. record?.state?.value !== 'disabled' ? 'disabled' : 'enabled'
  288. }`,
  289. defaultMessage: record?.state?.value !== 'disabled' ? '禁用' : '启用',
  290. })}
  291. </PermissionButton>,
  292. <PermissionButton
  293. key="delete"
  294. isPermission={permission.delete}
  295. type={'link'}
  296. style={{ padding: 0 }}
  297. tooltip={
  298. record?.state?.value !== 'disabled'
  299. ? { title: intl.formatMessage({ id: 'pages.device.instance.deleteTip' }) }
  300. : undefined
  301. }
  302. disabled={record?.state?.value !== 'disabled'}
  303. popConfirm={{
  304. title: intl.formatMessage({
  305. id: 'pages.data.option.remove.tips',
  306. }),
  307. disabled: record?.state?.value !== 'disabled',
  308. onConfirm: async () => {
  309. if (record?.state?.value === 'disabled') {
  310. await service.remove(record.id);
  311. onlyMessage(
  312. intl.formatMessage({
  313. id: 'pages.data.option.success',
  314. defaultMessage: '操作成功!',
  315. }),
  316. );
  317. actionRef.current?.reload();
  318. } else {
  319. onlyMessage(
  320. intl.formatMessage({ id: 'pages.device.instance.deleteTip' }),
  321. 'error',
  322. );
  323. }
  324. },
  325. }}
  326. >
  327. <DeleteOutlined />
  328. </PermissionButton>,
  329. ]}
  330. />
  331. )}
  332. />
  333. </PageContainer>
  334. );
  335. };
  336. export default AliCloud;