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.3KB

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 { getAccount } from '@/apis/api';
  9. import { Imageprefix } from '@/constants';
  10. const PagesPermissionAccountTable: React.FC = ({ dispatch, openModel, getId }: any) => {
  11. const actionRef = useRef<ActionType>();
  12. const [list, setList] = useState<object[]>([])
  13. const [total, setTotal] = useState<number>(0)
  14. const [page, setPage] = useState<number>(1)
  15. const [pageSize, setPageSize] = useState<number>(10)
  16. const setId = (id: number) => {
  17. getId(id)
  18. }
  19. useEffect(() => {
  20. if (!openModel.openModal) {
  21. actionRef.current.reload();
  22. }
  23. }, [openModel.openModal])
  24. return (
  25. <>
  26. <ConfigProvider
  27. theme={{
  28. token: {
  29. colorPrimary: '#4FBE70',
  30. colorLink: '#4FBE70',
  31. }
  32. }}
  33. >
  34. <ProTable
  35. scroll={{ y: 480, x: 'auto' }}
  36. bordered={true}
  37. actionRef={actionRef}
  38. dataSource={list}
  39. search={{ span: 8, labelWidth: 'auto' }}
  40. columns={[
  41. {
  42. title: '手机号码',
  43. dataIndex: 'mobile'
  44. }, {
  45. title: '昵称',
  46. dataIndex: 'nickname',
  47. search: false,
  48. }, {
  49. title: '头像',
  50. dataIndex: 'avatar',
  51. search: false,
  52. }, {
  53. title: '电子邮箱',
  54. dataIndex: 'email',
  55. search: false,
  56. }, {
  57. title: '角色ID',
  58. dataIndex: 'roleids',
  59. search: false,
  60. },
  61. {
  62. title: '操作',
  63. key: 'option',
  64. valueType: 'option',
  65. render: (_, record, action) => [
  66. <Button key='1' type='link' onClick={() => {
  67. setId(record.id)
  68. dispatch({ type: 'openModel/getOpenModal', payload: true })
  69. }}>编辑</Button>,
  70. <Popconfirm
  71. title="是否删除"
  72. onConfirm={(e) => {
  73. PostActivityaddressDel({ id: record.id }).then(res => {
  74. message.success('删除成功')
  75. actionRef.current?.reload();
  76. })
  77. }}
  78. okText="删除"
  79. cancelText="取消"
  80. >
  81. <Button danger type='link'>删除</Button>
  82. </Popconfirm>
  83. ],
  84. },
  85. ]}
  86. rowKey="id"
  87. pagination={{
  88. current: page,
  89. pageSize: pageSize,
  90. showSizeChanger: true,
  91. total: total,
  92. pageSizeOptions: [9, 18, 27, 99],
  93. onChange(page, pageSize) {
  94. setPage(page)
  95. setPageSize(pageSize)
  96. },
  97. onShowSizeChange(current, size) {
  98. setPage(current)
  99. setPageSize(size)
  100. }
  101. }}
  102. request={async (params = {} as Record<string, any>) =>
  103. getAccount({
  104. page: page,
  105. pagesize: pageSize,
  106. sort: 'id',
  107. sortby: 'desc',
  108. keyword: params.mobile,
  109. }).then(res => {
  110. setList(res.data.users)
  111. setTotal(res.data.total)
  112. })
  113. }
  114. headerTitle="账号列表"
  115. toolBarRender={() => [
  116. <Button type="primary" onClick={() => {
  117. dispatch({ type: 'openModel/getOpenModal', payload: true })
  118. }}>
  119. 添加账号
  120. </Button>
  121. ]}
  122. />
  123. </ConfigProvider>
  124. </>
  125. );
  126. };
  127. export default connect(({ openModel }: any) => ({
  128. openModel
  129. }))(PagesPermissionAccountTable);