You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import { useRef, useState, useEffect } from 'react';
  2. import { connect, history } from '@umijs/max';
  3. import type { ActionType, ProFormInstance } from '@ant-design/pro-components';
  4. import {
  5. ProTable, TableDropdown
  6. } from '@ant-design/pro-components';
  7. import { Button, Image, ConfigProvider, Popconfirm } from 'antd';
  8. import { GetSysconfigList } from '@/apis/api';
  9. import { Imageprefix } from '@/constants';
  10. import he from 'he';
  11. const PagesSettingSystemTable: React.FC = ({ dispatch, openModel, getId }: any) => {
  12. const actionRef = useRef<ActionType>();
  13. const [list, setList] = useState<object[]>([])
  14. const [total, setTotal] = useState<number>(0)
  15. const [page, setPage] = useState<number>(1)
  16. const [pageSize, setPageSize] = useState<number>(10)
  17. const setId = (id: number) => {
  18. getId(id)
  19. }
  20. useEffect(() => {
  21. if (!openModel.openModal) {
  22. actionRef.current.reload();
  23. }
  24. }, [openModel.openModal])
  25. return (
  26. <>
  27. <ConfigProvider
  28. theme={{
  29. token: {
  30. colorPrimary: '#4FBE70',
  31. colorLink: '#4FBE70',
  32. }
  33. }}
  34. >
  35. <ProTable
  36. size='small'
  37. bordered={true}
  38. scroll={{ y: 480 }}
  39. actionRef={actionRef}
  40. dataSource={list}
  41. columns={[
  42. {
  43. title: 'ID',
  44. dataIndex: 'id',
  45. search: false,
  46. },
  47. {
  48. title: '备注',
  49. dataIndex: 'remark',
  50. search: false,
  51. },
  52. {
  53. title: '配置项',
  54. dataIndex: 'name',
  55. },
  56. {
  57. title: '配置内容',
  58. dataIndex: 'value',
  59. ellipsis: true,
  60. search: false,
  61. },
  62. {
  63. title: '操作',
  64. key: 'option',
  65. valueType: 'option',
  66. render: (_, record, action) => [
  67. <Button key='1' type='link' onClick={() => {
  68. setId(record.id)
  69. dispatch({ type: 'openModel/getOpenModal', payload: true })
  70. }}>编辑</Button>,
  71. <Popconfirm
  72. title="是否删除"
  73. onConfirm={(e) => {
  74. PostActivityaddressDel({ id: record.id }).then(res => {
  75. message.success('删除成功')
  76. actionRef.current?.reload();
  77. })
  78. }}
  79. okText="删除"
  80. cancelText="取消"
  81. >
  82. <Button danger type='link'>删除</Button>
  83. </Popconfirm>
  84. ],
  85. },
  86. ]}
  87. rowKey="id"
  88. pagination={{
  89. current: page,
  90. pageSize: pageSize,
  91. showSizeChanger: true,
  92. total: total,
  93. pageSizeOptions: [9, 18, 27, 99],
  94. onChange(page, pageSize) {
  95. setPage(page)
  96. setPageSize(pageSize)
  97. },
  98. onShowSizeChange(current, size) {
  99. setPage(current)
  100. setPageSize(size)
  101. }
  102. }}
  103. request={async (params = {} as Record<string, any>) =>
  104. GetSysconfigList({
  105. page: page,
  106. pagesize: pageSize,
  107. sort: 'id',
  108. sortby: 'desc',
  109. keyword: params.name,
  110. }).then(res => {
  111. setList(res.data.sysconfigs)
  112. setTotal(res.data.total)
  113. })
  114. }
  115. headerTitle="系统配置"
  116. toolBarRender={() => [
  117. <Button type="primary" onClick={() => {
  118. dispatch({ type: 'openModel/getOpenModal', payload: true })
  119. }}>
  120. 添加配置项
  121. </Button>
  122. ]}
  123. />
  124. </ConfigProvider>
  125. </>
  126. );
  127. };
  128. export default connect(({ openModel }: any) => ({
  129. openModel
  130. }))(PagesSettingSystemTable);