优化设备管理界面讲将5个子页面抽离出组件 轻量化 也优化了 两个组件内弹窗的数据影响 优化了 设备参数弹窗的 loading效果
This commit is contained in:
@@ -2,22 +2,20 @@ import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
Form,
|
||||
Card,
|
||||
Row,
|
||||
Col,
|
||||
InputNumber,
|
||||
Input,
|
||||
Checkbox,
|
||||
Slider,
|
||||
Button,
|
||||
Space,
|
||||
Spin,
|
||||
} from 'antd';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { RootState } from '@/store';
|
||||
import { deviceRunParamSelectByDeviceId, deviceRunParamSave } from '@/api/stationManage/index';
|
||||
import utils from '@/lib/utils';
|
||||
|
||||
const GainSliderInput = ({ value = 0.5, onChange, disabled, min = 0.1, max = 1, step = 0.01 }) => {
|
||||
const GainSliderInput = ({ value, onChange, disabled, min = 0.1, max = 1, step = 0.01 }) => {
|
||||
const handleSliderChange = (val) => {
|
||||
onChange?.(val);
|
||||
};
|
||||
@@ -165,11 +163,13 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
|
||||
setParamData(res.data);
|
||||
paramForm.setFieldsValue({ ...res.data });
|
||||
} else {
|
||||
utils.message.error('获取参数失败');
|
||||
|
||||
setParamData(null);
|
||||
paramForm.resetFields();
|
||||
}
|
||||
} else {
|
||||
utils.message.error(res.msg || '获取参数失败');
|
||||
utils.message.error('获取参数失败');
|
||||
}
|
||||
} catch (err) {
|
||||
utils.message.error('获取参数失败');
|
||||
@@ -179,6 +179,7 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
|
||||
};
|
||||
|
||||
const saveParam = async (values) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const payload = {
|
||||
leftForwardGain: Math.max(0.1, Math.min(1, values.leftForwardGain >= 10 ? values.leftForwardGain / 10 : values.leftForwardGain)),
|
||||
@@ -200,6 +201,8 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
|
||||
}
|
||||
} catch (err) {
|
||||
utils.message.error('操作异常');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -231,85 +234,80 @@ const DeviceParamModal: React.FC<DeviceParamModalProps> = ({ open, device, onCan
|
||||
onOk={() => paramForm.submit()}
|
||||
confirmLoading={loading}
|
||||
width={780}
|
||||
bodyStyle={{ padding: '16px 24px 0px' }}
|
||||
destroyOnClose
|
||||
>
|
||||
<div style={{ maxHeight: '60vh', overflowY: 'auto', paddingRight: 8 }}>
|
||||
<Form form={paramForm} layout="vertical" onFinish={saveParam}>
|
||||
{/* 加载时表单区域简单遮罩提示(打开弹窗拉取参数时的loading反馈) */}
|
||||
<div style={{ maxHeight: '60vh', overflowY: 'auto', paddingRight: 8, position: 'relative' }}>
|
||||
<Spin spinning={loading} tip="加载中...">
|
||||
<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);
|
||||
const disabled = !field.editable;
|
||||
return (
|
||||
<Col span={12} key={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}` : ''}
|
||||
/>
|
||||
)}
|
||||
</Form.Item>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
</Row>
|
||||
<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);
|
||||
const disabled = !field.editable;
|
||||
return (
|
||||
<Col span={12} key={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}` : ''}
|
||||
/>
|
||||
)}
|
||||
</Form.Item>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
</Row>
|
||||
|
||||
|
||||
<Row gutter={16}>
|
||||
{paramFieldConfigs.filter(f => !editableKeys.includes(f.key)).map((field) => {
|
||||
const disabled = !field.editable;
|
||||
return (
|
||||
<Col span={12} key={field.key}>
|
||||
<Form.Item
|
||||
label={field.label}
|
||||
name={field.key}
|
||||
valuePropName={field.type === 'Checkbox' ? 'checked' : undefined}
|
||||
>
|
||||
{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}` : ''}
|
||||
/>
|
||||
) : field.type === 'Checkbox' ? (
|
||||
<Checkbox disabled={disabled} />
|
||||
) : (
|
||||
<Input disabled={disabled} placeholder="无数据" />
|
||||
)}
|
||||
</Form.Item>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
</Row>
|
||||
|
||||
<Form.Item style={{ marginTop: 20, marginBottom: 8 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 10 }}>
|
||||
<Button onClick={handleCancel} style={{ borderRadius: 8, padding: '4px 24px' }}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" loading={loading} style={{ borderRadius: 8, padding: '4px 28px' }}>保存</Button>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
<Row gutter={16}>
|
||||
{paramFieldConfigs.filter(f => !editableKeys.includes(f.key)).map((field) => {
|
||||
const disabled = !field.editable;
|
||||
return (
|
||||
<Col span={12} key={field.key}>
|
||||
<Form.Item
|
||||
label={field.label}
|
||||
name={field.key}
|
||||
valuePropName={field.type === 'Checkbox' ? 'checked' : undefined}
|
||||
>
|
||||
{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}` : ''}
|
||||
/>
|
||||
) : field.type === 'Checkbox' ? (
|
||||
<Checkbox disabled={disabled} />
|
||||
) : (
|
||||
<Input disabled={disabled} placeholder="无数据" />
|
||||
)}
|
||||
</Form.Item>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
</Row>
|
||||
</Form>
|
||||
</Spin>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user