导入excel表格上传参数 下载模板 参数枚举值补充 查看修改 保存参数 限制 只有admin可以修改

This commit is contained in:
mmc
2026-10-22 15:14:13 +08:00
parent 6bd497c9b5
commit f49c9e6075
6 changed files with 291 additions and 105 deletions

View File

@@ -434,12 +434,14 @@ export default function DeviceOverviewPage() {
const params = {
deviceId: data.serialNumber,
}
setCurrentParamDevice(data);
setParamModalOpen(true);
return;
hasPermission(params).then(res => {
if (res.code == 200) {
if (res.data) {
setCurrentParamDevice(data);
setParamModalOpen(true);
} else {
utils.message.error(t('devices.noPermission'));
}
@@ -635,7 +637,7 @@ export default function DeviceOverviewPage() {
<Col xs={24} lg={14}>
<Card title={<><EnvironmentOutlined />{t('devices.fixed2Equipment')}</>} extra={<Button type="text" icon={<SettingOutlined />} />} variant="borderless" style={{ borderRadius: 8, marginBottom: 8 }} styles={{ body: { padding: 0 } }}>
<div style={{ width: '100%', height: 350, borderRadius: 8, position: 'relative', overflow: 'hidden' }}>
<div style={{ position: 'absolute', zIndex: 9999, top: 12, left: 12, background: 'rgba(255,255,255,0.95)', borderRadius: 6, padding: 8 }}>
<div style={{ position: 'absolute', zIndex: 11, top: 12, left: 12, background: 'rgba(255,255,255,0.95)', borderRadius: 6, padding: 8 }}>
<div style={{ fontSize: 11, fontWeight: 60, marginBottom: 4 }}>{t('devices.s22')}</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, fontSize: 10 }}>
<div><span style={{ color: '#1890ff' }}>———</span>{t('devices.fixed2Inspection')}</div>

View File

@@ -9,6 +9,7 @@ import {
Checkbox,
Slider,
Spin,
Select,
} from 'antd';
import { useSelector } from 'react-redux';
import { RootState } from '@/store';
@@ -71,9 +72,8 @@ const GainSliderInput = ({ value, onChange, disabled, min = 0.1, max = 1, step =
);
};
const editableKeys = ['leftForwardGain', 'leftBackwardGain', 'rightForwardGain', 'rightBackwardGain'];
// 可编辑的增益滑块字段
const editableGainKeys = ['leftForwardGain', 'leftBackwardGain', 'rightForwardGain', 'rightBackwardGain'];
interface DeviceParamModalProps {
open: boolean;
@@ -89,17 +89,17 @@ interface DeviceParamModalProps {
onCancel: () => void;
onSuccess?: () => void;
}
const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCancel, onSuccess }) => {
const { stationId, currentStation } = useSelector((state: RootState) => state.station);
const [paramForm] = Form.useForm();
const [paramData, setParamData] = useState<any>(null);
const [loading, setLoading] = useState(false);
const { t } = useTranslation();
const deviceId = device?.serialNumber || device?.device_sn || '';
const deviceName = device?.deviceAlias || device?.deviceName || device?.drone_callsign || device?.callsign || deviceId;
const userInfo = useSelector((state: RootState) => state.user.userInfo);
const isAdmin = userInfo?.roleKey === 'admin'
useEffect(() => {
if (open && deviceId) {
@@ -120,7 +120,6 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
paramForm.setFieldsValue({ ...res.data });
} else {
utils.message.error(t('devices.fetchParamFail'));
setParamData(null);
paramForm.resetFields();
}
@@ -138,10 +137,7 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
setLoading(true);
try {
const payload = {
leftForwardGain: Math.max(0.1, Math.min(1, values.leftForwardGain >= 10 ? values.leftForwardGain / 10 : values.leftForwardGain)),
leftBackwardGain: Math.max(0.1, Math.min(1, values.leftBackwardGain >= 10 ? values.leftBackwardGain / 10 : values.leftBackwardGain)),
rightForwardGain: Math.max(0.1, Math.min(1, values.rightForwardGain >= 10 ? values.rightForwardGain / 10 : values.rightForwardGain)),
rightBackwardGain: Math.max(0.1, Math.min(1, values.rightBackwardGain >= 10 ? values.rightBackwardGain / 10 : values.rightBackwardGain)),
...values,
deviceId,
siteId: stationId,
orgId: currentStation?.orgId,
@@ -167,63 +163,132 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
paramForm.resetFields();
onCancel?.();
};
const paramFieldConfigs = [
{ key: 'leftForwardGain', label: t('devices.paramLeftForwardGain'), type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
{ key: 'leftBackwardGain', label: t('devices.paramLeftBackwardGain'), type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
{ key: 'rightForwardGain', label: t('devices.paramRightForwardGain'), type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
{ key: 'rightBackwardGain', label: t('devices.paramRightBackwardGain'), type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
{ key: 'runSpeed', label: t('devices.paramRunSpeed'), type: 'InputNumber', editable: true },
//hasHost: "hasHost",
//rtkMode: "rtkMode", cameraNum: "cameraNum", wheelType: "wheelType", engineType: "engineType", capabilityList: "capabilityList", powerType: "powerType",
{ key: 'hasHost', label: t('devices.hasHost'), type: 'Input', editable: false },
{ key: 'rtkMode', label: t('devices.rtkMode'), type: 'Input', editable: false },
{ key: 'cameraNum', label: t('devices.cameraNum'), type: 'Input', editable: false },
{ key: 'wheelType', label: t('devices.wheelType'), type: 'Input', editable: false },
{ key: 'engineType', label: t('devices.engineType'), type: 'Input', editable: false },
{ key: 'capabilityList', label: t('devices.capabilityList'), type: 'Input', editable: false },
{ key: 'chipUidSign', label: t('devices.paramChipUidSign'), type: 'InputNumber', editable: false },
{ key: 'chipUid', label: t('devices.paramChipUid'), type: 'Input', editable: false },
{ key: 'remoteConfig', label: t('devices.paramRemoteConfig'), type: 'InputNumber', editable: false },
{ key: 'knifeMotorMode', label: t('devices.paramKnifeMotorMode'), type: 'InputNumber', editable: false },
{ key: 'walkMotorMode', label: t('devices.paramWalkMotorMode'), type: 'InputNumber', editable: false },
{ key: 'leftMotorReverse', label: t('devices.paramLeftMotorReverse'), type: 'InputNumber', editable: false },
{ key: 'rightMotorReverse', label: t('devices.paramRightMotorReverse'), type: 'InputNumber', editable: false },
{ key: 'swapChannel', label: t('devices.paramSwapChannel'), type: 'InputNumber', editable: false },
{ key: 'use4G', label: t('devices.paramUse4G'), type: 'InputNumber', editable: false },
{ key: 'forwardSpeedLimit', label: t('devices.paramForwardSpeedLimit'), type: 'InputNumber', editable: false },
{ key: 'turnSpeedLimit', label: t('devices.paramTurnSpeedLimit'), type: 'InputNumber', editable: false },
{ key: 'knifePolarity', label: t('devices.paramKnifePolarity'), type: 'InputNumber', editable: false },
{ key: 'fanPolarity', label: t('devices.paramFanPolarity'), type: 'InputNumber', editable: false },
{ key: 'throttlePolarity', label: t('devices.paramThrottlePolarity'), type: 'InputNumber', editable: false },
{ key: 'liftProtectTime', label: t('devices.paramLiftProtectTime'), type: 'InputNumber', editable: false },
{ key: 'dualRtk', label: t('devices.paramDualRtk'), type: 'InputNumber', editable: false },
{ key: 'knifeChannel', label: t('devices.paramKnifeChannel'), type: 'InputNumber', editable: false },
{ key: 'fanChannel', label: t('devices.paramFanChannel'), type: 'InputNumber', editable: false },
{ key: 'throttleChannel', label: t('devices.paramThrottleChannel'), type: 'InputNumber', editable: false },
{ key: 'remoteType', label: t('devices.paramRemoteType'), type: 'InputNumber', editable: false },
{ key: 'relayBoard', label: t('devices.paramRelayBoard'), type: 'Checkbox', editable: false },
{ key: 'liftChannel', label: t('devices.paramLiftChannel'), type: 'InputNumber', editable: false },
{ key: 'chassisChannel', label: t('devices.paramChassisChannel'), type: 'InputNumber', editable: false },
{ key: 'armChannel', label: t('devices.paramArmChannel'), type: 'InputNumber', editable: false },
{ key: 'fuelPumpChannel', label: t('devices.paramFuelPumpChannel'), type: 'InputNumber', editable: false },
{ key: 'wifiName', label: t('devices.paramWifiName'), type: 'Input', editable: false },
{ key: 'wifiPassword', label: t('devices.paramWifiPassword'), type: 'Input', editable: false },
{ key: 'batteryType', label: t('devices.paramBatteryType'), type: 'InputNumber', editable: false },
{ key: 'driveType', label: t('devices.paramDriveType'), type: 'InputNumber', editable: false },
{ key: 'gearRatio', label: t('devices.paramGearRatio'), type: 'InputNumber', editable: false, step: 0.01 },
{ key: 'robotLength', label: t('devices.paramRobotLength'), type: 'InputNumber', editable: false, step: 0.01 },
{ key: 'robotWidth', label: t('devices.paramRobotWidth'), type: 'InputNumber', editable: false, step: 0.01 },
{ key: 'robotHeight', label: t('devices.paramRobotHeight'), type: 'InputNumber', editable: false, step: 0.01 },
{ key: 'knifeWidth', label: t('devices.paramKnifeWidth'), type: 'InputNumber', editable: false, step: 0.01 },
{ key: 'tyreSize', label: t('devices.paramTyreSize'), type: 'InputNumber', editable: false, step: 0.01 },
{ key: 'firmwareVersion', label: t('devices.paramFirmwareVersion'), type: 'Input', editable: false },
{ key: 'crc16', label: 'CRC16', type: 'InputNumber', editable: false },
{ key: 'tail1', label: 'tail1', type: 'InputNumber', editable: false },
{ key: 'tail2', label: 'tail2', type: 'InputNumber', editable: false },
{ key: 'remark', label: t('roles.remark'), type: 'Input', editable: false },
{ key: 'delFlag', label: t('devices.paramDelFlag'), type: 'Checkbox', editable: false },
];
// ========== 按你后端Java实体顺序重新整理字段配置 ==========
// 枚举取值参考设备参数规范:设备类型 M/I/U、车轮 W/T、动力 E/H、RTK N/B、发动机 H/L/Z 等
const paramFieldConfigs: any[] = [
// 【可编辑】增益滑块 + runSpeed
//{ key: 'leftForwardGain', label: t('devices.paramLeftForwardGain'), type: 'GainSlider', editable: true, min: 0.1, max: 1, step: 0.01 },
//{ key: 'leftBackwardGain', label: t('devices.paramLeftBackwardGain'), type: 'GainSlider', editable: true, min: 0.1, max: 1, step: 0.01 },
//{ key: 'rightForwardGain', label: t('devices.paramRightForwardGain'), type: 'GainSlider', editable: true, min: 0.1, max: 1, step: 0.01 },
//{ key: 'rightBackwardGain', label: t('devices.paramRightBackwardGain'), type: 'GainSlider', editable: true, min: 0.1, max: 1, step: 0.01 },
//{ key: 'runSpeed', label: t('devices.paramRunSpeed'), type: 'InputNumber', editable: true },
// 下面全部只读,和后端Excel实体顺序对齐
{ key: 'deviceId', label: t('devices.deviceId'), type: 'Input', editable: isAdmin },
{
key: 'productModel', label: t('devices.productModel'), type: 'Select', editable: isAdmin,
options: [
{ value: 'ST', label: 'ST' },
{ value: 'PL', label: 'PL' },
{ value: 'PR', label: 'PR' },
{ value: 'AI', label: 'AI' },
],
},
{
key: 'deviceType', label: t('devices.deviceType'), type: 'Select', editable: isAdmin,
options: [
{ value: 'M', label: t('devices.paramEnum.deviceTypeM') },
{ value: 'I', label: t('devices.paramEnum.deviceTypeI') },
{ value: 'U', label: t('devices.paramEnum.deviceTypeU') },
],
},
{
key: 'rtkMode', label: t('devices.rtkMode'), type: 'Select', editable: isAdmin,
options: [
{ value: 'N', label: t('devices.paramEnum.rtkModeN') },
{ value: 'B', label: t('devices.paramEnum.rtkModeB') },
],
},
{ key: 'cameraNum', label: t('devices.cameraNum'), type: 'InputNumber', editable: isAdmin, min: 0, max: 4, step: 1 },
{
key: 'powerType', label: t('devices.powerType'), type: 'Select', editable: isAdmin,
options: [
{ value: 'E', label: t('devices.paramEnum.powerTypeE') },
{ value: 'H', label: t('devices.paramEnum.powerTypeH') },
],
},
{
key: 'wheelType', label: t('devices.wheelType'), type: 'Select', editable: isAdmin,
options: [
{ value: 'W', label: t('devices.paramEnum.wheelTypeW') },
{ value: 'T', label: t('devices.paramEnum.wheelTypeT') },
],
},
{
key: 'engineType', label: t('devices.engineType'), type: 'Select', editable: isAdmin,
options: [
{ value: 'H', label: t('devices.paramEnum.engineTypeH') },
{ value: 'L', label: t('devices.paramEnum.engineTypeL') },
{ value: 'Z', label: t('devices.paramEnum.engineTypeZ') },
],
},
{
key: 'hasHost', label: t('devices.hasHost'), type: 'Select', editable: isAdmin,
options: [
{ value: 0, label: t('devices.paramEnum.hasHostNo') },
{ value: 1, label: t('devices.paramEnum.hasHostYes') },
],
},
{
key: 'batteryType', label: t('devices.batteryType'), type: 'Select', editable: isAdmin,
options: [
{ value: '铅酸', label: t('devices.paramEnum.batteryLeadAcid') },
{ value: '锂电', label: t('devices.paramEnum.batteryLithium') },
],
},
{
key: 'walkingDriveType', label: t('devices.walkingDriveType'), type: 'Select', editable: isAdmin,
options: [
{ value: 'FDK', label: 'FDK' },
{ value: 'SdBLdc', label: 'SdBLdc' },
{ value: 'SdFoc', label: 'SdFoc' },
],
},
{
key: 'cutterDriveType', label: t('devices.cutterDriveType'), type: 'Select', editable: isAdmin,
options: [
{ value: 'XLD', label: 'XLD' },
{ value: 'LH', label: 'LH' },
],
},
{
key: 'rtkAntennasNum', label: t('devices.rtkAntennasNum'), type: 'Select', editable: isAdmin,
options: [
{ value: 1, label: t('devices.paramEnum.rtkAntennaSingle') },
{ value: 2, label: t('devices.paramEnum.rtkAntennaDual') },
],
},
{
key: 'handleType', label: t('devices.handleType'), type: 'Select', editable: isAdmin,
options: [
{ value: 'SBUS', label: t('devices.paramEnum.handleSbus') },
{ value: '自定义', label: t('devices.paramEnum.handleCustom') },
],
},
{ key: 'pcbVersion', label: t('devices.pcbVersion'), type: 'Input', editable: isAdmin },
{ key: 'dimensions', label: t('devices.dimensions'), type: 'Input', editable: isAdmin },
{ key: 'bladeWidth', label: t('devices.bladeWidth'), type: 'Input', editable: isAdmin },
{ key: 'tyreSize', label: t('devices.tyreSize'), type: 'Input', editable: isAdmin },
{ key: 'speedRatio', label: t('devices.speedRatio'), type: 'Input', editable: isAdmin },
{ key: 'cellularInfo', label: t('devices.cellularInfo'), type: 'Input', editable: isAdmin },
{ key: 'wifiName', label: t('devices.paramWifiName'), type: 'Input', editable: isAdmin },
{ key: 'bluetoothName', label: t('devices.bluetoothName'), type: 'Input', editable: isAdmin },
{ key: 'hardwareIdentifiers', label: t('devices.hardwareIdentifiers'), type: 'Input', editable: isAdmin },
{ key: 'imuModel', label: t('devices.imuModel'), type: 'Input', editable: isAdmin },
{ key: 'tempHumiditySensor', label: t('devices.tempHumiditySensor'), type: 'Input', editable: isAdmin },
{ key: 'barometerPresent', label: t('devices.barometerPresent'), type: 'Input', editable: isAdmin },
{ key: 'ultrasonicPresent', label: t('devices.ultrasonicPresent'), type: 'Input', editable: isAdmin },
{ key: 'dacPresent', label: t('devices.dacPresent'), type: 'Input', editable: isAdmin },
{ key: 'operator', label: t('devices.operator'), type: 'Input', editable: isAdmin },
{ key: 'inspectionNo', label: t('devices.inspectionNo'), type: 'Input', editable: isAdmin },
{ key: 'firmwareVersion', label: t('devices.paramFirmwareVersion'), type: 'Input', editable: isAdmin },
{ key: 'dealer', label: t('devices.dealer'), type: 'Input', editable: isAdmin },
];
// 区分增益滑块组 和 其余普通字段组
const gainFields = paramFieldConfigs.filter(f => f.type === 'GainSlider');
const otherFields = paramFieldConfigs.filter(f => f.type !== 'GainSlider');
return (
<Modal
@@ -249,49 +314,33 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
width={780}
destroyOnClose
>
{/* 加载时表单区域简单遮罩提示(打开弹窗拉取参数时的loading反馈) */}
<div style={{ maxHeight: '60vh', overflowY: 'auto', paddingRight: 8, position: 'relative' }}>
<Spin spinning={loading} tip={t('common.loading')}>
<Form form={paramForm} layout="vertical" onFinish={saveParam}>
{/* 增益滑块行 */}
<Row gutter={16}>
{editableKeys.map((key) => {
const field = paramFieldConfigs.find(f => f.key === key);
if (!field) return null;
const isGainSliderField = ['leftForwardGain', 'leftBackwardGain', 'rightForwardGain', 'rightBackwardGain'].includes(key);
{gainFields.map((field) => {
const disabled = !field.editable;
return (
<Col span={12} key={key}>
<Col span={12} key={field.key}>
<Form.Item
label={<span style={{ fontWeight: 500 }}>{field.label}</span>}
name={field.key}
>
{isGainSliderField ? (
<GainSliderInput
disabled={disabled}
min={field.min}
max={field.max}
step={0.01}
/>
) : (
<InputNumber
style={{ width: '100%' }}
disabled={disabled}
min={field.min}
max={field.max}
step={field.step}
placeholder={typeof field.min === 'number' ? `${field.min}~${field.max}` : ''}
/>
)}
<GainSliderInput
disabled={disabled}
min={field.min}
max={field.max}
step={field.step}
/>
</Form.Item>
</Col>
);
})}
</Row>
{/* runSpeed + 其余全部只读字段 */}
<Row gutter={16}>
{paramFieldConfigs.filter(f => !editableKeys.includes(f.key)).map((field) => {
{otherFields.map((field) => {
const disabled = !field.editable;
return (
<Col span={12} key={field.key}>
@@ -300,14 +349,24 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
name={field.key}
valuePropName={field.type === 'Checkbox' ? 'checked' : undefined}
>
{field.type === 'InputNumber' ? (
{field.type === 'Select' ? (
<Select
style={{ width: '100%' }}
disabled={disabled}
allowClear
showSearch
optionFilterProp="label"
options={field.options}
placeholder={t('devices.noData')}
/>
) : field.type === 'InputNumber' ? (
<InputNumber
style={{ width: '100%' }}
disabled={disabled}
min={field.min}
max={field.max}
step={field.step}
placeholder={typeof field.min === 'number' ? `${field.min}~${field.max}` : ''}
placeholder={typeof field.min === 'number' ? `${field.min}~${field.max}` : t('devices.noData')}
/>
) : field.type === 'Checkbox' ? (
<Checkbox disabled={disabled} />
@@ -325,5 +384,4 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
</Modal>
);
};
export default DeviceParamModal;