index.tsx 3.6 KB

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