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 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, Tag } from 'antd';
  8. import { GetRoleList } from '@/apis/api';
  9. import { Imageprefix } from '@/constants';
  10. const PagesPermissionRoleTable: 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. size='small'
  36. bordered={true}
  37. scroll={{ x: 1300 }}
  38. actionRef={actionRef}
  39. dataSource={list}
  40. columns={[
  41. {
  42. title: 'ID',
  43. dataIndex: 'id',
  44. width: 100,
  45. search: false,
  46. },
  47. {
  48. title: '角色名',
  49. dataIndex: 'name'
  50. },
  51. {
  52. title: '别名',
  53. dataIndex: 'code',
  54. search: false,
  55. },
  56. {
  57. title: '描述',
  58. dataIndex: 'description',
  59. search: false,
  60. },
  61. {
  62. title: '操作',
  63. width: 300,
  64. key: 'option',
  65. valueType: 'option',
  66. fixed: 'right',
  67. render: (_, record, action) => [
  68. <Button key='1' type='link' onClick={() => {
  69. setId(record.id)
  70. dispatch({ type: 'openModel/getOpenModal', payload: true })
  71. }}>编辑</Button>,
  72. <Button key='2' type='link' onClick={() => {
  73. setId(record.id)
  74. dispatch({ type: 'openModel/getOpenDispenseModal', payload: true })
  75. }}>分配权限</Button>,
  76. <Button key='3' type='link' onClick={() => {
  77. }}>删除</Button>
  78. ],
  79. },
  80. ]}
  81. rowKey="id"
  82. pagination={{
  83. current: page,
  84. pageSize: pageSize,
  85. showSizeChanger: true,
  86. total: total,
  87. pageSizeOptions: [9, 18, 27, 99],
  88. onChange(page, pageSize) {
  89. setPage(page)
  90. setPageSize(pageSize)
  91. },
  92. onShowSizeChange(current, size) {
  93. setPage(current)
  94. setPageSize(size)
  95. }
  96. }}
  97. request={async (params = {} as Record<string, any>) =>
  98. GetRoleList({
  99. page: page,
  100. pagesize: pageSize,
  101. sort: 'id',
  102. sortby: 'desc',
  103. keyword: params.name,
  104. }).then(res => {
  105. setList(res.data.roles)
  106. setTotal(res.data.total)
  107. })
  108. }
  109. headerTitle="角色列表"
  110. toolBarRender={() => [
  111. <Button type="primary" onClick={() => {
  112. dispatch({ type: 'openModel/getOpenModal', payload: true })
  113. }}>
  114. 添加角色
  115. </Button>
  116. ]}
  117. />
  118. </ConfigProvider>
  119. </>
  120. );
  121. };
  122. export default connect(({ openModel }: any) => ({
  123. openModel
  124. }))(PagesPermissionRoleTable);