import { ProColumns, ActionType } from '@ant-design/pro-table'; import { Button, Modal, Space, Switch } from 'antd'; import React, { useRef, useState } from 'react'; import { OPTIONS } from '../../constants'; import AddForm from './AddForm'; import EditForm from './EditForm'; import BaseTable from '../../components/BaseTable'; import { ButtonFields, delApi, updateApi, getListApi } from './services'; const Page: React.FC = () => { const actionRef = useRef(); const [selectedRows, setSelectedRows] = useState([]); const onDelete = (record: ButtonFields) => { Modal.confirm({ title: '操作提示', content: `是否确认删除按钮名称为"${record.buttonName}"的数据项?`, maskClosable: true, onOk: async () => { await delApi([record.buttonId]); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const onBatchDelete = () => { const keys = selectedRows.map((item) => item.buttonId); Modal.confirm({ title: '操作提示', content: `是否确认执行批量删除操作?`, maskClosable: true, onOk: async () => { await delApi(keys); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const columns: ProColumns[] = [ { title: '菜单名称', dataIndex: 'menuName', ellipsis: true, }, { title: '菜单路由', dataIndex: 'menuPath', ellipsis: true, }, { title: '按钮名称', dataIndex: 'buttonName', ellipsis: true, }, { title: '权限字符', dataIndex: 'perms', hideInSearch: true, ellipsis: true, }, { title: '状态', dataIndex: 'status', hideInTable: true, valueType: 'select', request: async () => { return OPTIONS.OPTIONS_AVAILABLE; }, }, { title: '状态', dataIndex: 'status', hideInSearch: true, ellipsis: true, render: (_, record) => { return ( { const { buttonId, status: preStatus } = record; const status = preStatus === '1' ? '2' : '1'; await updateApi({ buttonId, status }); actionRef.current?.reload(); }} /> ); }, }, { title: '创建时间', key: 'showTime', dataIndex: 'createTime', valueType: 'dateTime', hideInSearch: true, ellipsis: true, }, { title: '操作', dataIndex: 'option', valueType: 'option', width: 120, fixed: 'right', render: (_, record) => ( 编辑} onOk={() => { actionRef.current?.reload(); }} > ), }, ]; return ( rowKey={'buttonId'} actionRef={actionRef} rowSelection={{ onChange: (keys, rows) => setSelectedRows(rows) }} toolBarRender={() => [ { actionRef.current?.reload(); }} > , , ]} columns={columns} request={async (params) => { const { current: pageNum, ...rest } = params; const { total = 0, data = [] } = await getListApi({ ...rest, pageNum, }); actionRef.current?.clearSelected?.(); return { data, total, }; }} /> ); }; export default Page;