| | |
| | | import MyCreateButton from "../../components/MyCreateButton"; |
| | | import MyExportButton from '../../components/MyExportButton'; |
| | | import InitButton from './InitButton'; |
| | | import BatchModal from './BatchModal'; |
| | | import PageDrawer from "../../components/PageDrawer"; |
| | | import MyField from "../../components/MyField"; |
| | | import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting'; |
| | | import * as Common from '@/utils/common'; |
| | | import DashboardIcon from '@mui/icons-material/Dashboard'; |
| | | import EditIcon from '@mui/icons-material/Edit'; |
| | | import request from '@/utils/request'; |
| | | |
| | | const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ |
| | |
| | | > |
| | | <StyledDatagrid |
| | | preferenceKey='loc' |
| | | bulkActionButtons={() => <BulkDeleteButton mutationMode={OPERATE_MODE} />} |
| | | rowClick={(id, resource, record) => false} |
| | | bulkActionButtons={ |
| | | <> |
| | | <BatchButton /> |
| | | <BulkDeleteButton /> |
| | | </> |
| | | } |
| | | rowClick={() => false} |
| | | expand={() => <LocPanel />} |
| | | expandSingle={true} |
| | | omit={['id', 'createTime', 'createBy', 'memo']} |
| | | > |
| | | <NumberField source="id" /> |
| | |
| | | |
| | | ) |
| | | } |
| | | |
| | | const BatchButton = () => { |
| | | const record = useRecordContext(); |
| | | const notify = useNotify(); |
| | | const refresh = useRefresh(); |
| | | const { selectedIds } = useListContext(); |
| | | console.log(selectedIds) |
| | | |
| | | const [createDialog, setCreateDialog] = useState(false); |
| | | |
| | | return ( |
| | | <> |
| | | <Button onClick={() => setCreateDialog(true)} label={"toolbar.batch"}> |
| | | <EditIcon /> |
| | | </Button> |
| | | |
| | | <BatchModal |
| | | open={createDialog} |
| | | setOpen={setCreateDialog} |
| | | /> |
| | | </> |
| | | |
| | | ) |
| | | } |
| | | const CustomBulkActionButton = () => { |
| | | const { selectedIds } = useListContext(); |
| | | const notify = useNotify(); |
| | | const refresh = useRefresh(); |
| | | |
| | | const handleCustomBulkAction = async () => { |
| | | if (selectedIds.length === 0) { |
| | | notify('请选择要操作的记录'); |
| | | return; |
| | | } |
| | | // 这里写具体的批量操作逻辑,例如向服务器发送请求 |
| | | try { |
| | | const res = await request.post('/loc/bulk-action', { ids: selectedIds }); |
| | | if (res?.data?.code === 200) { |
| | | refresh(); |
| | | notify('批量操作成功'); |
| | | } else { |
| | | notify(res.data.msg); |
| | | } |
| | | } catch (error) { |
| | | notify('批量操作失败,请稍后重试'); |
| | | } |
| | | }; |
| | | |
| | | return ( |
| | | <Button onClick={handleCustomBulkAction} label="自定义批量操作"> |
| | | {/* 可以添加自定义图标 */} |
| | | <EditIcon /> |
| | | </Button> |
| | | ); |
| | | }; |