#
vincentlu
3 天以前 c65a357fc8b907af755e1ef6a2c201e31eb71e94
zy-acs-flow/src/page/task/TaskList.jsx
@@ -30,8 +30,12 @@
    ReferenceArrayInput,
    AutocompleteInput,
    DeleteButton,
    FunctionField,
    Pagination,
    useNotify,
    useRefresh,
} from 'react-admin';
import { Box, Typography, Card, Stack } from '@mui/material';
import { Box, Chip, Card, Stack, LinearProgress } from '@mui/material';
import { styled } from '@mui/material/styles';
import TaskCreate from "./TaskCreate";
import TaskPanel from "./TaskPanel";
@@ -40,9 +44,14 @@
import MyExportButton from '../components/MyExportButton';
import PageDrawer from "../components/PageDrawer";
import MyField from "../components/MyField";
import { PAGE_DRAWER_WIDTH, OPERATE_MODE } from '@/config/setting';
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting';
import * as Common from '@/utils/common';
import TaskListAside from "./TaskListAside";
import { getTaskStsChipColor } from '@/utils/color-util';
import ConfirmButton from "../components/ConfirmButton";
import ClearIcon from '@mui/icons-material/Clear';
import CheckIcon from '@mui/icons-material/Check';
import request from '@/utils/request';
const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
    '& .css-1vooibu-MuiSvgIcon-root': {
@@ -62,35 +71,49 @@
    },
}));
const UPLINK_STATUS_CHOICES = [
    { id: 'NONE', name: 'page.task.enums.uplinkSts.NONE', color: 'default' },
    { id: 'PENDING', name: 'page.task.enums.uplinkSts.PENDING', color: 'warning' },
    { id: 'SENDING', name: 'page.task.enums.uplinkSts.SENDING', color: 'info' },
    { id: 'SUCCESS', name: 'page.task.enums.uplinkSts.SUCCESS', color: 'success' },
    { id: 'FAILED', name: 'page.task.enums.uplinkSts.FAILED', color: 'error' },
    { id: 'SKIPPED', name: 'page.task.enums.uplinkSts.SKIPPED', color: 'secondary' },
];
const UPLINK_STATUS_MAP = UPLINK_STATUS_CHOICES.reduce((acc, item) => {
    acc[item.id] = item;
    return acc;
}, {});
const filters = [
    <SearchInput source="condition" alwaysOn />,
    // <SearchInput source="condition" alwaysOn />,
    <DateInput label='common.time.after' source="timeStart" alwaysOn />,
    <DateInput label='common.time.before' source="timeEnd" alwaysOn />,
    <TextInput source="uuid" label="table.field.task.uuid" />,
    <ReferenceInput source="busId" label="table.field.task.busId" reference="bus">
        <AutocompleteInput label="table.field.task.busId" optionText="seqNum" filterToQuery={(val) => ({ seqNum: val })} />
    // <TextInput source="uuid" label="table.field.task.uuid" />,
    <ReferenceInput source="busId" label="table.field.task.busId" reference="bus" >
        <AutocompleteInput label="table.field.task.busId" optionText="busNo" filterToQuery={(val) => ({ seqNum: val })} />
    </ReferenceInput>,
    <TextInput source="seqNum" label="table.field.task.seqNum" />,
    <NumberInput source="priority" label="table.field.task.priority" />,
    <TextInput source="name" label="table.field.task.name" />,
    // <TextInput source="name" label="table.field.task.name" />,
    <ReferenceInput source="taskSts" label="table.field.task.taskSts" reference="taskSts">
        <AutocompleteInput label="table.field.task.taskSts" optionText="name" filterToQuery={(val) => ({ name: val })} />
    </ReferenceInput>,
    <ReferenceInput source="taskType" label="table.field.task.taskType" reference="taskType">
        <AutocompleteInput label="table.field.task.taskType" optionText="name" filterToQuery={(val) => ({ name: val })} />
    </ReferenceInput>,
    <ReferenceInput source="agvId" label="table.field.task.agvId" reference="agv">
    <ReferenceInput source="agvId" label="table.field.task.agvId" reference="agv" alwaysOn>
        <AutocompleteInput label="table.field.task.agvId" optionText="uuid" filterToQuery={(val) => ({ uuid: val })} />
    </ReferenceInput>,
    <DateInput source="ioTime" label="table.field.task.ioTime" />,
    <DateInput source="startTime" label="table.field.task.startTime" />,
    <DateInput source="endTime" label="table.field.task.endTime" />,
    <DateInput source="errTime" label="table.field.task.errTime" />,
    // <DateInput source="ioTime" label="table.field.task.ioTime" />,
    // <DateInput source="startTime" label="table.field.task.startTime" />,
    // <DateInput source="endTime" label="table.field.task.endTime" />,
    // <DateInput source="errTime" label="table.field.task.errTime" />,
    <ReferenceInput source="oriSta" label="table.field.task.oriSta" reference="sta">
        <AutocompleteInput label="table.field.task.oriSta" optionText="staNo" filterToQuery={(val) => ({ staNo: val })} />
    </ReferenceInput>,
    <ReferenceInput source="oriLoc" label="table.field.task.oriLoc" reference="loc">
    <ReferenceInput source="oriLoc" label="table.field.task.oriLoc" reference="loc" alwaysOn>
        <AutocompleteInput label="table.field.task.oriLoc" optionText="locNo" filterToQuery={(val) => ({ locNo: val })} />
    </ReferenceInput>,
    <ReferenceInput source="oriCode" label="table.field.task.oriCode" reference="code">
@@ -99,15 +122,16 @@
    <ReferenceInput source="destSta" label="table.field.task.destSta" reference="sta">
        <AutocompleteInput label="table.field.task.destSta" optionText="staNo" filterToQuery={(val) => ({ staNo: val })} />
    </ReferenceInput>,
    <ReferenceInput source="destLoc" label="table.field.task.destLoc" reference="loc">
    <ReferenceInput source="destLoc" label="table.field.task.destLoc" reference="loc" alwaysOn>
        <AutocompleteInput label="table.field.task.destLoc" optionText="locNo" filterToQuery={(val) => ({ locNo: val })} />
    </ReferenceInput>,
    <ReferenceInput source="destCode" label="table.field.task.destCode" reference="code">
        <AutocompleteInput label="table.field.task.destCode" optionText="data" filterToQuery={(val) => ({ data: val })} />
    </ReferenceInput>,
    <TextInput source="emptyMk" label="table.field.task.emptyMk" />,
    <SelectInput source="uplinkSts" label="table.field.task.uplinkSts" choices={UPLINK_STATUS_CHOICES} />,
    <TextInput source="zpallet" label="table.field.task.zpallet" />,
    <TextInput source="phase" label="table.field.task.phase" />,
    // <TextInput source="phase" label="table.field.task.phase" />,
    <TextInput source="errDesc" label="table.field.task.errDesc" />,
    <TextInput label="common.field.memo" source="memo" />,
@@ -121,9 +145,220 @@
    />,
]
const TaskList = () => {
const TaskListContent = () => {
    const translate = useTranslate();
    const notify = useNotify();
    const refresh = useRefresh();
    const { isLoading } = useListContext();
    const [taskStsByComplete, setTaskStsByComplete] = useState(null);
    const [taskStsByCancel, setTaskStsByCancel] = useState(null);
    useEffect(() => {
        request.post('/taskSts/list', {
            uuid: 'COMPLETE'
        }, {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }).then(res => {
            setTaskStsByComplete(res.data.data[0]?.id);
        })
        request.post('/taskSts/list', {
            uuid: 'CANCEL'
        }, {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }).then(res => {
            setTaskStsByCancel(res.data.data[0]?.id);
        })
    }, []);
    const onComplete = (taskId) => {
        request.get("/task/complete/" + taskId).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 } });
        })
    }
    const onCancel = (taskId) => {
        request.get("/task/cancel/" + taskId).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 (
        <Box sx={{ position: 'relative' }}>
            {isLoading && (
                <LinearProgress
                    sx={{
                        height: "2px",
                        position: 'absolute',
                        top: 0,
                        left: 0,
                        right: 0,
                    }}
                />
            )}
            <StyledDatagrid
                preferenceKey='task'
                bulkActionButtons={false}
                rowClick={(id, resource, record) => false}
                expand={() => <TaskPanel />}
                expandSingle={true}
                omit={['id', 'uuid', 'startTime', 'endTime', 'errTime', 'emptyMk', 'zpallet',
                    'oriSta', 'oriLoc', 'oriCode', 'destSta', 'destLoc', 'destCode', 'errDesc',
                    'updateTime', 'updateBy', 'ioTime', 'createBy', 'statusBool', 'memo']}
            >
                <NumberField source="id" />
                <TextField source="uuid" label="table.field.task.uuid" sortable={false} />
                <TextField source="seqNum" label="table.field.task.seqNum" sortable={false} />
                <ReferenceField source="busId" label="table.field.task.busId" reference="bus" link={false} sortable={false}>
                    <TextField source="busNo" />
                </ReferenceField>
                <ReferenceField source="agvId" label="table.field.task.agvId" reference="agv" link={false} sortable={false}>
                    <TextField source="uuid" />
                </ReferenceField>
                {/* <TextField source="name" label="table.field.task.name" /> */}
                <ReferenceField source="taskType" label="table.field.task.taskType" reference="taskType" link={false} sortable={false}>
                    <TextField source="name" />
                </ReferenceField>
                {/* <ReferenceField source="taskSts" label="table.field.task.taskSts" reference="taskSts" link={false} sortable={false}>
                        <TextField source="name" />
                    </ReferenceField> */}
                <ReferenceField source="taskSts" label="table.field.task.taskSts" reference="taskSts" link={false} sortable={true}>
                    <FunctionField render={record => (
                        <Chip
                            label={record.name}
                            variant="outlined"
                            size="small"
                            color={getTaskStsChipColor(record.name)}
                            sx={{ fontSize: '0.75rem' }}
                        />
                    )} />
                    {/* <TextField source="name" /> */}
                </ReferenceField>
                <DateField source="ioTime" label="table.field.task.ioTime" showTime sortable={false} />
                <DateField source="startTime" label="table.field.task.startTime" showTime sortable={false} />
                <DateField source="endTime" label="table.field.task.endTime" showTime sortable={false} />
                <DateField source="errTime" label="table.field.task.errTime" showTime sortable={false} />
                <ReferenceField source="oriSta" label="table.field.task.oriSta" reference="sta" link={false} sortable={false}>
                    <TextField source="staNo" />
                </ReferenceField>
                <ReferenceField source="oriLoc" label="table.field.task.oriLoc" reference="loc" link={false} sortable={false}>
                    <TextField source="locNo" />
                </ReferenceField>
                <ReferenceField source="oriCode" label="table.field.task.oriCode" reference="code" link={false} sortable={false}>
                    <TextField source="data" />
                </ReferenceField>
                <ReferenceField source="destSta" label="table.field.task.destSta" reference="sta" link={false} sortable={false}>
                    <TextField source="staNo" />
                </ReferenceField>
                <ReferenceField source="destLoc" label="table.field.task.destLoc" reference="loc" link={false} sortable={false}>
                    <TextField source="locNo" />
                </ReferenceField>
                <ReferenceField source="destCode" label="table.field.task.destCode" reference="code" link={false} sortable={false}>
                    <TextField source="data" />
                </ReferenceField>
                <TextField source="oriDesc" label="table.field.task.oriDesc" sortable={false} />
                <TextField source="destDesc" label="table.field.task.destDesc" sortable={false} />
                <NumberField source="priority" label="table.field.task.priority" sortable={false} />
                <FunctionField
                    label="table.field.task.uplinkSts"
                    sortable={false}
                    render={record => {
                        const meta = UPLINK_STATUS_MAP[record?.uplinkSts];
                        return (
                            <Chip
                                label={meta?.name ? translate(meta.name) : translate('common.enums.na')}
                                variant="outlined"
                                size="small"
                                color={meta?.color ?? 'default'}
                                sx={{ fontSize: '0.75rem' }}
                            />
                        );
                    }}
                />
                <TextField source="emptyMk" label="table.field.task.emptyMk" sortable={false} />
                <TextField source="zpallet" label="table.field.task.zpallet" sortable={false} />
                <TextField source="errDesc" label="table.field.task.errDesc" sortable={false} />
                <ReferenceField source="updateBy" label="common.field.updateBy" reference="user" link={false} sortable={false}>
                    <TextField source="nickname" />
                </ReferenceField>
                <DateField source="updateTime" label="common.field.updateTime" showTime />
                <ReferenceField source="createBy" label="common.field.createBy" reference="user" link={false} sortable={false}>
                    <TextField source="nickname" />
                </ReferenceField>
                <DateField source="createTime" label="common.field.createTime" showTime sortable={false} />
                <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 => (
                    (record.taskSts !== taskStsByComplete && record.taskSts !== taskStsByCancel) && (
                        <>
                            <ConfirmButton
                                label="common.action.complete"
                                size="small"
                                color="primary"
                                startIcon={<CheckIcon />}
                                sx={{
                                    padding: '1px',
                                    fontSize: '.75rem',
                                    '& .MuiButton-startIcon': {
                                        marginRight: '2px'
                                    },
                                    mr: 1
                                }}
                                data={record.seqNum}
                                onConfirm={() => {
                                    onComplete(record.id);
                                }}
                            />
                            <ConfirmButton
                                label="ra.action.cancel"
                                size="small"
                                color="error"
                                startIcon={<ClearIcon />}
                                sx={{
                                    padding: '1px',
                                    fontSize: '.75rem',
                                    '& .MuiButton-startIcon': {
                                        marginRight: '1.5px'
                                    },
                                }}
                                data={record.seqNum}
                                onConfirm={() => {
                                    onCancel(record.id);
                                }}
                            />
                        </>
                    )
                )} />
            </StyledDatagrid>
        </Box>
    )
}
const TaskList = () => {
    const [createDialog, setCreateDialog] = useState(false);
    const [drawerVal, setDrawerVal] = useState(false);
@@ -141,85 +376,20 @@
                title={"menu.task"}
                empty={<EmptyData onClick={() => { setCreateDialog(true) }} />}
                filters={filters}
                sort={{ field: "create_time", order: "desc" }}
                sort={{ field: "", order: "" }}
                actions={(
                    <TopToolbar>
                        <FilterButton />
                        <MyCreateButton onClick={() => { setCreateDialog(true) }} />
                        {/* <MyCreateButton onClick={() => { setCreateDialog(true) }} /> */}
                        <SelectColumnsButton preferenceKey='task' />
                        <MyExportButton />
                    </TopToolbar>
                )}
                pagination={<Pagination rowsPerPageOptions={[10, 25, 50, 100]} />}
                perPage={25}
                aside={<TaskListAside />}
            >
                <StyledDatagrid
                    preferenceKey='task'
                    bulkActionButtons={() => <BulkDeleteButton mutationMode={OPERATE_MODE} />}
                    rowClick={(id, resource, record) => false}
                    expand={() => <TaskPanel />}
                    expandSingle={true}
                    omit={['id', 'uuid', 'startTime', 'endTime', 'errTime', 'emptyMk', 'zpallet',
                        'updateTime', 'updateBy', 'createTime', 'createBy', 'statusBool', 'memo']}
                >
                    <NumberField source="id" />
                    <TextField source="uuid" label="table.field.task.uuid" />
                    <TextField source="seqNum" label="table.field.task.seqNum" />
                    <ReferenceField source="busId" label="table.field.task.busId" reference="bus" link={false} sortable={false}>
                        <TextField source="seqNum" />
                    </ReferenceField>
                    <ReferenceField source="agvId" label="table.field.task.agvId" reference="agv" link={false} sortable={false}>
                        <TextField source="uuid" />
                    </ReferenceField>
                    {/* <TextField source="name" label="table.field.task.name" /> */}
                    <ReferenceField source="taskType" label="table.field.task.taskType" reference="taskType" link={false} sortable={false}>
                        <TextField source="name" />
                    </ReferenceField>
                    <ReferenceField source="taskSts" label="table.field.task.taskSts" reference="taskSts" link={false} sortable={false}>
                        <TextField source="name" />
                    </ReferenceField>
                    <NumberField source="priority" label="table.field.task.priority" />
                    <DateField source="ioTime" label="table.field.task.ioTime" showTime />
                    <DateField source="startTime" label="table.field.task.startTime" showTime />
                    <DateField source="endTime" label="table.field.task.endTime" showTime />
                    <DateField source="errTime" label="table.field.task.errTime" showTime />
                    <ReferenceField source="oriSta" label="table.field.task.oriSta" reference="sta" link={false} sortable={false}>
                        <TextField source="staNo" />
                    </ReferenceField>
                    <ReferenceField source="oriLoc" label="table.field.task.oriLoc" reference="loc" link={false} sortable={false}>
                        <TextField source="locNo" />
                    </ReferenceField>
                    <ReferenceField source="oriCode" label="table.field.task.oriCode" reference="code" link={false} sortable={false}>
                        <TextField source="data" />
                    </ReferenceField>
                    <ReferenceField source="destSta" label="table.field.task.destSta" reference="sta" link={false} sortable={false}>
                        <TextField source="staNo" />
                    </ReferenceField>
                    <ReferenceField source="destLoc" label="table.field.task.destLoc" reference="loc" link={false} sortable={false}>
                        <TextField source="locNo" />
                    </ReferenceField>
                    <ReferenceField source="destCode" label="table.field.task.destCode" reference="code" link={false} sortable={false}>
                        <TextField source="data" />
                    </ReferenceField>
                    <TextField source="emptyMk" label="table.field.task.emptyMk" />
                    <TextField source="zpallet" label="table.field.task.zpallet" />
                    <TextField source="errDesc" label="table.field.task.errDesc" />
                    <ReferenceField source="updateBy" label="common.field.updateBy" reference="user" link={false} sortable={false}>
                        <TextField source="nickname" />
                    </ReferenceField>
                    <DateField source="updateTime" label="common.field.updateTime" showTime />
                    <ReferenceField source="createBy" label="common.field.createBy" 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} />
                    <WrapperField cellClassName="opt" label="common.field.opt">
                        <EditButton sx={{ padding: '1px', fontSize: '.75rem' }} />
                        <DeleteButton sx={{ padding: '1px', fontSize: '.75rem' }} mutationMode={OPERATE_MODE} />
                    </WrapperField>
                </StyledDatagrid>
                <TaskListContent drawerVal={drawerVal} />
            </List>
            <TaskCreate
                open={createDialog}