两个地方的设备参数 组件 加上授权功能
This commit is contained in:
@@ -437,6 +437,26 @@ export function deviceCommmand(data) {
|
||||
})
|
||||
}
|
||||
|
||||
///iot/device/paramModifyAuth
|
||||
//设备前置授权
|
||||
export function getDeviceAuth(data) {
|
||||
return request({
|
||||
url: '/iot/device/paramModifyAuth',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
//查看当前是否有权限修改
|
||||
export function hasPermission(params) {
|
||||
return request({
|
||||
url: '/iot/device/hasPermission',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,61 +32,10 @@ import {
|
||||
DisconnectOutlined,
|
||||
} from '@ant-design/icons';
|
||||
|
||||
const GainSliderInput = ({ value = 0.5, onChange, disabled, min = 0.1, max = 1, step = 0.01 }) => {
|
||||
const handleSliderChange = (val) => {
|
||||
onChange?.(val);
|
||||
};
|
||||
const handleInputChange = (val) => {
|
||||
let num = Number(val);
|
||||
if (isNaN(num)) num = min;
|
||||
num = Math.max(min, Math.min(max, num));
|
||||
onChange?.(Number(num.toFixed(2)));
|
||||
};
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 12,
|
||||
padding: '8px 12px',
|
||||
background: disabled ? '#fafafa' : 'linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%)',
|
||||
borderRadius: 10,
|
||||
border: '1px solid',
|
||||
borderColor: disabled ? '#f0f0f0' : '#e4e8ed',
|
||||
transition: 'all 0.3s ease',
|
||||
boxShadow: disabled ? 'none' : '0 2px 6px rgba(0,0,0,0.04)',
|
||||
}}>
|
||||
<Slider
|
||||
style={{ flex: 1, margin: 0 }}
|
||||
disabled={disabled}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
value={typeof value === 'number' ? value : min}
|
||||
onChange={handleSliderChange}
|
||||
tooltip={{ formatter: (v) => `${v?.toFixed(2)}` }}
|
||||
marks={{
|
||||
[min]: { style: { color: '#8c8c8c', fontSize: 10 }, label: min },
|
||||
[(min + max) / 2]: { style: { color: '#8c8c8c', fontSize: 10 }, label: ((min + max) / 2).toFixed(2) },
|
||||
[max]: { style: { color: '#8c8c8c', fontSize: 10 }, label: max },
|
||||
}}
|
||||
/>
|
||||
<InputNumber
|
||||
disabled={disabled}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
value={value}
|
||||
onChange={handleInputChange}
|
||||
style={{
|
||||
width: 72,
|
||||
borderRadius: 8,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
import SerialNumGenerate from "./SerialNumGenerate"
|
||||
import { getPlaneDeviceList, bindDrone, unbindDrone, bindSmartDevice, unbindSmartDevice, getAllDevice, deviceCommmand } from '@/api/device';
|
||||
import DeviceParamModal from '../devices/DeviceParamModal';
|
||||
import { getPlaneDeviceList, bindDrone, unbindDrone, bindSmartDevice, unbindSmartDevice, getAllDevice, deviceCommmand, getDeviceAuth, hasPermission } from '@/api/device';
|
||||
import { getOrgList } from '@/api/organization/index';
|
||||
import { getSiteByOrgId, getStationList, deviceRunParamSelectByDeviceId, deviceRunParamSave, deviceRunParamDelete } from '@/api/stationManage/index';
|
||||
import { getUser } from '@/api/user/index';
|
||||
@@ -174,11 +123,9 @@ export default function DeviceManagementPage() {
|
||||
const [editSmartForm] = Form.useForm();
|
||||
const [currentEditSmart, setCurrentEditSmart] = useState(null);
|
||||
|
||||
// 设备参数管理相关状态
|
||||
// 设备参数管理相关状态(由 DeviceParamModal 通用组件内部管理 API/表单逻辑)
|
||||
const [paramModalVisible, setParamModalVisible] = useState(false);
|
||||
const [currentParamDevice, setCurrentParamDevice] = useState(null);
|
||||
const [paramData, setParamData] = useState(null);
|
||||
const [paramForm] = Form.useForm();
|
||||
|
||||
|
||||
const [paramModalVisible1, setParamModalVisible1] = useState(false);
|
||||
@@ -186,7 +133,7 @@ export default function DeviceManagementPage() {
|
||||
const [paramData1, setParamData1] = useState(null);
|
||||
const [paramForm1] = Form.useForm();
|
||||
|
||||
// 设备参数表单字段配置
|
||||
// 设备参数表单字段配置(仅其他弹窗/增益单独弹窗/批量弹窗用,主参数弹窗已封装至通用组件)
|
||||
const paramFieldConfigs = [
|
||||
{ key: 'leftForwardGain', label: '左轮前进增益', type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
|
||||
{ key: 'leftBackwardGain', label: '左轮后退增益', type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
|
||||
@@ -279,89 +226,49 @@ export default function DeviceManagementPage() {
|
||||
setCurrentEditSmart(null);
|
||||
};
|
||||
|
||||
// 打开设备参数管理弹窗
|
||||
// 打开设备参数管理弹窗(通用组件内部自动读取/保存参数)
|
||||
const openParamModal = async (record) => {
|
||||
setCurrentParamDevice(record);
|
||||
setParamModalVisible(true);
|
||||
await fetchParamData(record.serialNumber);
|
||||
getDevivePermisstion(record);
|
||||
|
||||
};
|
||||
const openParamModal1 = async (record) => {
|
||||
setCurrentParamDevice1(record);
|
||||
setParamModalVisible1(true);
|
||||
};
|
||||
const getDevivePermisstion = (data) => {
|
||||
const params = {
|
||||
deviceId: data.serialNumber,
|
||||
}
|
||||
|
||||
// 获取设备参数
|
||||
const fetchParamData = async (deviceId) => {
|
||||
try {
|
||||
const res = await deviceRunParamSelectByDeviceId({ deviceId });
|
||||
|
||||
hasPermission(params).then(res => {
|
||||
if (res.code == 200) {
|
||||
if (res.data) {
|
||||
setParamData(res.data);
|
||||
// 一次性回填所有字段
|
||||
paramForm.setFieldsValue({ ...res.data });
|
||||
setCurrentParamDevice(data);
|
||||
setParamModalVisible(true);
|
||||
} else {
|
||||
setParamData(null);
|
||||
paramForm.resetFields();
|
||||
utils.message.error('无权限');
|
||||
}
|
||||
} else {
|
||||
utils.message.error(res.msg || '获取参数失败');
|
||||
}
|
||||
} catch (err) {
|
||||
utils.message.error('获取参数失败');
|
||||
}
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 保存参数
|
||||
const saveParam = async (values) => {
|
||||
console.log(values, currentParamDevice);
|
||||
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)),
|
||||
deviceId: currentParamDevice.serialNumber,
|
||||
siteId: stationId,
|
||||
orgId: currentStation?.orgId,
|
||||
runSpeed: values.runSpeed,
|
||||
id: paramData?.id,
|
||||
};
|
||||
const res = await deviceRunParamSave(payload);
|
||||
if (res.code === 200) {
|
||||
utils.message.success('保存参数成功');
|
||||
setParamModalVisible(false);
|
||||
//await fetchParamData(currentParamDevice.serialNumber);
|
||||
} else {
|
||||
utils.message.error(res.msg || '保存参数失败');
|
||||
}
|
||||
} catch (err) {
|
||||
utils.message.error('操作异常');
|
||||
}
|
||||
};
|
||||
|
||||
const saveParam1 = async (values) => {
|
||||
console.log(values);
|
||||
try {
|
||||
const payload = {
|
||||
params: {
|
||||
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)),
|
||||
},
|
||||
commandType: "WheelGainCoefficients",
|
||||
deviceId: [currentParamDevice1.serialNumber],
|
||||
|
||||
deviceId: currentParamDevice1.serialNumber,
|
||||
duration: values?.minute,
|
||||
};
|
||||
console.log(values);
|
||||
const res = await deviceCommmand(payload);
|
||||
if (res.code === 200) {
|
||||
console.log(payload, "payload");
|
||||
const res = await getDeviceAuth(payload);
|
||||
console.log(res, "res");
|
||||
if (res.code === 200 && res.data == true) {
|
||||
utils.message.success('保存参数成功');
|
||||
setParamModalVisible1(false);
|
||||
//await fetchParamData(currentParamDevice.serialNumber);
|
||||
} else {
|
||||
utils.message.error(res.msg || '保存参数失败');
|
||||
utils.message.error(res.msg || '授权失败');
|
||||
}
|
||||
} catch (err) {
|
||||
utils.message.error('操作异常');
|
||||
@@ -632,7 +539,7 @@ export default function DeviceManagementPage() {
|
||||
<Button size="small" icon={<DisconnectOutlined />} onClick={() => handleUnbindSmart([record.serialNumber], 3)}>组织</Button>
|
||||
</Tooltip>
|
||||
<Button size="small" icon={<EditOutlined />} onClick={() => openParamModal(record)}>参数</Button>
|
||||
{/*<Button size="small" icon={<EditOutlined />} onClick={() => openParamModal1(record)}>增益参数</Button>*/}
|
||||
{userInfo?.userId == 1 && <Button size="small" icon={<EditOutlined />} onClick={() => openParamModal1(record)}>授权</Button>}
|
||||
|
||||
|
||||
</Space>
|
||||
@@ -960,7 +867,7 @@ export default function DeviceManagementPage() {
|
||||
background: 'linear-gradient(180deg, #1890ff 0%, #096dd9 100%)',
|
||||
borderRadius: 2,
|
||||
}}></span>
|
||||
<span style={{ fontWeight: 600 }}>增益参数管理</span>
|
||||
<span style={{ fontWeight: 600 }}>设备授权</span>
|
||||
<span style={{ color: '#8c8c8c', fontSize: 13, fontWeight: 'normal' }}>
|
||||
- {currentParamDevice1?.deviceAlias || currentParamDevice1?.serialNumber}
|
||||
</span>
|
||||
@@ -973,225 +880,69 @@ export default function DeviceManagementPage() {
|
||||
setParamData1(null);
|
||||
}}
|
||||
footer={null}
|
||||
onOk={() => paramForm1.submit()}
|
||||
width={560}
|
||||
bodyStyle={{ padding: '20px 24px 8px' }}
|
||||
>
|
||||
<Form
|
||||
form={paramForm1}
|
||||
layout="vertical"
|
||||
onFinish={saveParam1}
|
||||
|
||||
>
|
||||
<Card
|
||||
size="small"
|
||||
style={{
|
||||
marginBottom: 16,
|
||||
borderRadius: 12,
|
||||
background: 'linear-gradient(135deg, #fff7e6 0%, #ffe7ba 100%)',
|
||||
border: '1px solid #ffd591',
|
||||
background: 'linear-gradient(135deg, #e6f7ff 0%, #bae7ff 100%)',
|
||||
border: '1px solid #91caeb',
|
||||
}}
|
||||
bodyStyle={{ padding: '10px 14px' }}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, color: '#d46b08', fontSize: 13 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, color: '#095b91', fontSize: 13 }}>
|
||||
<span>💡</span>
|
||||
<span>增益系数范围 0.10 ~ 1.00,拖动滑块或直接输入数值均可调节</span>
|
||||
<span>设置设备操作授权,授权到期后设备将失去对应操作权限</span>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Form.Item label={<span style={{ fontWeight: 500 }}>左轮前进增益</span>} name="leftForwardGain" rules={[{ required: true, message: '请设置左轮前进增益系数' }]}>
|
||||
<GainSliderInput min={0.1} max={1} step={0.01} />
|
||||
</Form.Item>
|
||||
<Form.Item label={<span style={{ fontWeight: 500 }}>左轮后退增益</span>} name="leftBackwardGain" rules={[{ required: true, message: '请设置左轮后退增益系数' }]}>
|
||||
<GainSliderInput min={0.1} max={1} step={0.01} />
|
||||
</Form.Item>
|
||||
<Form.Item label={<span style={{ fontWeight: 500 }}>右轮前进增益</span>} name="rightForwardGain" rules={[{ required: true, message: '请设置右轮前进增益系数' }]}>
|
||||
<GainSliderInput min={0.1} max={1} step={0.01} />
|
||||
</Form.Item>
|
||||
<Form.Item label={<span style={{ fontWeight: 500 }}>右轮后退增益</span>} name="rightBackwardGain" rules={[{ required: true, message: '请设置右轮后退增益系数' }]}>
|
||||
<GainSliderInput min={0.1} max={1} step={0.01} />
|
||||
<Form.Item
|
||||
label={<span style={{ fontWeight: 500 }}>授权时间(min)</span>}
|
||||
name="minute"
|
||||
rules={[
|
||||
{ required: true, message: '请输入授权剩余时间' },
|
||||
{ type: 'number', min: 0, message: '授权时间不能小于0' }
|
||||
]}
|
||||
>
|
||||
<InputNumber
|
||||
style={{ width: '100%' }}
|
||||
min={0}
|
||||
placeholder="请输入授权剩余时间"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
|
||||
|
||||
<Form.Item style={{ marginTop: 20, marginBottom: 8 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 10 }}>
|
||||
<Button onClick={() => setParamModalVisible1(false)} style={{ borderRadius: 8, padding: '4px 20px' }}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" style={{ borderRadius: 8, padding: '4px 24px' }}>保存参数</Button>
|
||||
<Button type="primary" htmlType="submit" style={{ borderRadius: 8, padding: '4px 24px' }}>保存授权</Button>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
|
||||
{/* 设备参数管理弹窗 */}
|
||||
<Modal
|
||||
title={
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<span style={{
|
||||
display: 'inline-block',
|
||||
width: 4,
|
||||
height: 18,
|
||||
background: 'linear-gradient(180deg, #52c41a 0%, #389e0d 100%)',
|
||||
borderRadius: 2,
|
||||
}}></span>
|
||||
<span style={{ fontWeight: 600 }}>设备全部参数查看与增益修改</span>
|
||||
<span style={{ color: '#8c8c8c', fontSize: 13, fontWeight: 'normal' }}>
|
||||
- {currentParamDevice?.deviceAlias || currentParamDevice?.serialNumber}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
<DeviceParamModal
|
||||
open={paramModalVisible}
|
||||
device={currentParamDevice}
|
||||
onCancel={() => {
|
||||
setParamModalVisible(false);
|
||||
setCurrentParamDevice(null);
|
||||
setParamData(null);
|
||||
paramForm.resetFields();
|
||||
}}
|
||||
onOk={() => paramForm.submit()}
|
||||
width={780}
|
||||
bodyStyle={{ padding: '16px 24px 0px' }}
|
||||
>
|
||||
<div style={{ maxHeight: '60vh', overflowY: 'auto', paddingRight: 8 }}>
|
||||
<Form form={paramForm} layout="vertical" onFinish={saveParam}>
|
||||
|
||||
<Row gutter={16}>
|
||||
{['leftForwardGain', 'leftBackwardGain', 'rightForwardGain', 'rightBackwardGain'].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 => !['leftForwardGain', 'leftBackwardGain', 'rightForwardGain', 'rightBackwardGain'].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={() => setParamModalVisible(false)} style={{ borderRadius: 8, padding: '4px 24px' }}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" style={{ borderRadius: 8, padding: '4px 28px' }}>保存增益与运行速度</Button>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
|
||||
{/* 批量修改增益参数弹窗 */}
|
||||
<Modal
|
||||
title={
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<span style={{
|
||||
display: 'inline-block',
|
||||
width: 4,
|
||||
height: 18,
|
||||
background: 'linear-gradient(180deg, #722ed1 0%, #531dab 100%)',
|
||||
borderRadius: 2,
|
||||
}}></span>
|
||||
<span style={{ fontWeight: 600 }}>批量修改增益参数</span>
|
||||
<Tag color="purple" style={{ marginLeft: 4 }}>已选 {selectedSmartKeys.length} 台</Tag>
|
||||
</div>
|
||||
}
|
||||
open={batchParamModalVisible}
|
||||
onCancel={() => {
|
||||
setBatchParamModalVisible(false);
|
||||
batchParamForm.resetFields();
|
||||
onSuccess={() => {
|
||||
}}
|
||||
footer={null}
|
||||
width={560}
|
||||
>
|
||||
<Form
|
||||
form={batchParamForm}
|
||||
layout="vertical"
|
||||
onFinish={saveBatchParam}
|
||||
/>
|
||||
|
||||
|
||||
|
||||
>
|
||||
<Card
|
||||
size="small"
|
||||
style={{
|
||||
marginBottom: 16,
|
||||
borderRadius: 12,
|
||||
background: 'linear-gradient(135deg, #f9f0ff 0%, #efdbff 100%)',
|
||||
border: '1px solid #d3adf7',
|
||||
}}
|
||||
bodyStyle={{ padding: '10px 14px' }}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, color: '#531dab', fontSize: 13 }}>
|
||||
<span>⚠️</span>
|
||||
<span>将为 {selectedSmartKeys.length} 台设备统一设置增益系数,范围 0.10 ~ 1.00</span>
|
||||
</div>
|
||||
</Card>
|
||||
<Form.Item label={<span style={{ fontWeight: 500 }}>左轮前进增益系数</span>} name="leftForwardGain" rules={[{ required: true, message: '请设置左轮前进增益系数' }]}>
|
||||
<GainSliderInput min={0.1} max={1} step={0.01} />
|
||||
</Form.Item>
|
||||
<Form.Item label={<span style={{ fontWeight: 500 }}>左轮后退增益系数</span>} name="leftBackwardGain" rules={[{ required: true, message: '请设置左轮后退增益系数' }]}>
|
||||
<GainSliderInput min={0.1} max={1} step={0.01} />
|
||||
</Form.Item>
|
||||
<Form.Item label={<span style={{ fontWeight: 500 }}>右轮前进增益系数</span>} name="rightForwardGain" rules={[{ required: true, message: '请设置右轮前进增益系数' }]}>
|
||||
<GainSliderInput min={0.1} max={1} step={0.01} />
|
||||
</Form.Item>
|
||||
<Form.Item label={<span style={{ fontWeight: 500 }}>右轮后退增益系数</span>} name="rightBackwardGain" rules={[{ required: true, message: '请设置右轮后退增益系数' }]}>
|
||||
<GainSliderInput min={0.1} max={1} step={0.01} />
|
||||
</Form.Item>
|
||||
<Form.Item style={{ marginTop: 20, marginBottom: 8 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 10 }}>
|
||||
<Button onClick={() => setBatchParamModalVisible(false)} style={{ borderRadius: 8, padding: '4px 20px' }}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" style={{ borderRadius: 8, padding: '4px 24px' }}>确认批量保存</Button>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
</>
|
||||
) : activeTab === 'drone' ? (
|
||||
|
||||
@@ -128,7 +128,7 @@ export default function UserRolePage() {
|
||||
const params = {
|
||||
pageNum: userPagination.pageNum,
|
||||
pageSize: userPagination.pageSize,
|
||||
orgId: currentStation?.orgId,
|
||||
orgId: userInfo?.orgId,
|
||||
//siteId: stationId,
|
||||
};
|
||||
getUser(params).then(res => {
|
||||
@@ -718,7 +718,7 @@ export default function UserRolePage() {
|
||||
<Select
|
||||
placeholder="请选择场站"
|
||||
allowClear
|
||||
disabled={siteDisabled}
|
||||
//disabled={siteDisabled}
|
||||
>
|
||||
{siteList.map(item => (
|
||||
<Select.Option key={item.id} value={item.id}>{item.siteName}</Select.Option>
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
Layout, Card, Row, Col, Statistic, Tag, Button, Table,
|
||||
Typography, Space, Progress, Badge, Timeline, message,
|
||||
Select, Modal, Space as AntSpace,
|
||||
Input
|
||||
Input, Tooltip
|
||||
} from 'antd';
|
||||
import {
|
||||
EnvironmentOutlined, RobotOutlined, BranchesOutlined,
|
||||
@@ -27,7 +27,8 @@ import AgoraTextTest from '../AgoraRtc.tsx';
|
||||
import { useWebRTCPlayer } from '../useWebRTCStream.tsx';
|
||||
import VideoPlayer from '../VideoPlayer.tsx';
|
||||
import CesiumMap from '../Map.jsx';
|
||||
import { getUAVState, getSiteDevice, getSiteUAVList, getsinglePlan, getRobotTaskList, getDeviceTotalData, updateDeviceAliasApi } from '@/api/device.ts';
|
||||
import DeviceParamModal from './DeviceParamModal';
|
||||
import { getUAVState, getSiteDevice, getSiteUAVList, getsinglePlan, getRobotTaskList, getDeviceTotalData, updateDeviceAliasApi, hasPermission } from '@/api/device.ts';
|
||||
import dayjs from 'dayjs';
|
||||
import { useMqtt } from '@/hooks/useMqtt';
|
||||
import { useSelector } from 'react-redux';
|
||||
@@ -78,6 +79,11 @@ export default function DeviceOverviewPage() {
|
||||
const [currentEditRobot, setCurrentEditRobot] = useState(null);
|
||||
const [editAliasInput, setEditAliasInput] = useState('');
|
||||
const [editLoading, setEditLoading] = useState(false);
|
||||
|
||||
// 设备参数弹窗相关
|
||||
const [paramModalOpen, setParamModalOpen] = useState(false);
|
||||
const [currentParamDevice, setCurrentParamDevice] = useState<any>(null);
|
||||
|
||||
const navigate = useNavigate();
|
||||
console.log('stationId', stationId, currentStation);
|
||||
|
||||
@@ -414,6 +420,23 @@ export default function DeviceOverviewPage() {
|
||||
`webrtc://1.95.137.212/live/livestream/${selectedDevice?.serialNumber}`,
|
||||
);
|
||||
|
||||
const getDevivePermisstion = (data) => {
|
||||
const params = {
|
||||
deviceId: data.serialNumber,
|
||||
}
|
||||
|
||||
hasPermission(params).then(res => {
|
||||
if (res.code == 200) {
|
||||
if (res.data) {
|
||||
setCurrentParamDevice(data);
|
||||
setParamModalOpen(true);
|
||||
} else {
|
||||
utils.message.error('无权限');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 顶部统计卡片
|
||||
|
||||
//feStatus; 1任务中 / 2空闲
|
||||
@@ -657,7 +680,7 @@ export default function DeviceOverviewPage() {
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 120,
|
||||
width: 150,
|
||||
//fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<Space size={4}>
|
||||
@@ -669,7 +692,17 @@ export default function DeviceOverviewPage() {
|
||||
onClick={() => openEditRobotModal(record)}
|
||||
title="编辑"
|
||||
/>
|
||||
<Button size="small" type="text" icon={<SettingOutlined />} title="设置" />
|
||||
<Tooltip title="设备参数设置">
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
icon={<SettingOutlined />}
|
||||
onClick={() => {
|
||||
getDevivePermisstion(record);
|
||||
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Space>
|
||||
)
|
||||
}]}
|
||||
@@ -1027,6 +1060,19 @@ export default function DeviceOverviewPage() {
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
{/* 设备参数查看与修改弹窗(通用组件) */}
|
||||
<DeviceParamModal
|
||||
open={paramModalOpen}
|
||||
device={currentParamDevice}
|
||||
onCancel={() => {
|
||||
setParamModalOpen(false);
|
||||
setCurrentParamDevice(null);
|
||||
}}
|
||||
onSuccess={() => {
|
||||
fetchAllData();
|
||||
}}
|
||||
/>
|
||||
|
||||
</Content>
|
||||
</div>
|
||||
);
|
||||
|
||||
318
src/components/devices/DeviceParamModal.tsx
Normal file
318
src/components/devices/DeviceParamModal.tsx
Normal file
@@ -0,0 +1,318 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
Form,
|
||||
Card,
|
||||
Row,
|
||||
Col,
|
||||
InputNumber,
|
||||
Input,
|
||||
Checkbox,
|
||||
Slider,
|
||||
Button,
|
||||
Space,
|
||||
} 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 handleSliderChange = (val) => {
|
||||
onChange?.(val);
|
||||
};
|
||||
const handleInputChange = (val) => {
|
||||
let num = Number(val);
|
||||
if (isNaN(num)) num = min;
|
||||
num = Math.max(min, Math.min(max, num));
|
||||
onChange?.(Number(num.toFixed(2)));
|
||||
};
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 12,
|
||||
padding: '8px 12px',
|
||||
background: disabled ? '#fafafa' : 'linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%)',
|
||||
borderRadius: 10,
|
||||
border: '1px solid',
|
||||
borderColor: disabled ? '#f0f0f0' : '#e4e8ed',
|
||||
transition: 'all 0.3s ease',
|
||||
boxShadow: disabled ? 'none' : '0 2px 6px rgba(0,0,0,0.04)',
|
||||
}}>
|
||||
<Slider
|
||||
style={{ flex: 1, margin: 0 }}
|
||||
disabled={disabled}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
value={typeof value === 'number' ? value : min}
|
||||
onChange={handleSliderChange}
|
||||
tooltip={{ formatter: (v) => `${v?.toFixed(2)}` }}
|
||||
marks={{
|
||||
[min]: { style: { color: '#8c8c8c', fontSize: 10 }, label: min },
|
||||
[(min + max) / 2]: { style: { color: '#8c8c8c', fontSize: 10 }, label: ((min + max) / 2).toFixed(2) },
|
||||
[max]: { style: { color: '#8c8c8c', fontSize: 10 }, label: max },
|
||||
}}
|
||||
/>
|
||||
<InputNumber
|
||||
disabled={disabled}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
value={value}
|
||||
onChange={handleInputChange}
|
||||
style={{
|
||||
width: 72,
|
||||
borderRadius: 8,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const paramFieldConfigs = [
|
||||
{ key: 'leftForwardGain', label: '左轮前进增益', type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
|
||||
{ key: 'leftBackwardGain', label: '左轮后退增益', type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
|
||||
{ key: 'rightForwardGain', label: '右轮前进增益', type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
|
||||
{ key: 'rightBackwardGain', label: '右轮后退增益', type: 'InputNumber', editable: true, min: 0, max: 1, step: 0.01 },
|
||||
|
||||
{ key: 'runSpeed', label: '运行速度', type: 'InputNumber', editable: true },
|
||||
{ key: 'chipUidSign', label: '芯片UID固化标志位', type: 'InputNumber', editable: false },
|
||||
{ key: 'chipUid', label: '芯片UID', type: 'Input', editable: false },
|
||||
{ key: 'remoteConfig', label: '遥控器通道配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'knifeMotorMode', label: '割刀电机模式', type: 'InputNumber', editable: false },
|
||||
{ key: 'walkMotorMode', label: '行走电机模式', type: 'InputNumber', editable: false },
|
||||
{ key: 'leftMotorReverse', label: '左轮电机方向极性', type: 'InputNumber', editable: false },
|
||||
{ key: 'rightMotorReverse', label: '右轮电机方向极性', type: 'InputNumber', editable: false },
|
||||
{ key: 'swapChannel', label: '左右轮通道互换标志', type: 'InputNumber', editable: false },
|
||||
{ key: 'use4G', label: '联网标志位', type: 'InputNumber', editable: false },
|
||||
{ key: 'forwardSpeedLimit', label: '前进速度限制', type: 'InputNumber', editable: false },
|
||||
{ key: 'turnSpeedLimit', label: '转向速度限制', type: 'InputNumber', editable: false },
|
||||
{ key: 'knifePolarity', label: '割刀通道极性', type: 'InputNumber', editable: false },
|
||||
{ key: 'fanPolarity', label: '风门通道极性', type: 'InputNumber', editable: false },
|
||||
{ key: 'throttlePolarity', label: '油门通道极性', type: 'InputNumber', editable: false },
|
||||
{ key: 'liftProtectTime', label: '底盘升降电机保护时间', type: 'InputNumber', editable: false },
|
||||
{ key: 'dualRtk', label: 'RTK配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'knifeChannel', label: '割刀通道配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'fanChannel', label: '风门通道配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'throttleChannel', label: '油门通道配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'remoteType', label: '遥控器类型', type: 'InputNumber', editable: false },
|
||||
{ key: 'relayBoard', label: '是否搭载继电器板', type: 'Checkbox', editable: false },
|
||||
{ key: 'liftChannel', label: '底盘升通道配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'chassisChannel', label: '底盘降通道配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'armChannel', label: '抱闸通道配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'fuelPumpChannel', label: '燃油励磁通道配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'wifiName', label: 'wifi名称', type: 'Input', editable: false },
|
||||
{ key: 'wifiPassword', label: 'wifi密码', type: 'Input', editable: false },
|
||||
{ key: 'batteryType', label: '电池类型', type: 'InputNumber', editable: false },
|
||||
{ key: 'driveType', label: '行走驱动配置', type: 'InputNumber', editable: false },
|
||||
{ key: 'gearRatio', label: '转速比', type: 'InputNumber', editable: false, step: 0.01 },
|
||||
{ key: 'robotLength', label: '机器人长度', type: 'InputNumber', editable: false, step: 0.01 },
|
||||
{ key: 'robotWidth', label: '机器人宽度', type: 'InputNumber', editable: false, step: 0.01 },
|
||||
{ key: 'robotHeight', label: '机器人高度', type: 'InputNumber', editable: false, step: 0.01 },
|
||||
{ key: 'knifeWidth', label: '割刀宽度', type: 'InputNumber', editable: false, step: 0.01 },
|
||||
{ key: 'tyreSize', label: '轮胎尺寸', type: 'InputNumber', editable: false, step: 0.01 },
|
||||
{ key: 'firmwareVersion', label: '固件版本', 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: '备注', type: 'Input', editable: false },
|
||||
{ key: 'delFlag', label: '删除标志', type: 'Checkbox', editable: false },
|
||||
];
|
||||
|
||||
const editableKeys = ['leftForwardGain', 'leftBackwardGain', 'rightForwardGain', 'rightBackwardGain'];
|
||||
|
||||
interface DeviceParamModalProps {
|
||||
open: boolean;
|
||||
device?: {
|
||||
serialNumber?: string;
|
||||
device_sn?: string;
|
||||
deviceAlias?: string;
|
||||
deviceName?: string;
|
||||
callsign?: string;
|
||||
drone_callsign?: string;
|
||||
[key: string]: any;
|
||||
} | null;
|
||||
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 deviceId = device?.serialNumber || device?.device_sn || '';
|
||||
const deviceName = device?.deviceAlias || device?.deviceName || device?.drone_callsign || device?.callsign || deviceId;
|
||||
|
||||
useEffect(() => {
|
||||
if (open && deviceId) {
|
||||
fetchParamData(deviceId);
|
||||
} else {
|
||||
setParamData(null);
|
||||
paramForm.resetFields();
|
||||
}
|
||||
}, [open, deviceId]);
|
||||
|
||||
const fetchParamData = async (id: string) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await deviceRunParamSelectByDeviceId({ deviceId: id });
|
||||
if (res.code == 200) {
|
||||
if (res.data) {
|
||||
setParamData(res.data);
|
||||
paramForm.setFieldsValue({ ...res.data });
|
||||
} else {
|
||||
setParamData(null);
|
||||
paramForm.resetFields();
|
||||
}
|
||||
} else {
|
||||
utils.message.error(res.msg || '获取参数失败');
|
||||
}
|
||||
} catch (err) {
|
||||
utils.message.error('获取参数失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const saveParam = async (values) => {
|
||||
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)),
|
||||
deviceId,
|
||||
siteId: stationId,
|
||||
orgId: currentStation?.orgId,
|
||||
id: paramData?.id,
|
||||
};
|
||||
const res = await deviceRunParamSave(payload);
|
||||
if (res.code === 200) {
|
||||
utils.message.success('保存参数成功');
|
||||
onSuccess?.();
|
||||
onCancel?.();
|
||||
} else {
|
||||
utils.message.error(res.msg || '保存参数失败');
|
||||
}
|
||||
} catch (err) {
|
||||
utils.message.error('操作异常');
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
setParamData(null);
|
||||
paramForm.resetFields();
|
||||
onCancel?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<span style={{
|
||||
display: 'inline-block',
|
||||
width: 4,
|
||||
height: 18,
|
||||
background: 'linear-gradient(180deg, #52c41a 0%, #389e0d 100%)',
|
||||
borderRadius: 2,
|
||||
}}></span>
|
||||
<span style={{ fontWeight: 600 }}>设备全部参数查看与增益修改</span>
|
||||
<span style={{ color: '#8c8c8c', fontSize: 13, fontWeight: 'normal' }}>
|
||||
- {deviceName}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
open={open}
|
||||
onCancel={handleCancel}
|
||||
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}>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceParamModal;
|
||||
Reference in New Issue
Block a user