|  |  |  | 
|---|
|  |  |  | DeleteButton, | 
|---|
|  |  |  | FunctionField, | 
|---|
|  |  |  | Count, | 
|---|
|  |  |  | useNotify, | 
|---|
|  |  |  | useRefresh, | 
|---|
|  |  |  | } from 'react-admin'; | 
|---|
|  |  |  | import { Box, Typography, Stack, useMediaQuery, Tabs, Tab, Divider } from '@mui/material'; | 
|---|
|  |  |  | import { styled } from '@mui/material/styles'; | 
|---|
|  |  |  | 
|---|
|  |  |  | import MyField from "../components/MyField"; | 
|---|
|  |  |  | import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting'; | 
|---|
|  |  |  | import * as Common from '@/utils/common'; | 
|---|
|  |  |  | import ConfirmButton from "../components/ConfirmButton"; | 
|---|
|  |  |  | import ClearIcon from '@mui/icons-material/Clear'; | 
|---|
|  |  |  | import request from '@/utils/request'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ | 
|---|
|  |  |  | '& .css-1vooibu-MuiSvgIcon-root': { | 
|---|
|  |  |  | 
|---|
|  |  |  | '& .column-name': { | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | '& .opt': { | 
|---|
|  |  |  | width: 200 | 
|---|
|  |  |  | width: 130 | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | })); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const filters = [ | 
|---|
|  |  |  | <SearchInput source="condition" alwaysOn />, | 
|---|
|  |  |  | // <SearchInput source="condition" alwaysOn />, | 
|---|
|  |  |  | <TextInput source="groupId" label="table.field.segment.groupId" alwaysOn />, | 
|---|
|  |  |  | <ReferenceInput source="agvId" label="table.field.segment.agvId" reference="agv" alwaysOn> | 
|---|
|  |  |  | <AutocompleteInput label="table.field.segment.agvId" optionText="uuid" filterToQuery={(val) => ({ uuid: val })} /> | 
|---|
|  |  |  | </ReferenceInput>, | 
|---|
|  |  |  | <ReferenceInput source="taskId" label="table.field.segment.taskId" reference="task" alwaysOn> | 
|---|
|  |  |  | <AutocompleteInput label="table.field.segment.taskId" optionText="seqNum" filterToQuery={(val) => ({ seqNum: val })} /> | 
|---|
|  |  |  | </ReferenceInput>, | 
|---|
|  |  |  | <TextInput source="posType" label="table.field.segment.posType" alwaysOn resettable />, | 
|---|
|  |  |  | <DateInput label='common.time.after' source="timeStart" alwaysOn />, | 
|---|
|  |  |  | <DateInput label='common.time.before' source="timeEnd" alwaysOn />, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <TextInput source="uuid" label="table.field.segment.uuid" />, | 
|---|
|  |  |  | <TextInput source="groupId" label="table.field.segment.groupId" />, | 
|---|
|  |  |  | <NumberInput source="travelId" label="table.field.segment.travelId" />, | 
|---|
|  |  |  | <ReferenceInput source="taskId" label="table.field.segment.taskId" reference="task"> | 
|---|
|  |  |  | <AutocompleteInput label="table.field.segment.taskId" optionText="seqNum" filterToQuery={(val) => ({ seqNum: val })} /> | 
|---|
|  |  |  | </ReferenceInput>, | 
|---|
|  |  |  | <ReferenceInput source="agvId" label="table.field.segment.agvId" reference="agv"> | 
|---|
|  |  |  | <AutocompleteInput label="table.field.segment.agvId" optionText="uuid" filterToQuery={(val) => ({ uuid: val })} /> | 
|---|
|  |  |  | </ReferenceInput>, | 
|---|
|  |  |  | <ReferenceInput source="endNode" label="table.field.segment.endNode" reference="code"> | 
|---|
|  |  |  | <AutocompleteInput label="table.field.segment.endNode" optionText="data" filterToQuery={(val) => ({ data: val })} /> | 
|---|
|  |  |  | </ReferenceInput>, | 
|---|
|  |  |  | <TextInput source="posType" label="table.field.segment.posType" />, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <NumberInput source="backpack" label="table.field.segment.backpack" />, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <TextInput label="common.field.memo" source="memo" />, | 
|---|
|  |  |  | 
|---|
|  |  |  | title={"menu.segment"} | 
|---|
|  |  |  | empty={<EmptyData />} | 
|---|
|  |  |  | filters={filters} | 
|---|
|  |  |  | sort={{ field: "create_time", order: "desc" }} | 
|---|
|  |  |  | sort={{ field: "update_time", order: "desc" }} | 
|---|
|  |  |  | actions={( | 
|---|
|  |  |  | <TopToolbar> | 
|---|
|  |  |  | <FilterButton /> | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const TabbedDatagrid = () => { | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  | const { filterValues, setFilters, displayedFilters } = useListContext(); | 
|---|
|  |  |  | const isXSmall = useMediaQuery(theme => | 
|---|
|  |  |  | theme.breakpoints.down('sm') | 
|---|
|  |  |  | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }, [filterValues, setFilters, displayedFilters]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const handleDeprecate = (segmentId) => { | 
|---|
|  |  |  | request.get("/segment/cancel/" + segmentId).then(res => { | 
|---|
|  |  |  | const { code, msg, data } = res.data; | 
|---|
|  |  |  | if (code === 200) { | 
|---|
|  |  |  | notify(msg || 'common.response.success', { type: 'success', messageArgs: { _: msg } }); | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(msg || 'common.response.fail', { type: 'error', messageArgs: { _: msg } }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }).catch(error => { | 
|---|
|  |  |  | notify(error.message || 'common.response.fail', { type: 'error', messageArgs: { _: error.message } }); | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <> | 
|---|
|  |  |  | 
|---|
|  |  |  | <> | 
|---|
|  |  |  | <StyledDatagrid | 
|---|
|  |  |  | preferenceKey='segment' | 
|---|
|  |  |  | bulkActionButtons={() => <BulkDeleteButton mutationMode={OPERATE_MODE} />} | 
|---|
|  |  |  | bulkActionButtons={false} | 
|---|
|  |  |  | rowClick={(id, resource, record) => false} | 
|---|
|  |  |  | expand={() => <SegmentPanel />} | 
|---|
|  |  |  | expandSingle={true} | 
|---|
|  |  |  | 
|---|
|  |  |  | <ReferenceField source="taskId" label="table.field.segment.taskId" reference="task" link={false} sortable={false}> | 
|---|
|  |  |  | <TextField source="seqNum" /> | 
|---|
|  |  |  | </ReferenceField> | 
|---|
|  |  |  | <TextField source="posType" label="table.field.segment.posType" /> | 
|---|
|  |  |  | <NumberField source="backpack" label="table.field.segment.backpack" /> | 
|---|
|  |  |  | <TextField source="posType" label="table.field.segment.posType" sortable={false} /> | 
|---|
|  |  |  | <NumberField source="backpack" label="table.field.segment.backpack" sortable={false} /> | 
|---|
|  |  |  | <NumberField source="algoTime" label="table.field.segment.algoTime" sortable={false} /> | 
|---|
|  |  |  | <ReferenceField source="endNode" label="table.field.segment.endNode" reference="code" link={false} sortable={false}> | 
|---|
|  |  |  | <TextField source="data" /> | 
|---|
|  |  |  | </ReferenceField> | 
|---|
|  |  |  | 
|---|
|  |  |  | {translate(tabs.find(item => item.id === record.state)?.name)} | 
|---|
|  |  |  | </> | 
|---|
|  |  |  | )} /> | 
|---|
|  |  |  | <NumberField source="serial" label="table.field.segment.serial" /> | 
|---|
|  |  |  | <NumberField source="serial" label="table.field.segment.serial" sortable={false} /> | 
|---|
|  |  |  | <ReferenceField source="updateBy" label="common.field.updateBy" reference="user" link={false} sortable={false}> | 
|---|
|  |  |  | <TextField source="nickname" /> | 
|---|
|  |  |  | </ReferenceField> | 
|---|
|  |  |  | 
|---|
|  |  |  | <DateField source="createTime" label="common.field.createTime" showTime /> | 
|---|
|  |  |  | <BooleanField source="statusBool" label="common.field.status" sortable={false} /> | 
|---|
|  |  |  | <TextField source="memo" label="common.field.memo" sortable={false} /> | 
|---|
|  |  |  | {/* <FunctionField label="common.field.opt" cellClassName="opt" render={record => ( | 
|---|
|  |  |  | <> | 
|---|
|  |  |  | </> | 
|---|
|  |  |  | )} /> */} | 
|---|
|  |  |  | {( | 
|---|
|  |  |  | filterValues.state === 'INIT' | 
|---|
|  |  |  | || filterValues.state === 'WAITING' | 
|---|
|  |  |  | || filterValues.state === 'RUNNING' | 
|---|
|  |  |  | ) && ( | 
|---|
|  |  |  | <FunctionField label="common.field.opt" cellClassName="opt" render={record => ( | 
|---|
|  |  |  | <> | 
|---|
|  |  |  | <ConfirmButton | 
|---|
|  |  |  | label="common.action.deprecate" | 
|---|
|  |  |  | size="small" | 
|---|
|  |  |  | color="inherit" | 
|---|
|  |  |  | startIcon={<ClearIcon />} | 
|---|
|  |  |  | sx={{ | 
|---|
|  |  |  | padding: '1px', | 
|---|
|  |  |  | fontSize: '.75rem', | 
|---|
|  |  |  | '& .MuiButton-startIcon': { | 
|---|
|  |  |  | marginRight: '2px' | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | data={record.id} | 
|---|
|  |  |  | onConfirm={() => { | 
|---|
|  |  |  | handleDeprecate(record.id); | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </> | 
|---|
|  |  |  | )} /> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  | </StyledDatagrid> | 
|---|
|  |  |  | </> | 
|---|
|  |  |  | )} | 
|---|