import { ProColumns, ActionType } from '@ant-design/pro-table'; import { Button, Modal, Space, Switch, Tag } from 'antd'; import React, { useRef } from 'react'; import Truly from '../../components/Truly'; import { OPTIONS } from '../../constants'; import { isFalse, isTrue } from '../../utils/auth'; import EditForm from './EditForm'; import BaseTable from '../../components/BaseTable'; import { RoleFields, delApi, changeStatusApi, getListApi } from './services'; import { getMenuSelections } from '../../services'; import { sessionStore } from '../../utils/store'; import { useRequest } from 'ahooks'; const Page: React.FC = () => { const actionRef = useRef(); const appId: string = sessionStore.get('current-appId'); const { data: menuList } = useRequest(() => getMenuSelections(appId)); const onDelete = (record: RoleFields) => { Modal.confirm({ title: '操作提示', content: `是否确认删除角色名称为"${record.roleName}"的数据项?`, maskClosable: true, onOk: async () => { await delApi(record.roleId); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const columns: ProColumns[] = [ { title: '角色名称', dataIndex: 'roleName', ellipsis: true, }, { title: '角色类别', dataIndex: 'roleType', valueType: 'select', hideInSearch: true, ellipsis: true, fieldProps: { options: OPTIONS.OPTIONS_ROLE, }, }, { title: '权限字符', dataIndex: 'roleKey', ellipsis: true, }, { title: '显示顺序', dataIndex: 'roleSort', hideInSearch: true, ellipsis: true, }, { title: '状态', dataIndex: 'status', hideInTable: true, valueType: 'select', fieldProps: { options: OPTIONS.OPTIONS_AVAILABLE, }, }, { title: '状态', dataIndex: 'status', hideInSearch: true, ellipsis: true, render: (_, record) => { if (isTrue('administration:role:switch')) { return ( { const { roleId, status: preStatus } = record; const status = preStatus === '1' ? '2' : '1'; await changeStatusApi({ roleId, status }); actionRef.current?.reload(); }} /> ); } else if (record.status === '1') { return 启用; } return 停用; }, }, { title: '创建时间', key: 'showTime', dataIndex: 'createTime', valueType: 'dateTime', hideInSearch: true, ellipsis: true, }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateRange', hideInTable: true, search: { transform: (value) => { return { 'params[beginTime]': value[0], 'params[endTime]': value[1], }; }, }, }, { title: '操作', dataIndex: 'option', valueType: 'option', width: 120, hideInTable: isFalse( 'administration:role:update', 'administration:role:delete', ), fixed: 'right', render: (_, record) => ( 编辑} onSubmit={() => { actionRef.current?.reload(); }} > ), }, ]; return ( rowKey={'roleId'} actionRef={actionRef} toolBarRender={() => [ 新增} onSubmit={() => { actionRef.current?.reload(); }} > , ]} columns={columns} request={async (params) => { const { current: pageNum, ...rest } = params; const { total = 0, data = [] } = await getListApi({ ...rest, pageNum, }); return { data, total, }; }} /> ); }; export default Page;