import { ProColumns, ActionType } from '@ant-design/pro-table'; import { Button, FormInstance, Modal, Space, Switch, Tag } from 'antd'; import React, { useRef, useState } from 'react'; import { Link } from 'umi'; import Truly from '../../components/Truly'; import { OPTIONS } from '../../constants'; import { isFalse, isTrue } from '../../utils/auth'; import EditForm from './EditForm'; import ImportModal from './ImportModal'; import { pathHolder } from '../../utils/route'; import BaseTable from '../../components/BaseTable'; import { DictTypeFields, delApi, getListApi, refreshCacheApi, updateApi, } from './services'; import { exportExcelApi } from '../Config/services'; const Page: React.FC = () => { const formRef = useRef>(); const actionRef = useRef(); const [query, setQuery] = useState(); const [selectRows, setSelectRows] = useState([]); const onDelete = (record: DictTypeFields) => { Modal.confirm({ title: '操作提示', content: `是否确认删除字典名称为"${record.dictName}"的数据项?`, maskClosable: true, onOk: async () => { await delApi([record.dictId]); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const onBatchDelete = () => { Modal.confirm({ title: '操作提示', content: `是否确认批量删除操作?`, maskClosable: true, onOk: async () => { const keys = selectRows.map((item) => item.dictId); await delApi(keys); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const onRefreshCache = async () => { await refreshCacheApi(); actionRef.current?.reload(); }; const onExport = async () => { Modal.confirm({ title: '操作提示', content: '是否确认导出全部数据?', maskClosable: true, onOk: async () => { await exportExcelApi({ ...query }); }, okText: '确定', cancelText: '取消', }); }; const columns: ProColumns[] = [ { title: '字典名称', dataIndex: 'dictName', ellipsis: true, }, { title: '字典类型', dataIndex: 'dictType', ellipsis: true, render: (text, record) => { return ( {record.dictType} ); }, }, { title: '状态', dataIndex: 'status', hideInTable: true, valueType: 'select', fieldProps: { options: OPTIONS.OPTIONS_STATUS, }, }, { title: '状态', dataIndex: 'status', hideInSearch: true, render: (_, record) => { if (isTrue('sysSetting:dict:switch')) { return ( { const { dictId, dictType, dictName, status: preStatus, } = record; const status = preStatus === '0' ? '1' : '0'; await updateApi({ dictId, status, dictType, dictName, }); actionRef.current?.reload(); }} /> ); } else if (record.status === '0') { return 启用; } return 停用; }, ellipsis: true, }, { title: '备注', dataIndex: 'remark', hideInSearch: true, ellipsis: true, }, { title: '创建时间', key: 'showTime', dataIndex: 'createTime', valueType: 'dateTime', hideInSearch: true, ellipsis: true, }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateRange', hideInTable: true, search: { transform: (value) => { return { beginTime: value[0], endTime: value[1], }; }, }, }, { title: '操作', dataIndex: 'option', valueType: 'option', width: 120, fixed: 'right', hideInTable: isFalse('sysSetting:dict:update', 'sysSetting:dict:delete'), render: (_, record) => ( 编辑} onOk={() => { actionRef.current?.reload(); }} > ), }, ]; return ( rowKey={'dictId'} actionRef={actionRef} formRef={formRef} rowSelection={{ fixed: true, onChange: (selectKeys, selectRows) => setSelectRows(selectRows), }} toolBarRender={() => [ 新增} onOk={() => { actionRef.current?.reload(); }} > , , , 导入} /> , , ]} columns={columns} request={async (params) => { const { current: pageNum, pageSize, ...rest } = params; const querys = { ...rest, pageNum, pageSize, }; setQuery(rest); const { total = 0, data = [] } = await getListApi(querys); actionRef.current?.clearSelected?.(); return { data, total, }; }} /> ); }; export default Page;