index.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import SearchComponent from '@/components/SearchComponent';
  3. import { useRef, useState } from 'react';
  4. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  5. import { PermissionButton, ProTableCard } from '@/components';
  6. import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
  7. import { useIntl } from '@@/plugin-locale/localeExports';
  8. import { message, Space } from 'antd';
  9. import { DuerOSItem } from '@/pages/Northbound/DuerOS/types';
  10. import DuerOSCard from '@/components/ProTableCard/CardItems/duerOs';
  11. import { history } from '@@/core/history';
  12. import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
  13. import Service from './service';
  14. export const service = new Service('dueros/product');
  15. export default () => {
  16. const actionRef = useRef<ActionType>();
  17. const intl = useIntl();
  18. const [searchParams, setSearchParams] = useState<any>({});
  19. const { permission } = PermissionButton.usePermission('Northbound/DuerOS');
  20. const Tools = (record: any, type: 'card' | 'table') => {
  21. return [
  22. <PermissionButton
  23. key={'update'}
  24. type={'link'}
  25. style={{ padding: 0 }}
  26. isPermission={permission.update}
  27. tooltip={
  28. type === 'table'
  29. ? {
  30. title: intl.formatMessage({
  31. id: 'pages.data.option.edit',
  32. defaultMessage: '编辑',
  33. }),
  34. }
  35. : undefined
  36. }
  37. onClick={() => {
  38. history.push(getMenuPathByParams(MENUS_CODE['Northbound/DuerOS/Detail'], record.id));
  39. }}
  40. >
  41. <EditOutlined />
  42. {type !== 'table' &&
  43. intl.formatMessage({
  44. id: 'pages.data.option.edit',
  45. defaultMessage: '编辑',
  46. })}
  47. </PermissionButton>,
  48. <PermissionButton
  49. key={'delete'}
  50. type={'link'}
  51. style={{ padding: 0 }}
  52. isPermission={permission.delete}
  53. popConfirm={{
  54. title: '确认删除?',
  55. onConfirm: async () => {
  56. await service.remove(record.id);
  57. message.success('删除成功!');
  58. actionRef.current?.reload();
  59. },
  60. }}
  61. tooltip={{
  62. title: '删除',
  63. }}
  64. >
  65. <DeleteOutlined />
  66. </PermissionButton>,
  67. ];
  68. };
  69. const columns: ProColumns<DuerOSItem>[] = [
  70. {
  71. title: intl.formatMessage({
  72. id: 'pages.table.name',
  73. defaultMessage: '名称',
  74. }),
  75. dataIndex: 'name',
  76. },
  77. {
  78. title: intl.formatMessage({
  79. id: 'page.cloud.duerOS.productName',
  80. defaultMessage: '产品',
  81. }),
  82. dataIndex: 'productName',
  83. },
  84. {
  85. title: intl.formatMessage({
  86. id: 'pages.cloud.duerOS.applianceType',
  87. defaultMessage: '设备类型',
  88. }),
  89. dataIndex: 'applianceType',
  90. },
  91. {
  92. title: intl.formatMessage({
  93. id: 'pages.cloud.duerOS.manufacturerName',
  94. defaultMessage: '厂家名称',
  95. }),
  96. dataIndex: 'manufacturerName',
  97. },
  98. {
  99. title: intl.formatMessage({
  100. id: 'pages.cloud.duerOS.version',
  101. defaultMessage: '动作数量',
  102. }),
  103. dataIndex: 'version',
  104. },
  105. {
  106. title: intl.formatMessage({
  107. id: 'pages.data.option',
  108. defaultMessage: '操作',
  109. }),
  110. valueType: 'option',
  111. align: 'center',
  112. width: 200,
  113. render: (text, record) => Tools(record, 'table'),
  114. },
  115. ];
  116. return (
  117. <PageContainer>
  118. <SearchComponent<DuerOSItem>
  119. field={columns}
  120. target="northbound-dueros"
  121. onSearch={(data) => {
  122. actionRef.current?.reset?.();
  123. setSearchParams(data);
  124. }}
  125. />
  126. <ProTableCard<DuerOSItem>
  127. rowKey="id"
  128. search={false}
  129. columns={columns}
  130. actionRef={actionRef}
  131. params={searchParams}
  132. options={{ fullScreen: true }}
  133. request={(params) =>
  134. service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
  135. }
  136. cardRender={(record) => <DuerOSCard {...record} action={Tools(record, 'card')} />}
  137. headerTitle={
  138. <Space>
  139. <PermissionButton
  140. isPermission={true}
  141. onClick={() => {
  142. history.push(getMenuPathByParams(MENUS_CODE['Northbound/DuerOS/Detail']));
  143. }}
  144. key="button"
  145. icon={<PlusOutlined />}
  146. type="primary"
  147. >
  148. {intl.formatMessage({
  149. id: 'pages.data.option.add',
  150. defaultMessage: '新增',
  151. })}
  152. </PermissionButton>
  153. </Space>
  154. }
  155. />
  156. {/*<Save/>*/}
  157. </PageContainer>
  158. );
  159. };