index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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: 'pages.cloud.duerOS.applianceType',
  80. defaultMessage: '设备类型',
  81. }),
  82. dataIndex: 'applianceType',
  83. },
  84. {
  85. title: intl.formatMessage({
  86. id: 'pages.cloud.duerOS.manufacturerName',
  87. defaultMessage: '厂家名称',
  88. }),
  89. dataIndex: 'manufacturerName',
  90. },
  91. {
  92. title: intl.formatMessage({
  93. id: 'pages.cloud.duerOS.version',
  94. defaultMessage: '动作数量',
  95. }),
  96. dataIndex: 'version',
  97. },
  98. {
  99. title: intl.formatMessage({
  100. id: 'pages.data.option',
  101. defaultMessage: '操作',
  102. }),
  103. valueType: 'option',
  104. align: 'center',
  105. width: 200,
  106. render: (text, record) => Tools(record, 'table'),
  107. },
  108. ];
  109. return (
  110. <PageContainer>
  111. <SearchComponent<DuerOSItem>
  112. field={columns}
  113. target="northbound-dueros"
  114. onSearch={(data) => {
  115. actionRef.current?.reset?.();
  116. setSearchParams(data);
  117. }}
  118. />
  119. <ProTableCard<DuerOSItem>
  120. rowKey="id"
  121. search={false}
  122. columns={columns}
  123. actionRef={actionRef}
  124. params={searchParams}
  125. options={{ fullScreen: true }}
  126. request={(params) =>
  127. service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
  128. }
  129. cardRender={(record) => <DuerOSCard {...record} action={Tools(record, 'card')} />}
  130. headerTitle={
  131. <Space>
  132. <PermissionButton
  133. isPermission={true}
  134. onClick={() => {
  135. history.push(getMenuPathByParams(MENUS_CODE['Northbound/DuerOS/Detail']));
  136. }}
  137. key="button"
  138. icon={<PlusOutlined />}
  139. type="primary"
  140. >
  141. {intl.formatMessage({
  142. id: 'pages.data.option.add',
  143. defaultMessage: '新增',
  144. })}
  145. </PermissionButton>
  146. </Space>
  147. }
  148. />
  149. {/*<Save/>*/}
  150. </PageContainer>
  151. );
  152. };