index.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import { PermissionButton } from '@/components';
  2. import SearchComponent from '@/components/SearchComponent';
  3. import useDomFullHeight from '@/hooks/document/useDomFullHeight';
  4. import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
  5. import { onlyMessage } from '@/utils/util';
  6. import {
  7. DeleteOutlined,
  8. EditOutlined,
  9. PlayCircleOutlined,
  10. PlusOutlined,
  11. StopOutlined,
  12. } from '@ant-design/icons';
  13. import { PageContainer } from '@ant-design/pro-layout';
  14. import ProTable, { ActionType, ProColumns } from '@jetlinks/pro-table';
  15. import { Badge } from 'antd';
  16. import { useRef, useState } from 'react';
  17. import Service from './service';
  18. import { useHistory } from '@/hooks';
  19. export const service = new Service('network/card/platform');
  20. const Platform = () => {
  21. const { minHeight } = useDomFullHeight(`.record`, 24);
  22. const actionRef = useRef<ActionType>();
  23. const [param, setParam] = useState({});
  24. const history = useHistory();
  25. const { permission } = PermissionButton.usePermission('iot-card/Platform');
  26. const statusUpdate = async (data: any) => {
  27. const res = await service.update(data);
  28. if (res.status === 200) {
  29. onlyMessage('操作成功');
  30. actionRef.current?.reload();
  31. }
  32. };
  33. const columns: ProColumns<any>[] = [
  34. {
  35. title: '名称',
  36. dataIndex: 'name',
  37. ellipsis: true,
  38. },
  39. {
  40. title: '平台类型',
  41. dataIndex: 'operatorName',
  42. ellipsis: true,
  43. valueType: 'select',
  44. valueEnum: {
  45. onelink: {
  46. text: '移动OneLink',
  47. status: 'onelink',
  48. },
  49. ctwing: {
  50. text: '电信Ctwing',
  51. status: 'ctwing',
  52. },
  53. unicom: {
  54. text: '联通Unicom',
  55. status: 'unicom',
  56. },
  57. },
  58. },
  59. {
  60. title: '状态',
  61. dataIndex: 'state',
  62. ellipsis: true,
  63. valueType: 'select',
  64. valueEnum: {
  65. enabled: {
  66. text: '启用',
  67. status: 'enabled',
  68. },
  69. disabled: {
  70. text: '禁用',
  71. status: 'disabled',
  72. },
  73. },
  74. render: (_, record: any) => (
  75. <Badge
  76. status={record.state?.value === 'disabled' ? 'error' : 'success'}
  77. text={record.state?.text}
  78. />
  79. ),
  80. },
  81. {
  82. title: '说明',
  83. dataIndex: 'explain',
  84. ellipsis: true,
  85. hideInSearch: true,
  86. },
  87. {
  88. title: '操作',
  89. valueType: 'option',
  90. fixed: 'right',
  91. render: (text, record) => [
  92. <PermissionButton
  93. isPermission={permission.update}
  94. key="edit"
  95. onClick={() => {
  96. const url = `${getMenuPathByParams(MENUS_CODE['iot-card/Platform/Detail'], record.id)}`;
  97. history.push(url);
  98. }}
  99. type={'link'}
  100. style={{ padding: 0 }}
  101. tooltip={{
  102. title: '编辑',
  103. }}
  104. >
  105. <EditOutlined />
  106. </PermissionButton>,
  107. <PermissionButton
  108. isPermission={permission.action}
  109. key="action"
  110. type={'link'}
  111. style={{ padding: 0 }}
  112. tooltip={{
  113. title: record.state.value === 'enabled' ? '禁用' : '启用',
  114. }}
  115. popConfirm={{
  116. title: `确认${record.state.value === 'enabled' ? '禁用' : '启用'}`,
  117. onConfirm: () => {
  118. if (record.state.value === 'enabled') {
  119. statusUpdate({
  120. id: record.id,
  121. config: { ...record.config },
  122. state: 'disabled',
  123. operatorName: record.operatorName,
  124. });
  125. } else {
  126. statusUpdate({
  127. id: record.id,
  128. config: { ...record.config },
  129. state: 'enabled',
  130. operatorName: record.operatorName,
  131. });
  132. }
  133. },
  134. }}
  135. >
  136. {record.state.value === 'enabled' ? <StopOutlined /> : <PlayCircleOutlined />}
  137. </PermissionButton>,
  138. <PermissionButton
  139. isPermission={permission.delete}
  140. tooltip={{
  141. title: record.state.value !== 'enabled' ? '删除' : '请先禁用再删除',
  142. }}
  143. style={{ padding: 0 }}
  144. disabled={record.state.value === 'enabled'}
  145. popConfirm={{
  146. title: '确认删除',
  147. disabled: record.state.value === 'enabled',
  148. onConfirm: async () => {
  149. const res: any = await service.remove(record.id);
  150. if (res.status === 200) {
  151. onlyMessage('操作成功');
  152. actionRef.current?.reload();
  153. }
  154. },
  155. }}
  156. key="delete"
  157. type="link"
  158. >
  159. <DeleteOutlined />
  160. </PermissionButton>,
  161. ],
  162. },
  163. ];
  164. return (
  165. <PageContainer>
  166. <SearchComponent
  167. field={columns}
  168. target="record"
  169. onSearch={(data) => {
  170. // 重置分页数据
  171. actionRef.current?.reset?.();
  172. setParam(data);
  173. }}
  174. />
  175. <ProTable
  176. actionRef={actionRef}
  177. params={param}
  178. columns={columns}
  179. search={false}
  180. rowKey="id"
  181. tableClassName={'record'}
  182. columnEmptyText={''}
  183. tableStyle={{ minHeight }}
  184. headerTitle={
  185. <>
  186. <PermissionButton
  187. onClick={() => {
  188. const url = `${getMenuPathByParams(MENUS_CODE['iot-card/Platform/Detail'])}`;
  189. history.push(url);
  190. }}
  191. style={{ marginRight: 12 }}
  192. isPermission={permission.add}
  193. key="button"
  194. icon={<PlusOutlined />}
  195. type="primary"
  196. >
  197. 新增
  198. </PermissionButton>
  199. </>
  200. }
  201. request={async (params: any) => {
  202. delete params?.total;
  203. const res = await service.getList({
  204. ...params,
  205. sorts: [{ name: 'createTime', order: 'desc' }],
  206. });
  207. return {
  208. code: res.status,
  209. result: res.result,
  210. status: res.status,
  211. };
  212. }}
  213. />
  214. </PageContainer>
  215. );
  216. };
  217. export default Platform;