import { PageContainer, ProTable } from '@ant-design/pro-components';
|
import { buildProTableDataSource, sendRequest, showDelConfirm } from '@/utils/antdUtils';
|
import { Button, Space } from 'antd';
|
import { useRef, useState } from 'react';
|
import { Access, history, useAccess } from 'umi';
|
import { getList, del, edit, add } from './service'
|
import AddAndEdit from './components/addAndEdit'
|
const Role = () => {
|
|
const actionRef = useRef();
|
const addViewRef = useRef();
|
const [modalVisible, handleModalVisibles] = useState(false);
|
const access = useAccess();
|
|
const columns = [
|
{
|
title: '权限名称',
|
dataIndex: 'name',
|
},
|
{
|
title: '操作',
|
hideInSearch: true,
|
render: (text, record) => {
|
return (
|
<Space>
|
{
|
record.id != 1 &&
|
<Access accessible={access['/system_setting/role_management/edit']}>
|
<Button
|
type="link"
|
onClick={() => {
|
addViewRef.current.refreshData(record);
|
handleModalVisibles(true)
|
}}
|
>
|
编辑
|
</Button>
|
</Access>
|
}
|
{
|
record.id != 1 &&
|
<Access accessible={access['/system_setting/role_management/del']}>
|
<Button
|
type="link"
|
onClick={() => {
|
|
showDelConfirm(async () => {
|
let status = await sendRequest(del, record.id)
|
if (status) {
|
actionRef.current.reload();
|
}
|
}, '确认删除所选信息吗?');
|
}}
|
>
|
删除
|
</Button>
|
</Access>
|
}
|
<Access accessible={access['/system_setting/role_management/detail']}>
|
<Button
|
type="link"
|
onClick={() => {
|
addViewRef.current.refreshData(record, true);
|
handleModalVisibles(true)
|
}}
|
>
|
查看详情
|
</Button>
|
</Access>
|
</Space >
|
);
|
},
|
},
|
]
|
|
return <PageContainer title='角色管理' header={{
|
breadcrumb: {},
|
}}>
|
<ProTable
|
rowKey='id'
|
actionRef={actionRef}
|
columns={columns}
|
pagination={{
|
showSizeChanger: true,
|
showQuickJumper: true,
|
defaultPageSize: 10,
|
}}
|
request={(params) => buildProTableDataSource(getList, params)}
|
toolBarRender={(action, selectRows) => [
|
<Access accessible={access['/system_setting/role_management/add']}>
|
<Space>
|
<Button
|
type="primary"
|
onClick={() => {
|
addViewRef.current.refreshData({});
|
handleModalVisibles(true)
|
}}
|
>
|
添加
|
</Button>
|
</Space>
|
</Access>
|
]}
|
/>
|
<AddAndEdit
|
ref={addViewRef}
|
visible={modalVisible}
|
onSave={async (fileds) => {
|
let success = await sendRequest(add, fileds);
|
if (success) {
|
handleModalVisibles(false);
|
actionRef.current.reload();
|
}
|
addViewRef.current.clean();
|
}}
|
onUpdate={async (fileds) => {
|
let success = await sendRequest(edit, fileds);
|
if (success) {
|
handleModalVisibles(false);
|
actionRef.current.reload();
|
}
|
addViewRef.current.clean();
|
}}
|
onCancel={() => handleModalVisibles(false)}
|
/>
|
</PageContainer>
|
};
|
|
export default Role;
|