import { ProColumns, ActionType } from '@ant-design/pro-table'; import { useRequest } from 'ahooks'; import { Button, FormInstance, Modal, Space, Switch, Tag } from 'antd'; import React, { useRef, useState } from 'react'; import { history, useLocation } from 'umi'; 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 { DictDataFields, getDictTypeListApi, exportApi, delApi, updateApi, getListApi, } from './services'; const View: React.FC = () => { const formRef = useRef>(); const actionRef = useRef(); const { query: urlQuerys } = useLocation() as any; const { dictType } = urlQuerys || {}; const [formDictType, setFormDictType] = useState(''); const [query, setQuery] = useState(); const { data: dictTypeList } = useRequest(getDictTypeListApi); const [selectRows, setSelectRows] = useState([]); const onDelete = (record: DictDataFields) => { Modal.confirm({ title: '操作提示', content: `是否确认删除字典标签为"${record.dictLabel}"的数据项?`, maskClosable: true, onOk: async () => { await delApi([record.dictCode]); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const onBatchDelete = () => { Modal.confirm({ title: '操作提示', content: `是否确认批量删除操作?`, maskClosable: true, onOk: async () => { const keys = selectRows.map((item) => item.dictCode); await delApi(keys); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const onExport = async () => { Modal.confirm({ title: '操作提示', content: '是否确认导出全部数据?', maskClosable: true, onOk: async () => { await exportApi({ ...query }); }, okText: '确定', cancelText: '取消', }); }; const columns: ProColumns[] = [ { title: '字典类型', dataIndex: 'dictType', hideInTable: true, valueType: 'select', initialValue: dictType, fieldProps: { showSearch: true, options: dictTypeList || [], }, }, { title: '字典编号', dataIndex: 'dictCode', hideInSearch: true, ellipsis: true, }, { title: '字典标签', dataIndex: 'dictLabel', ellipsis: true, }, { title: '字典键值', dataIndex: 'dictValue', hideInSearch: true, ellipsis: true, }, { title: '字典排序', dataIndex: 'dictSort', hideInSearch: true, ellipsis: true, }, { title: '状态', dataIndex: 'status', hideInTable: true, valueType: 'select', fieldProps: { options: OPTIONS.OPTIONS_STATUS, }, }, { title: '状态', dataIndex: 'status', hideInSearch: true, ellipsis: true, render: (_, record) => { if (isTrue('sysSetting:dict:data:switch')) { return ( { const { dictCode, dictType, dictLabel, dictValue, status: preStatus, } = record; const status = preStatus === '0' ? '1' : '0'; await updateApi({ dictCode, status, dictType, dictLabel, dictValue, }); actionRef.current?.reload(); }} /> ); } else if (record.status === '0') { return 启用; } return 停用; }, }, { title: '备注', dataIndex: 'remark', hideInSearch: true, ellipsis: true, }, { title: '创建时间', key: 'showTime', dataIndex: 'createTime', valueType: 'dateTime', hideInSearch: true, ellipsis: true, }, { title: '操作', dataIndex: 'option', valueType: 'option', width: 120, fixed: 'right', hideInTable: isFalse( 'sysSetting:dict:data:update', 'sysSetting:dict:data:delete', ), render: (_, record) => ( 编辑} onOk={() => { actionRef.current?.reload(); }} > ), }, ]; return ( rowKey={'dictCode'} formRef={formRef} actionRef={actionRef} rowSelection={{ fixed: true, onChange: (selectKeys, selectRows) => setSelectRows(selectRows), }} toolBarRender={() => [ , 新增} onOpen={() => { setFormDictType(formRef.current?.getFieldValue('dictType')); }} onOk={() => { actionRef.current?.reload(); }} > , , , ]} columns={columns} request={async (params) => { const { current: pageNum, pageSize, ...rest } = params; const { total = 0, data = [] } = await getListApi({ ...rest, pageNum, pageSize, }); setQuery(rest); actionRef.current?.clearSelected?.(); return { data, total, }; }} /> ); }; export default View;