index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import BaseService from '@/utils/BaseService';
  3. import { useRef } from 'react';
  4. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  5. import { Popconfirm, Tooltip } from 'antd';
  6. import {
  7. CloseCircleOutlined,
  8. EditOutlined,
  9. MinusOutlined,
  10. PlayCircleOutlined,
  11. } from '@ant-design/icons';
  12. import BaseCrud from '@/components/BaseCrud';
  13. import { CurdModel } from '@/components/BaseCrud/model';
  14. import type { OnenetItem } from '@/pages/cloud/Onenet/typings';
  15. import { useIntl } from '@@/plugin-locale/localeExports';
  16. import { onlyMessage } from '@/utils/util';
  17. export const service = new BaseService<OnenetItem>('one-net/product');
  18. const stateIconMap = {
  19. enabled: <CloseCircleOutlined />,
  20. disabled: <PlayCircleOutlined />,
  21. };
  22. const Onenet = () => {
  23. const intl = useIntl();
  24. const actionRef = useRef<ActionType>();
  25. const columns: ProColumns<OnenetItem>[] = [
  26. {
  27. dataIndex: 'index',
  28. valueType: 'indexBorder',
  29. width: 48,
  30. },
  31. {
  32. title: intl.formatMessage({
  33. id: 'pages.table.name',
  34. defaultMessage: '名称',
  35. }),
  36. align: 'center',
  37. dataIndex: 'name',
  38. },
  39. {
  40. title: intl.formatMessage({
  41. id: 'pages.searchTable.titleStatus',
  42. defaultMessage: '状态',
  43. }),
  44. align: 'center',
  45. dataIndex: 'state.text',
  46. },
  47. {
  48. title: intl.formatMessage({
  49. id: 'pages.table.description',
  50. defaultMessage: '说明',
  51. }),
  52. align: 'center',
  53. dataIndex: 'description',
  54. },
  55. {
  56. title: intl.formatMessage({
  57. id: 'pages.data.option',
  58. defaultMessage: '操作',
  59. }),
  60. valueType: 'option',
  61. align: 'center',
  62. width: 200,
  63. render: (text, record) => [
  64. <a key="editable" onClick={() => CurdModel.update(record)}>
  65. <Tooltip
  66. title={intl.formatMessage({
  67. id: 'pages.data.option.edit',
  68. defaultMessage: '编辑',
  69. })}
  70. >
  71. <EditOutlined />
  72. </Tooltip>
  73. </a>,
  74. <a key="status">
  75. <Popconfirm
  76. title={intl.formatMessage({
  77. id: `pages.data.option.${
  78. record.state.value === 'disabled' ? 'enabled' : 'disabled'
  79. }.tips`,
  80. defaultMessage: `确认${record.state.value === 'disabled' ? '启' : '禁'}用?`,
  81. })}
  82. onConfirm={async () => {
  83. onlyMessage(
  84. intl.formatMessage({
  85. id: 'pages.data.option.success',
  86. defaultMessage: '操作成功!',
  87. }),
  88. );
  89. actionRef.current?.reload();
  90. }}
  91. >
  92. <Tooltip
  93. title={intl.formatMessage({
  94. id: `pages.data.option.${
  95. record.state.value === 'enabled' ? 'disabled' : 'enabled'
  96. }`,
  97. defaultMessage: record.state.text,
  98. })}
  99. >
  100. {stateIconMap[record.state.value]}
  101. </Tooltip>
  102. </Popconfirm>
  103. </a>,
  104. <a>
  105. <Tooltip
  106. title={intl.formatMessage({
  107. id: 'pages.data.option.remove',
  108. defaultMessage: '删除',
  109. })}
  110. >
  111. <MinusOutlined />
  112. </Tooltip>
  113. </a>,
  114. ],
  115. },
  116. ];
  117. const schema = {};
  118. return (
  119. <PageContainer>
  120. <BaseCrud<OnenetItem>
  121. columns={columns}
  122. service={service}
  123. title={intl.formatMessage({
  124. id: 'pages.cloud.onenet',
  125. defaultMessage: 'Onenet',
  126. })}
  127. schema={schema}
  128. actionRef={actionRef}
  129. />
  130. </PageContainer>
  131. );
  132. };
  133. export default Onenet;