import IsBatchDelete from '@/components/BatchOperation/isBatchDelete'; import TableActionCard from '@/components/TableActionCard'; import IsDelete from '@/components/TableActionCard/isDelete'; import { deleteDeviceCategoryDeleteDeviceCategory, deleteDeviceCategoryDeleteDeviceCategoryByIds, postDeviceCategoryGetDeviceCategoryList, } from '@/services/device/DeviceCategory'; import { PlusOutlined } from '@ant-design/icons'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { PageContainer, ProTable } from '@ant-design/pro-components'; import { Access, FormattedMessage, history, useAccess, useIntl } from '@umijs/max'; import { Button, message } from 'antd'; import React, { useRef, useState } from 'react'; import { proTableCommonOptions, proTablePaginationOptions } from '../../../../config/defaultTable'; import { ColumnDrawer } from './components/ColumnDrawer'; import CreateForm from './components/CreateForm'; import UpdateForm from './components/UpdateForm'; const DeviceCategoryList: React.FC = () => { /** * @en-US Pop-up window of new window * @zh-CN 新建窗口的弹窗 * */ const [createModalOpen, setCreateModalOpen] = useState(false); /** * @en-US The pop-up window of the distribution update window * @zh-CN 分布更新窗口的弹窗 * */ const [updateModalOpen, setUpdateModalOpen] = useState(false); const [showDetail, setShowDetail] = useState(false); /** * @en-US International configuration * @zh-CN 国际化配置 * */ const access = useAccess(); const intl = useIntl(); const actionRef = useRef(); // 动态设置每页数量 const [currentPageSize, setCurrentPageSize] = useState(10); const [currentRow, setCurrentRow] = useState(); const [selectedRowsState, setSelectedRows] = useState([]); const handleUpdateModal = () => { if (updateModalOpen) { setUpdateModalOpen(false); setCurrentRow(undefined); } else { setUpdateModalOpen(true); } }; const handleCreateModal = () => { if (createModalOpen) { setCreateModalOpen(false); setCurrentRow(undefined); } else { setCreateModalOpen(true); } }; const handleColumnDrawer = () => { if (showDetail) { setShowDetail(false); setCurrentRow(undefined); } else { setShowDetail(true); } }; const handleDestroy = async (selectedRow: API.DeviceCategory) => { deleteDeviceCategoryDeleteDeviceCategory({ id: selectedRow.id }) .then(() => { message.success(intl.formatMessage({ id: 'common.success', defaultMessage: '$$$' })); actionRef.current?.reload(); }) .catch(() => { message.error(intl.formatMessage({ id: 'common.failure', defaultMessage: '$$$' })); }); }; const columns: ProColumns[] = [ // { // title: , // dataIndex: 'id', // sorter: true, // render: (dom, entity) => { // return ( // { // setCurrentRow(entity); // setShowDetail(true); // }} // > // {dom} // // ); // }, // }, { title: , dataIndex: 'name', hideInSearch: false, }, { title: , dataIndex: 'code', hideInSearch: true, }, { title: ( ), dataIndex: 'remark', hideInSearch: true, }, { title: ( ), dataIndex: 'createTime', sorter: true, hideInSearch: true, valueType: 'dateTime', }, { title: ( ), dataIndex: 'updateTime', sorter: true, hideInSearch: true, valueType: 'dateTime', }, { title: , dataIndex: 'option', valueType: 'option', fixed: 'right', render: (_, record) => [ { setUpdateModalOpen(true); setCurrentRow(record); }} > ), }, { key: 'destroy', renderDom: ( { handleDestroy(record).then(() => {}); }} > ), }, ]} >, ], }, ]; return ( headerTitle={intl.formatMessage({ id: 'pages.searchTable.title', defaultMessage: '$$$', })} options={{ fullScreen: true, setting: true, density: true, reload: true }} actionRef={actionRef} rowKey="key" search={{ labelWidth: proTableCommonOptions.searchLabelWidth, }} onDataSourceChange={(data) => {}} pagination={{ ...proTablePaginationOptions, pageSize: currentPageSize, onChange: (page, pageSize) => setCurrentPageSize(pageSize), }} columnsState={{ persistenceKey: 'device_category_list', persistenceType: 'localStorage', }} tableAlertOptionRender={() => { return ( <> {selectedRowsState?.length > 0 && ( { // TODO 需要;联调删除接口 deleteDeviceCategoryDeleteDeviceCategoryByIds({ ids: selectedRowsState.map((v: API.DeviceCategory) => { return v.id as number; }), }).then(() => { actionRef.current?.reloadAndRest?.(); }); }} /> )} ); }} toolBarRender={() => [ , ]} request={async (params = {}, sort) => { const { current, ...rest } = params; const reqParams = { page: current, desc: false, orderKey: '', ...rest, }; if (sort && Object.keys(sort).length) { reqParams.orderKey = Object.keys(sort)[0]; let sort_select = sort[reqParams.orderKey]; reqParams.desc = sort_select === 'descend'; } let resp = await postDeviceCategoryGetDeviceCategoryList({ ...reqParams }); return { data: resp.data.list.map((v: API.DeviceCategory) => { return { ...v, key: v.id }; }), success: resp.success, total: resp.data.total, current: resp.data.page, pageSize: resp.data.pageSize, }; }} columns={columns} rowSelection={{ onChange: (_, selectedRows) => { setSelectedRows(selectedRows); }, }} /> ); }; export default DeviceCategoryList;