设备接入 和视频监测
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import {
|
||||
Card, Table, Button, Space, Form, Modal, Input, Select, InputNumber,
|
||||
Tabs, Tag, Popconfirm, message, Divider, Switch, Empty, Checkbox
|
||||
Tabs, Tag, Popconfirm, message, Divider, Switch, Empty, Checkbox,
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined,
|
||||
AppstoreOutlined, SwapOutlined, VideoCameraOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { addDeviceModel } from '../../api/deviceAccess.ts';
|
||||
import { addDeviceModel, getDeviceModelList } from '../../api/deviceAccess.ts';
|
||||
|
||||
const { Option } = Select;
|
||||
const { TabPane } = Tabs;
|
||||
@@ -20,18 +20,18 @@ const productList = [
|
||||
},
|
||||
{
|
||||
id: 2, name: '大华摄像头', code: 'dahua', protocolType: 'rtsp', manufacturer: '大华',
|
||||
publishTopic: '/dahua/device/upload', subscribeTopic: '/dahua/device/cmd'
|
||||
publishTopic: '/dahua/upload', subscribeTopic: '/dahua/cmd'
|
||||
},
|
||||
{
|
||||
id: 3, name: '通用MQTT设备', code: 'mqtt_device', protocolType: 'mqtt', manufacturer: '通用',
|
||||
publishTopic: '/iot/device/upload', subscribeTopic: '/iot/device/cmd'
|
||||
publishTopic: '/iot/upload', subscribeTopic: '/iot/cmd'
|
||||
},
|
||||
];
|
||||
|
||||
const modelList = [
|
||||
{ id: 10, name: '通用视频监控设备', code: 'video_camera', desc: '摄像头、云台、告警' },
|
||||
{ id: 11, name: '环境监测设备', code: 'env_sensor', desc: '温湿度、烟感' },
|
||||
{ id: 12, name: '电池供电设备', code: 'battery_device', desc: '电量、电压监测' },
|
||||
{ id: 10, name: '通用视频监控设备', code: 'video_camera', desc: '摄像头、云台、告警', connectType: 'MQTT' },
|
||||
{ id: 11, name: '环境监测设备', code: 'env_sensor', desc: '温湿度、烟感', connectType: 'MQTT' },
|
||||
{ id: 12, name: '电池供电设备', code: 'battery_device', desc: '电量、电压监测', connectType: 'HTTP' },
|
||||
];
|
||||
|
||||
const modelDetailList: Record<number, {
|
||||
@@ -112,6 +112,17 @@ export default function DeviceAccessPage() {
|
||||
const [mappingModal, setMappingModal] = useState(false);
|
||||
const [mappingForm] = Form.useForm();
|
||||
|
||||
// 筛选条件
|
||||
const [filterForm] = Form.useForm();
|
||||
const [filteredModelList, setFilteredModelList] = useState(modelList);
|
||||
|
||||
// ========== 物模型分页(只加这里) ==========
|
||||
const [pagination, setPagination] = useState({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: modelList.length,
|
||||
});
|
||||
|
||||
// 打开弹窗
|
||||
const openModal = (type: string, record?: any) => {
|
||||
setModalType(type);
|
||||
@@ -134,7 +145,44 @@ export default function DeviceAccessPage() {
|
||||
setVisible(true);
|
||||
};
|
||||
|
||||
// ===================== 物模型提交(完全匹配你的JSON) =====================
|
||||
// 获取物模型列表(带分页 + 筛选)
|
||||
const getModel = () => {
|
||||
const values = filterForm.getFieldsValue();
|
||||
const params = {
|
||||
pageNum: pagination.current,
|
||||
pageSize: pagination.pageSize,
|
||||
name: values.name || '',
|
||||
connectType: values.connectType || '',
|
||||
};
|
||||
getDeviceModelList(params).then(res => {
|
||||
// 接口返回格式自行替换:res.list / res.total
|
||||
if (res.code === 200) {
|
||||
// setFilteredModelList(res.data.list);
|
||||
// setPagination(prev => ({ ...prev, total: res.data.total }));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 筛选
|
||||
const handleFilter = () => {
|
||||
setPagination(prev => ({ ...prev, current: 1 }));
|
||||
setTimeout(() => getModel(), 0);
|
||||
};
|
||||
|
||||
// 重置
|
||||
const handleReset = () => {
|
||||
filterForm.resetFields();
|
||||
setPagination(prev => ({ ...prev, current: 1 }));
|
||||
setTimeout(() => getModel(), 0);
|
||||
};
|
||||
|
||||
// 分页切换
|
||||
const handleTableChange = (pag) => {
|
||||
setPagination(pag);
|
||||
getModel();
|
||||
};
|
||||
|
||||
// ===================== 物模型提交 =====================
|
||||
const handleSubmit = () => {
|
||||
form.validateFields().then(values => {
|
||||
if (modalType === 'model') {
|
||||
@@ -161,12 +209,10 @@ export default function DeviceAccessPage() {
|
||||
addDeviceModel(submitData).then(res => {
|
||||
if (res.code === 200) {
|
||||
message.success('物模型保存成功');
|
||||
getModel(); // 保存后刷新列表
|
||||
}
|
||||
});
|
||||
console.log('✅ 最终提交物模型(完全匹配接口)', submitData);
|
||||
message.success('物模型保存成功');
|
||||
} else {
|
||||
message.success('保存成功');
|
||||
console.log('✅ 提交物模型', submitData);
|
||||
}
|
||||
setVisible(false);
|
||||
});
|
||||
@@ -205,25 +251,29 @@ export default function DeviceAccessPage() {
|
||||
if (val.id) {
|
||||
const index = newList.findIndex(x => x.id === val.id);
|
||||
if (index >= 0) newList[index] = val;
|
||||
message.success('字段映射修改成功');
|
||||
message.success('修改成功');
|
||||
} else {
|
||||
newList.push({ ...val, id: Date.now() });
|
||||
message.success('字段映射新增成功');
|
||||
message.success('新增成功');
|
||||
}
|
||||
setMappingList(newList);
|
||||
mappingInitList = newList;
|
||||
setMappingModal(false);
|
||||
});
|
||||
};
|
||||
const deleteMapping = (id: number) => {
|
||||
const newList = mappingList.filter(x => x.id !== id);
|
||||
setMappingList(newList);
|
||||
mappingInitList = newList;
|
||||
message.success('字段映射删除成功');
|
||||
message.success('删除成功');
|
||||
};
|
||||
|
||||
const getAlarmProps = () => modelDetail?.props?.filter(item => item.isAlarm) || [];
|
||||
|
||||
useEffect(() => {
|
||||
if (activeTab === 'model') {
|
||||
getModel();
|
||||
}
|
||||
}, [ pagination.pageSize, activeTab]);
|
||||
|
||||
// 表格列
|
||||
const deviceColumns = [
|
||||
{ title: '设备名称', dataIndex: 'name' },
|
||||
@@ -253,6 +303,7 @@ export default function DeviceAccessPage() {
|
||||
|
||||
const modelColumns = [
|
||||
{ title: '模型名称', dataIndex: 'name' },
|
||||
{ title: '连接协议', dataIndex: 'connectType' },
|
||||
{ title: '操作', render: r => <Button type="text" icon={<EditOutlined />} onClick={() => openModal('model', r)}>编辑</Button> }
|
||||
];
|
||||
|
||||
@@ -268,7 +319,40 @@ export default function DeviceAccessPage() {
|
||||
|
||||
{activeTab === 'device' && <Card><Space className="mb-3"><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('device')}>新增设备</Button></Space><Table rowKey="id" columns={deviceColumns} dataSource={deviceList} /></Card>}
|
||||
{activeTab === 'product' && <Card><Space className="mb-3"><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('product')}>新增产品</Button></Space><Table rowKey="id" columns={productColumns} dataSource={productList} /></Card>}
|
||||
{activeTab === 'model' && <Card><Space className="mb-3"><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('model')}>新增物模型</Button></Space><Table rowKey="id" columns={modelColumns} dataSource={modelList} /></Card>}
|
||||
|
||||
{/* 物模型 + 筛选 + 分页 */}
|
||||
{activeTab === 'model' && (
|
||||
<Card>
|
||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||
<Form form={filterForm} layout="inline">
|
||||
<Form.Item name="name" label="模型名称">
|
||||
<Input placeholder="名称" allowClear />
|
||||
</Form.Item>
|
||||
<Form.Item name="connectType" label="连接协议">
|
||||
<Select placeholder="协议" allowClear style={{ width: 160 }}>
|
||||
<Option value="MQTT">MQTT</Option>
|
||||
<Option value="HTTP">HTTP</Option>
|
||||
<Option value="RTSP">RTSP</Option>
|
||||
<Option value="ONVIF">ONVIF</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" onClick={handleFilter}>查询</Button>
|
||||
<Button onClick={handleReset}>重置</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('model')}>新增物模型</Button>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={modelColumns}
|
||||
dataSource={filteredModelList}
|
||||
pagination={pagination}
|
||||
onChange={handleTableChange}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Modal open={visible} width={900} onCancel={() => setVisible(false)} onOk={handleSubmit} destroyOnClose
|
||||
title={modalType === 'device' ? '设备配置' : modalType === 'product' ? '产品配置' : '物模型配置'}>
|
||||
@@ -284,19 +368,43 @@ export default function DeviceAccessPage() {
|
||||
<TabPane tab="协议配置" key="protocol">
|
||||
<Form.Item label="设备协议类型" name="protocolType" rules={[{ required: true }]}>
|
||||
<Select value={deviceProtocol} onChange={setDeviceProtocol}>
|
||||
<Option value="onvif">ONVIF 协议</Option>
|
||||
<Option value="rtsp">RTSP 视频流</Option>
|
||||
<Option value="mqtt">MQTT 物联网协议</Option>
|
||||
<Option value="onvif">ONVIF</Option>
|
||||
<Option value="rtsp">RTSP</Option>
|
||||
<Option value="mqtt">MQTT</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Divider />
|
||||
{deviceProtocol === 'onvif' && <><Form.Item label="设备IP地址" name="ip"><Input /></Form.Item><Form.Item label="访问端口" name="port"><InputNumber className="w-full" /></Form.Item><Form.Item label="登录账号" name="username"><Input /></Form.Item><Form.Item label="登录密码" name="password"><Input.Password /></Form.Item></>}
|
||||
{deviceProtocol === 'rtsp' && <Form.Item label="RTSP 完整流地址" name="rtspUrl"><Input /></Form.Item>}
|
||||
{deviceProtocol === 'mqtt' && <><Form.Item label="MQTT 服务地址" name="mqttServer"><Input /></Form.Item><Form.Item label="MQTT 端口" name="mqttPort"><InputNumber defaultValue={1883} /></Form.Item><Form.Item label="设备 ClientID" name="clientId"><Input /></Form.Item><Form.Item label="MQTT 用户名" name="mqttUsername"><Input /></Form.Item><Form.Item label="MQTT 密码" name="mqttPassword"><Input.Password /></Form.Item></>}
|
||||
{deviceProtocol === 'onvif' && (
|
||||
<>
|
||||
<Form.Item label="IP" name="ip"><Input /></Form.Item>
|
||||
<Form.Item label="端口" name="port"><InputNumber className="w-full" /></Form.Item>
|
||||
<Form.Item label="账号" name="username"><Input /></Form.Item>
|
||||
<Form.Item label="密码" name="password"><Input.Password /></Form.Item>
|
||||
</>
|
||||
)}
|
||||
{deviceProtocol === 'rtsp' && <Form.Item label="RTSP地址" name="rtspUrl"><Input /></Form.Item>}
|
||||
{deviceProtocol === 'mqtt' && (
|
||||
<>
|
||||
<Form.Item label="MQTT服务地址" name="mqttServer"><Input /></Form.Item>
|
||||
<Form.Item label="端口" name="mqttPort"><InputNumber defaultValue={1883} /></Form.Item>
|
||||
<Form.Item label="ClientID" name="clientId"><Input /></Form.Item>
|
||||
<Form.Item label="用户名" name="mqttUsername"><Input /></Form.Item>
|
||||
<Form.Item label="密码" name="mqttPassword"><Input.Password /></Form.Item>
|
||||
</>
|
||||
)}
|
||||
</TabPane>
|
||||
<TabPane tab="报警阈值" key="alarm">
|
||||
{getAlarmProps().map(item => <div key={item.code}><Form.Item label={`${item.name} 上限`} name={['alarmConfig', `${item.code}Max`]}><InputNumber className="w-full" /></Form.Item><Form.Item label={`${item.name} 下限`} name={['alarmConfig', `${item.code}Min`]}><InputNumber className="w-full" /></Form.Item></div>)}
|
||||
{getAlarmProps().length === 0 && <Empty description="当前物模型无配置告警参数" />}
|
||||
{getAlarmProps().map(item => (
|
||||
<div key={item.code} className="flex gap-2">
|
||||
<Form.Item label={`${item.name}上限`} name={['alarmConfig', `${item.code}Max`]} style={{ flex: 1 }}>
|
||||
<InputNumber className="w-full" />
|
||||
</Form.Item>
|
||||
<Form.Item label={`${item.name}下限`} name={['alarmConfig', `${item.code}Min`]} style={{ flex: 1 }}>
|
||||
<InputNumber className="w-full" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
))}
|
||||
{getAlarmProps().length === 0 && <Empty description="无告警参数" />}
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
)}
|
||||
@@ -305,22 +413,28 @@ export default function DeviceAccessPage() {
|
||||
<Tabs defaultActiveKey="base">
|
||||
<TabPane tab="基础信息" key="base">
|
||||
<Form.Item label="产品名称" name="name" rules={[{ required: true }]}><Input /></Form.Item>
|
||||
<Form.Item label="厂商名称" name="manufacturer"><Input /></Form.Item>
|
||||
<Form.Item label="默认协议类型" name="protocolType"><Select value={productProtocol} onChange={setProductProtocol}><Option value="onvif">ONVIF</Option><Option value="rtsp">RTSP</Option><Option value="mqtt">MQTT</Option></Select></Form.Item>
|
||||
{productProtocol === 'mqtt' && <><Divider>MQTT 厂商级 Topic 配置</Divider><Form.Item label="设备上报 Topic" name="publishTopic"><Input /></Form.Item><Form.Item label="平台下发 Topic" name="subscribeTopic"><Input /></Form.Item></>}
|
||||
<Form.Item label="厂商" name="manufacturer"><Input /></Form.Item>
|
||||
<Form.Item label="协议" name="protocolType"><Select value={productProtocol} onChange={setProductProtocol}><Option value="onvif">ONVIF</Option><Option value="rtsp">RTSP</Option><Option value="mqtt">MQTT</Option></Select></Form.Item>
|
||||
{productProtocol === 'mqtt' && (
|
||||
<>
|
||||
<Divider>MQTT Topic</Divider>
|
||||
<Form.Item label="上报Topic" name="publishTopic"><Input /></Form.Item>
|
||||
<Form.Item label="订阅Topic" name="subscribeTopic"><Input /></Form.Item>
|
||||
</>
|
||||
)}
|
||||
</TabPane>
|
||||
<TabPane tab="字段映射" key="mapping">
|
||||
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openMappingModal()} className="mb-2">新增映射</Button>
|
||||
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openMappingModal()} className="mb-2">新增</Button>
|
||||
<Table size="small" dataSource={mappingList.filter(x => x.productId === editData?.id)} pagination={false}
|
||||
columns={[
|
||||
{ title: '标准字段', dataIndex: 'standardCode' },
|
||||
{ title: '厂商原始字段', dataIndex: 'sourceField' },
|
||||
{ title: '厂商字段', dataIndex: 'sourceField' },
|
||||
{ title: '转换规则', dataIndex: 'convertRule' },
|
||||
{
|
||||
title: '操作', render: r => (
|
||||
<Space>
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => openMappingModal(r)}>编辑</Button>
|
||||
<Popconfirm onConfirm={() => deleteMapping(r.id)} title="确定删除?"><Button type="text" danger icon={<DeleteOutlined />}>删除</Button></Popconfirm>
|
||||
<Button type="text" onClick={() => openMappingModal(r)}>编辑</Button>
|
||||
<Popconfirm onConfirm={() => deleteMapping(r.id)}><Button type="text" danger>删除</Button></Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
@@ -332,26 +446,20 @@ export default function DeviceAccessPage() {
|
||||
|
||||
{modalType === 'model' && (
|
||||
<>
|
||||
<div style={{ display: "flex", gap: 16, marginBottom: 16 }}>
|
||||
<div style={{ flex: 1 }}>
|
||||
<Form.Item label="模型名称" name="name" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<div className="flex gap-4 mb-4">
|
||||
<div className="flex-1">
|
||||
<Form.Item label="模型名称" name="name" rules={[{ required: true }]}><Input /></Form.Item>
|
||||
</div>
|
||||
<div style={{ flex: 1 }}>
|
||||
<Form.Item label="连接协议" name="connectType" initialValue="MQTT">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<div className="flex-1">
|
||||
<Form.Item label="连接协议" name="connectType" initialValue="MQTT"><Input /></Form.Item>
|
||||
</div>
|
||||
<div style={{ flex: 1 }}>
|
||||
<Form.Item label="设备类型" name="deviceType" initialValue={1}>
|
||||
<InputNumber style={{ width: "100%" }} />
|
||||
</Form.Item>
|
||||
<div className="flex-1">
|
||||
<Form.Item label="设备类型" name="deviceType" initialValue={1}><InputNumber style={{ width: '100%' }} /></Form.Item>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Divider>属性列表</Divider>
|
||||
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openItemModal('props')} className="mb-2">新增属性</Button>
|
||||
<Divider>属性</Divider>
|
||||
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openItemModal('props')} className="mb-2">新增</Button>
|
||||
<Table size="small" dataSource={modelDetail.props} pagination={false} columns={[
|
||||
{ title: '编码', dataIndex: 'code' },
|
||||
{ title: '名称', dataIndex: 'name' },
|
||||
@@ -362,43 +470,34 @@ export default function DeviceAccessPage() {
|
||||
{
|
||||
title: '操作', render: r => (
|
||||
<Space>
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => openItemModal('props', r)}>编辑</Button>
|
||||
<Popconfirm onConfirm={() => deleteItem('props', r.id)}>
|
||||
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
|
||||
</Popconfirm>
|
||||
<Button type="text" onClick={() => openItemModal('props', r)}>编辑</Button>
|
||||
<Popconfirm onConfirm={() => deleteItem('props', r.id)}><Button type="text" danger>删除</Button></Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
]} />
|
||||
|
||||
<Divider>指令列表</Divider>
|
||||
<Divider>指令</Divider>
|
||||
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => {
|
||||
setCurrentAction({ actionId: '', actionName: '', params: {} });
|
||||
setParamList([{ paramKey: '', type: 'int', desc: '', defaultValue: '', enum: [] }]);
|
||||
setActionModal(true);
|
||||
}} className="mb-2">新增指令</Button>
|
||||
}} className="mb-2">新增</Button>
|
||||
<Table size="small" dataSource={modelDetail.actions} pagination={false} columns={[
|
||||
{ title: '指令编码', dataIndex: 'actionId' },
|
||||
{ title: '指令名称', dataIndex: 'actionName' },
|
||||
{ title: '参数', render: r => Object.keys(r.params || {}).join(',') || '无' },
|
||||
{ title: '参数', render: r => Object.keys(r.params || []).join(',') || '无' },
|
||||
{
|
||||
title: '操作', render: r => (
|
||||
<Space>
|
||||
<Button type="text" onClick={() => {
|
||||
setCurrentAction(r);
|
||||
const arr = [];
|
||||
for (let k in r.params) {
|
||||
arr.push({ paramKey: k, ...r.params[k] });
|
||||
}
|
||||
for (let k in r.params) arr.push({ paramKey: k, ...r.params[k] });
|
||||
setParamList(arr);
|
||||
setActionModal(true);
|
||||
}}>编辑</Button>
|
||||
<Popconfirm onConfirm={() => {
|
||||
setModelDetail({
|
||||
...modelDetail,
|
||||
actions: modelDetail.actions.filter(x => x.actionId !== r.actionId)
|
||||
})
|
||||
}}>
|
||||
<Popconfirm onConfirm={() => setModelDetail({ ...modelDetail, actions: modelDetail.actions.filter(x => x.actionId !== r.actionId) })}>
|
||||
<Button type="text" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
@@ -410,13 +509,13 @@ export default function DeviceAccessPage() {
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
{/* 属性弹窗:完整字段 */}
|
||||
{/* 属性弹窗 */}
|
||||
<Modal open={itemModal} width={580} zIndex={1001} destroyOnClose onCancel={() => setItemModal(false)} onOk={saveItem} title="配置属性">
|
||||
<Form form={itemForm} layout="vertical">
|
||||
<Form.Item name="id" hidden><Input /></Form.Item>
|
||||
<Form.Item label="属性编码" name="code" rules={[{ required: true }]}><Input placeholder="如 temperature" /></Form.Item>
|
||||
<Form.Item label="属性编码" name="code" rules={[{ required: true }]}><Input placeholder="如 temp" /></Form.Item>
|
||||
<Form.Item label="属性名称" name="name" rules={[{ required: true }]}><Input placeholder="如 温度" /></Form.Item>
|
||||
<Form.Item label="数据类型" name="type">
|
||||
<Form.Item label="类型" name="type">
|
||||
<Select>
|
||||
<Option value="int">int</Option>
|
||||
<Option value="float">float</Option>
|
||||
@@ -424,105 +523,51 @@ export default function DeviceAccessPage() {
|
||||
<Option value="bool">bool</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="单位" name="unit"><Input placeholder="如 ℃、%、V" /></Form.Item>
|
||||
{/*<Form.Item label="是否必填" name="required" valuePropName="checked"><Switch /></Form.Item>*/}
|
||||
<Form.Item label="默认值" name="defaultValue"><Input placeholder="选填" /></Form.Item>
|
||||
<Form.Item label="是否作为告警参数" name="isAlarm" valuePropName="checked"><Switch /></Form.Item>
|
||||
<Form.Item label="单位" name="unit"><Input placeholder="℃、%、V" /></Form.Item>
|
||||
<Form.Item label="默认值" name="defaultValue"><Input /></Form.Item>
|
||||
<Form.Item label="告警参数" name="isAlarm" valuePropName="checked"><Switch /></Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
{/* 指令 + 参数 + 枚举 */}
|
||||
<Modal
|
||||
title="配置指令"
|
||||
open={actionModal}
|
||||
onCancel={() => setActionModal(false)}
|
||||
{/* 指令弹窗 */}
|
||||
<Modal title="配置指令" open={actionModal} zIndex={1002} onCancel={() => setActionModal(false)}
|
||||
onOk={() => {
|
||||
const params = paramList.reduce((obj, item) => {
|
||||
obj[item.paramKey] = {
|
||||
type: item.type,
|
||||
description: item.desc || '',
|
||||
default: item.defaultValue,
|
||||
...(item.enum?.length ? { enum: item.enum } : {})
|
||||
};
|
||||
obj[item.paramKey] = { type: item.type, description: item.desc, default: item.defaultValue, ...(item.enum?.length && { enum: item.enum }) };
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
const action = {
|
||||
actionId: currentAction.actionId,
|
||||
actionName: currentAction.actionName,
|
||||
params
|
||||
};
|
||||
|
||||
const action = { actionId: currentAction.actionId, actionName: currentAction.actionName, params };
|
||||
const exists = modelDetail.actions.some(x => x.actionId === currentAction.actionId);
|
||||
setModelDetail({
|
||||
...modelDetail,
|
||||
actions: exists
|
||||
? modelDetail.actions.map(x => x.actionId === currentAction.actionId ? action : x)
|
||||
: [...modelDetail.actions, action]
|
||||
actions: exists ? modelDetail.actions.map(x => x.actionId === currentAction.actionId ? action : x) : [...modelDetail.actions, action]
|
||||
});
|
||||
setActionModal(false);
|
||||
message.success('保存成功');
|
||||
}}
|
||||
width={750}
|
||||
>
|
||||
<div style={{ marginBottom: 16, display: 'flex', gap: 8 }}>
|
||||
<Input
|
||||
placeholder="指令编码 如 restart"
|
||||
value={currentAction?.actionId}
|
||||
onChange={(e) => setCurrentAction({ ...currentAction, actionId: e.target.value })}
|
||||
style={{ flex: 1 }}
|
||||
/>
|
||||
<Input
|
||||
placeholder="指令名称 如 重启设备"
|
||||
value={currentAction?.actionName}
|
||||
onChange={(e) => setCurrentAction({ ...currentAction, actionName: e.target.value })}
|
||||
style={{ flex: 1 }}
|
||||
/>
|
||||
width={750}>
|
||||
<div className="flex gap-2 mb-4">
|
||||
<Input placeholder="指令编码" value={currentAction?.actionId} onChange={e => setCurrentAction({ ...currentAction, actionId: e.target.value })} style={{ flex: 1 }} />
|
||||
<Input placeholder="指令名称" value={currentAction?.actionName} onChange={e => setCurrentAction({ ...currentAction, actionName: e.target.value })} style={{ flex: 1 }} />
|
||||
</div>
|
||||
|
||||
<Divider>指令参数(支持枚举)</Divider>
|
||||
|
||||
{/* 只保留 1 个参数,不支持新增多行 */}
|
||||
{paramList.length > 0 && (
|
||||
<div key={0} style={{ display: 'flex', gap: 8, marginBottom: 10, alignItems: 'center' }}>
|
||||
<Input placeholder="参数名" value={paramList[0].paramKey} onChange={(e) => {
|
||||
const arr = [...paramList];
|
||||
arr[0].paramKey = e.target.value;
|
||||
setParamList(arr);
|
||||
}} />
|
||||
<Select value={paramList[0].type} style={{ width: 100 }} onChange={(v) => {
|
||||
const arr = [...paramList];
|
||||
arr[0].type = v;
|
||||
setParamList(arr);
|
||||
}}>
|
||||
<Select.Option value="int">int</Select.Option>
|
||||
<Select.Option value="string">string</Select.Option>
|
||||
<Divider>指令参数</Divider>
|
||||
{paramList[0] && (
|
||||
<div className="flex gap-2 items-center">
|
||||
<Input placeholder="参数名" value={paramList[0].paramKey} onChange={e => setParamList([{ ...paramList[0], paramKey: e.target.value }])} />
|
||||
<Select value={paramList[0].type} style={{ width: 100 }} onChange={v => setParamList([{ ...paramList[0], type: v }])}>
|
||||
<Option value="int">int</Option><Option value="string">string</Option>
|
||||
</Select>
|
||||
<Input placeholder="描述" value={paramList[0].desc} onChange={(e) => {
|
||||
const arr = [...paramList];
|
||||
arr[0].desc = e.target.value;
|
||||
setParamList(arr);
|
||||
}} />
|
||||
<Input placeholder="默认值" value={paramList[0].defaultValue} onChange={(e) => {
|
||||
const arr = [...paramList];
|
||||
arr[0].defaultValue = e.target.value;
|
||||
setParamList(arr);
|
||||
}} />
|
||||
<Input placeholder="枚举,逗号分隔" value={paramList[0].enum?.join(',')} onChange={(e) => {
|
||||
const arr = [...paramList];
|
||||
arr[0].enum = e.target.value.split(',').map(s => s.trim());
|
||||
setParamList(arr);
|
||||
}} />
|
||||
<Input placeholder="描述" value={paramList[0].desc} onChange={e => setParamList([{ ...paramList[0], desc: e.target.value }])} />
|
||||
<Input placeholder="默认值" value={paramList[0].defaultValue} onChange={e => setParamList([{ ...paramList[0], defaultValue: e.target.value }])} />
|
||||
<Input placeholder="枚举(,分隔)" value={paramList[0].enum?.join(',')} onChange={e => setParamList([{ ...paramList[0], enum: e.target.value.split(',').map(s => s.trim()) }])} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
</Modal>
|
||||
|
||||
<Modal open={mappingModal} width={600} zIndex={1002} destroyOnClose onCancel={() => setMappingModal(false)} onOk={saveMapping} title="字段映射配置">
|
||||
{/* 字段映射 */}
|
||||
<Modal open={mappingModal} width={600} zIndex={1002} destroyOnClose onCancel={() => setMappingModal(false)} onOk={saveMapping} title="字段映射">
|
||||
<Form form={mappingForm} layout="vertical">
|
||||
<Form.Item name="id" hidden /><Form.Item name="productId" hidden />
|
||||
<Form.Item label="标准模型字段" name="standardCode" rules={[{ required: true }]}>
|
||||
<Form.Item label="标准字段" name="standardCode" rules={[{ required: true }]}>
|
||||
<Select>{modelDetail.props?.map(p => <Option key={p.code} value={p.code}>{p.name}</Option>)}</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="厂商原始字段" name="sourceField" rules={[{ required: true }]}><Input /></Form.Item>
|
||||
|
||||
Reference in New Issue
Block a user