| | |
| | | import React from 'react'; |
| | | import { useForm, Controller } from 'react-hook-form'; |
| | | import { |
| | | Drawer, |
| | | Button, |
| | | TextField, |
| | | Grid, |
| | |
| | | |
| | | const onSubmit = (data) => { |
| | | console.log(data); |
| | | // 提交表单数据的逻辑 |
| | | }; |
| | | |
| | | const taskMode = watch('taskMode'); |
| | | |
| | | // 根据任务方式确定需要显示的字段 |
| | | const showField = (field) => { |
| | | const mode = taskMode; |
| | | switch (field) { |
| | | case 'startCode': |
| | | return ['MOVE', 'LOC_TO_LOC', 'LOC_TO_STA', 'STA_TO_LOC', 'STA_TO_STA'].includes(mode); |
| | | return false; |
| | | case 'endCode': |
| | | return ['MOVE', 'LOC_TO_LOC', 'LOC_TO_STA', 'STA_TO_LOC', 'STA_TO_STA'].includes(mode); |
| | | return ['MOVE'].includes(mode); |
| | | case 'startLocNo': |
| | | return ['LOC_TO_LOC', 'LOC_TO_STA'].includes(mode); |
| | | case 'endLocNo': |
| | |
| | | }; |
| | | |
| | | return ( |
| | | <Box sx={{ width: 578, p: 3 }}> |
| | | <Typography variant="h6" gutterBottom> |
| | | 任务下发 |
| | | </Typography> |
| | | <Box display="flex" height="100%" p={2}> |
| | | <form onSubmit={handleSubmit(onSubmit)}> |
| | | <Grid container spacing={2}> |
| | | {/* 左侧:任务方式选择 */} |
| | | {/* left */} |
| | | <Grid item xs={4}> |
| | | <Controller |
| | | name="taskMode" |
| | |
| | | /> |
| | | </Grid> |
| | | |
| | | {/* 右侧:输入字段和按钮 */} |
| | | {/* right */} |
| | | <Grid item xs={8}> |
| | | <Grid container spacing={2}> |
| | | {/* 动态渲染表单字段 */} |
| | | {showField('startCode') && ( |
| | | <Grid item xs={12}> |
| | | <Controller |
| | |
| | | </Grid> |
| | | )} |
| | | |
| | | {/* 按钮区域 */} |
| | | {/* button group */} |
| | | <Grid item xs={12} sx={{ display: 'flex', justifyContent: 'flex-end', mt: 2 }}> |
| | | <Button variant="contained" color="primary" type="submit" sx={{ mr: 2 }}> |
| | | 确认 |