⚡️ improve: Optimized weight/priority input handling in TableRow component.
This commit is contained in:
parent
2305da2359
commit
376d54f56a
@ -11,10 +11,6 @@ import {
|
|||||||
MenuItem,
|
MenuItem,
|
||||||
TableCell,
|
TableCell,
|
||||||
IconButton,
|
IconButton,
|
||||||
FormControl,
|
|
||||||
InputLabel,
|
|
||||||
InputAdornment,
|
|
||||||
Input,
|
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@ -25,6 +21,7 @@ import {
|
|||||||
Grid,
|
Grid,
|
||||||
Collapse,
|
Collapse,
|
||||||
Typography,
|
Typography,
|
||||||
|
TextField,
|
||||||
Box
|
Box
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
|
||||||
@ -34,7 +31,7 @@ import TableSwitch from 'ui-component/Switch';
|
|||||||
import ResponseTimeLabel from './ResponseTimeLabel';
|
import ResponseTimeLabel from './ResponseTimeLabel';
|
||||||
import GroupLabel from './GroupLabel';
|
import GroupLabel from './GroupLabel';
|
||||||
|
|
||||||
import { IconDotsVertical, IconEdit, IconTrash, IconPencil, IconCopy, IconWorldWww } from '@tabler/icons-react';
|
import { IconDotsVertical, IconEdit, IconTrash, IconCopy, IconWorldWww } from '@tabler/icons-react';
|
||||||
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
||||||
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
|
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
|
||||||
import { copy } from 'utils/common';
|
import { copy } from 'utils/common';
|
||||||
@ -78,30 +75,34 @@ export default function ChannelTableRow({ item, manageChannel, handleOpenModal,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePriority = async () => {
|
const handlePriority = async (event) => {
|
||||||
if (priorityValve === '' || priorityValve === item.priority) {
|
const currentValue = parseInt(event.target.value);
|
||||||
|
if (isNaN(currentValue) || currentValue === priorityValve) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priorityValve < 0) {
|
if (currentValue < 0) {
|
||||||
showError('优先级不能小于 0');
|
showError('优先级不能小于 0');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await manageChannel(item.id, 'priority', priorityValve);
|
await manageChannel(item.id, 'priority', currentValue);
|
||||||
|
setPriority(currentValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleWeight = async () => {
|
const handleWeight = async (event) => {
|
||||||
if (weightValve === '' || weightValve === item.weight) {
|
const currentValue = parseInt(event.target.value);
|
||||||
|
if (isNaN(currentValue) || currentValue === weightValve) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weightValve <= 0) {
|
if (currentValue < 1) {
|
||||||
showError('权重不能小于 0');
|
showError('权重不能小于 1');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await manageChannel(item.id, 'weight', weightValve);
|
await manageChannel(item.id, 'weight', currentValue);
|
||||||
|
setWeight(currentValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleResponseTime = async () => {
|
const handleResponseTime = async () => {
|
||||||
@ -178,42 +179,26 @@ export default function ChannelTableRow({ item, manageChannel, handleOpenModal,
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<FormControl sx={{ m: 1, width: '70px' }} variant="standard">
|
<TextField
|
||||||
<InputLabel htmlFor={`priority-${item.id}`}>优先级</InputLabel>
|
|
||||||
<Input
|
|
||||||
id={`priority-${item.id}`}
|
id={`priority-${item.id}`}
|
||||||
type="text"
|
onBlur={handlePriority}
|
||||||
value={priorityValve}
|
type="number"
|
||||||
onChange={(e) => setPriority(e.target.value)}
|
label="优先级"
|
||||||
sx={{ textAlign: 'center' }}
|
variant="standard"
|
||||||
endAdornment={
|
defaultValue={item.priority}
|
||||||
<InputAdornment position="end">
|
inputProps={{ min: '0' }}
|
||||||
<IconButton onClick={handlePriority} sx={{ color: 'rgb(99, 115, 129)' }} size="small">
|
|
||||||
<IconPencil />
|
|
||||||
</IconButton>
|
|
||||||
</InputAdornment>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<FormControl sx={{ m: 1, width: '70px' }} variant="standard">
|
<TextField
|
||||||
<InputLabel htmlFor={`priority-${item.id}`}>权重</InputLabel>
|
|
||||||
<Input
|
|
||||||
id={`weight-${item.id}`}
|
id={`weight-${item.id}`}
|
||||||
type="text"
|
onBlur={handleWeight}
|
||||||
value={weightValve}
|
type="number"
|
||||||
onChange={(e) => setWeight(e.target.value)}
|
label="权重"
|
||||||
sx={{ textAlign: 'center' }}
|
variant="standard"
|
||||||
endAdornment={
|
defaultValue={item.weight}
|
||||||
<InputAdornment position="end">
|
inputProps={{ min: '1' }}
|
||||||
<IconButton onClick={handleWeight} sx={{ color: 'rgb(99, 115, 129)' }} size="small">
|
|
||||||
<IconPencil />
|
|
||||||
</IconButton>
|
|
||||||
</InputAdornment>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
|
Loading…
Reference in New Issue
Block a user