index.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import SearchComponent from '@/components/SearchComponent';
  2. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  3. import ProTable from '@jetlinks/pro-table';
  4. import { useRef, useState } from 'react';
  5. import Service from '@/pages/system/Relationship/service';
  6. import { PageContainer } from '@ant-design/pro-layout';
  7. import { PermissionButton } from '@/components';
  8. import { useIntl } from 'umi';
  9. import { DeleteOutlined, EditOutlined } from '@ant-design/icons';
  10. import Save from './Save';
  11. import { useDomFullHeight } from '@/hooks';
  12. import { onlyMessage } from '@/utils/util';
  13. import { message } from 'antd';
  14. export const service = new Service('relation');
  15. const Relationship = () => {
  16. const intl = useIntl();
  17. const [param, setParam] = useState<any>({});
  18. const [current, setCurrent] = useState<Partial<ReationItem>>({});
  19. const [visible, setVisible] = useState<boolean>(false);
  20. const actionRef = useRef<ActionType>();
  21. const { permission } = PermissionButton.usePermission('system/Relationship');
  22. const { minHeight } = useDomFullHeight(`.relation`, 24);
  23. const columns: ProColumns<ReationItem>[] = [
  24. {
  25. dataIndex: 'name',
  26. title: '名称',
  27. ellipsis: true,
  28. fixed: 'left',
  29. width: '20%',
  30. },
  31. {
  32. dataIndex: 'objectTypeName',
  33. title: '关联方',
  34. ellipsis: true,
  35. },
  36. {
  37. dataIndex: 'targetTypeName',
  38. title: '被关联方',
  39. ellipsis: true,
  40. },
  41. {
  42. dataIndex: 'description',
  43. title: '说明',
  44. ellipsis: true,
  45. },
  46. {
  47. title: '操作',
  48. valueType: 'option',
  49. align: 'center',
  50. width: 200,
  51. fixed: 'right',
  52. render: (text, record) => [
  53. <PermissionButton
  54. isPermission={permission.update}
  55. key="warning"
  56. onClick={() => {
  57. setVisible(true);
  58. setCurrent(record);
  59. }}
  60. type={'link'}
  61. style={{ padding: 0 }}
  62. tooltip={{
  63. title: intl.formatMessage({
  64. id: 'pages.data.option.edit',
  65. defaultMessage: '编辑',
  66. }),
  67. }}
  68. >
  69. <EditOutlined />
  70. </PermissionButton>,
  71. <PermissionButton
  72. isPermission={permission.delete}
  73. style={{ padding: 0 }}
  74. popConfirm={{
  75. title: '确认删除',
  76. onConfirm: async () => {
  77. const resp: any = await service.remove(record.id);
  78. if (resp.status === 200) {
  79. onlyMessage(
  80. intl.formatMessage({
  81. id: 'pages.data.option.success',
  82. defaultMessage: '操作成功!',
  83. }),
  84. );
  85. actionRef.current?.reload();
  86. } else {
  87. message.error(resp.message);
  88. }
  89. },
  90. }}
  91. key="button"
  92. type="link"
  93. >
  94. <DeleteOutlined />
  95. </PermissionButton>,
  96. ],
  97. },
  98. ];
  99. return (
  100. <PageContainer>
  101. <SearchComponent<ReationItem>
  102. field={columns}
  103. target="relationship"
  104. onSearch={(data) => {
  105. actionRef.current?.reload();
  106. setParam(data);
  107. }}
  108. />
  109. <ProTable<ReationItem>
  110. actionRef={actionRef}
  111. params={param}
  112. columns={columns}
  113. search={false}
  114. rowKey="id"
  115. columnEmptyText={''}
  116. scroll={{ x: 1366 }}
  117. tableClassName={'relation'}
  118. tableStyle={{ minHeight }}
  119. request={async (params) => {
  120. return service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] });
  121. }}
  122. headerTitle={[
  123. <PermissionButton
  124. isPermission={permission.add}
  125. key="add"
  126. onClick={() => {
  127. setVisible(true);
  128. setCurrent({});
  129. }}
  130. type="primary"
  131. tooltip={{
  132. title: intl.formatMessage({
  133. id: 'pages.data.option.add',
  134. defaultMessage: '新增',
  135. }),
  136. }}
  137. >
  138. 新增
  139. </PermissionButton>,
  140. ]}
  141. />
  142. {visible && (
  143. <Save
  144. data={current}
  145. close={() => {
  146. setVisible(false);
  147. actionRef.current?.reload();
  148. }}
  149. />
  150. )}
  151. </PageContainer>
  152. );
  153. };
  154. export default Relationship;