修改
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
|||||||
PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined,
|
PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined,
|
||||||
AppstoreOutlined, SwapOutlined, VideoCameraOutlined
|
AppstoreOutlined, SwapOutlined, VideoCameraOutlined
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { addDeviceModel, getConnectTypes, getDeviceModelList, updateDeviceModel } from '../../api/deviceAccess.ts';
|
import { addDeviceModel, addProduct, getConnectTypes, getDeviceModelList, updateDeviceModel } from '../../api/deviceAccess.ts';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
const { TabPane } = Tabs;
|
const { TabPane } = Tabs;
|
||||||
@@ -101,6 +101,7 @@ export default function DeviceAccessPage() {
|
|||||||
const [itemModal, setItemModal] = useState(false);
|
const [itemModal, setItemModal] = useState(false);
|
||||||
const [itemType, setItemType] = useState<'props' | 'events' | 'actions'>('props');
|
const [itemType, setItemType] = useState<'props' | 'events' | 'actions'>('props');
|
||||||
const [itemForm] = Form.useForm();
|
const [itemForm] = Form.useForm();
|
||||||
|
const [thinsModelList, setThingsModelList] = useState([]);
|
||||||
|
|
||||||
// 指令 + 参数 + 枚举
|
// 指令 + 参数 + 枚举
|
||||||
const [actionModal, setActionModal] = useState(false);
|
const [actionModal, setActionModal] = useState(false);
|
||||||
@@ -112,6 +113,8 @@ export default function DeviceAccessPage() {
|
|||||||
const [mappingModal, setMappingModal] = useState(false);
|
const [mappingModal, setMappingModal] = useState(false);
|
||||||
const [mappingForm] = Form.useForm();
|
const [mappingForm] = Form.useForm();
|
||||||
const [protocolList, setProtocolList] = useState([]);
|
const [protocolList, setProtocolList] = useState([]);
|
||||||
|
const [propertyList, setPropertyList] = useState([]); // 物模型属性列表
|
||||||
|
const [selectedModelId, setSelectedModelId] = useState(''); // 选中的模型ID
|
||||||
|
|
||||||
// 筛选条件
|
// 筛选条件
|
||||||
const [filterForm] = Form.useForm();
|
const [filterForm] = Form.useForm();
|
||||||
@@ -179,10 +182,23 @@ export default function DeviceAccessPage() {
|
|||||||
setDeviceProtocol(record.protocolType);
|
setDeviceProtocol(record.protocolType);
|
||||||
setModelDetail(modelDetailList[record.modelId] || { props: [] });
|
setModelDetail(modelDetailList[record.modelId] || { props: [] });
|
||||||
}
|
}
|
||||||
if (type === 'product') setProductProtocol(record.protocolType || '');
|
if (type === 'product') {
|
||||||
|
setProductProtocol(record?.protocolCode || '');
|
||||||
|
// 编辑回显
|
||||||
|
const modelId = Object.keys(record?.thingsModels || {})[0] || '';
|
||||||
|
const limitConfig = record?.thingsModels?.[modelId] || {};
|
||||||
|
const targetModel = filteredModelList.find(m => m.id == modelId);
|
||||||
|
form.setFieldsValue({
|
||||||
|
...record,
|
||||||
|
modelId: modelId,
|
||||||
|
limitConfig: limitConfig,
|
||||||
|
propertyList: targetModel?.supportProperties || []
|
||||||
|
});
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (type === 'device') { setDeviceProtocol('onvif'); setModelDetail({ props: [] }); }
|
if (type === 'device') { setDeviceProtocol('onvif'); setModelDetail({ props: [] }); }
|
||||||
else if (type === 'product') setProductProtocol('');
|
else if (type === 'product') { setProductProtocol(''); setPropertyList([]) }
|
||||||
else setModelDetail({ props: [], events: [], actions: [] });
|
else setModelDetail({ props: [], events: [], actions: [] });
|
||||||
}
|
}
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
@@ -205,6 +221,20 @@ export default function DeviceAccessPage() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getModelAll = () => {
|
||||||
|
const params = {
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 999999,
|
||||||
|
|
||||||
|
};
|
||||||
|
getDeviceModelList(params).then(res => {
|
||||||
|
if (res.code === 200) {
|
||||||
|
setThingsModelList(res.rows);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// 筛选
|
// 筛选
|
||||||
const handleFilter = () => {
|
const handleFilter = () => {
|
||||||
setPagination(prev => ({ ...prev, current: 1 }));
|
setPagination(prev => ({ ...prev, current: 1 }));
|
||||||
@@ -269,6 +299,26 @@ export default function DeviceAccessPage() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (modalType === 'product') {
|
||||||
|
form.setFieldValue('modelId', selectedModelId);
|
||||||
|
const newValues = form.getFieldsValue();
|
||||||
|
const { modelId, limitConfig, ...params } = newValues;
|
||||||
|
// 生成你需要的格式
|
||||||
|
const thingsModels = {};
|
||||||
|
if (modelId) {
|
||||||
|
thingsModels[modelId] = limitConfig || {};
|
||||||
|
}
|
||||||
|
const submitData = {
|
||||||
|
...params,
|
||||||
|
thingsModels: thingsModels
|
||||||
|
};
|
||||||
|
addProduct(submitData).then(res => {
|
||||||
|
if (res.code == 200) {
|
||||||
|
message.success('新增产品成功');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -331,6 +381,7 @@ export default function DeviceAccessPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getConnectList();
|
getConnectList();
|
||||||
|
getModelAll();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// 表格列
|
// 表格列
|
||||||
@@ -515,44 +566,120 @@ export default function DeviceAccessPage() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{modalType === 'product' && (
|
{modalType === 'product' && (
|
||||||
<Tabs defaultActiveKey="base">
|
|
||||||
<TabPane tab="基础信息" key="base">
|
<>
|
||||||
<Form.Item label="产品名称" name="name" rules={[{ required: true }]}><Input /></Form.Item>
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<Form.Item label="厂商" name="manufacturer"><Input /></Form.Item>
|
<Form.Item label="产品编号" name="code" rules={[{ required: true }]}>
|
||||||
<Form.Item label="协议" name="protocolType">
|
<Input placeholder="PROD001" />
|
||||||
<Select value={productProtocol} onChange={setProductProtocol}>
|
</Form.Item>
|
||||||
|
<Form.Item label="产品名称" name="name" rules={[{ required: true }]}>
|
||||||
|
<Input placeholder="智能网关" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="厂商" name="manufacturer">
|
||||||
|
<Input placeholder="迈步科技" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="分类ID" name="categoryId">
|
||||||
|
<InputNumber style={{ width: '100%' }} min={1} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="协议" name="protocolCode" rules={[{ required: true }]}>
|
||||||
|
<Select placeholder="选择协议">
|
||||||
{protocolList.map(p => (
|
{protocolList.map(p => (
|
||||||
<Option key={p.code} value={p.code.toLowerCase()}>{p.name}</Option>
|
<Option key={p.code} value={p.code}>{p.name}</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{productProtocol === 'mqtt' && (
|
<Form.Item label="传输类型" name="transport">
|
||||||
<>
|
<Select placeholder="传输方式">
|
||||||
<Divider>MQTT Topic</Divider>
|
<Option value="tcp">TCP</Option>
|
||||||
<Form.Item label="上报Topic" name="publishTopic"><Input /></Form.Item>
|
<Option value="udp">UDP</Option>
|
||||||
<Form.Item label="订阅Topic" name="subscribeTopic"><Input /></Form.Item>
|
</Select>
|
||||||
</>
|
</Form.Item>
|
||||||
)}
|
<Form.Item label="上报Topic" name="uploadTopic">
|
||||||
</TabPane>
|
<Input placeholder="device/upload" />
|
||||||
<TabPane tab="字段映射" key="mapping">
|
</Form.Item>
|
||||||
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openMappingModal()} className="mb-2">新增</Button>
|
<Form.Item label="订阅Topic" name="subscribeTopic">
|
||||||
<Table size="small" dataSource={mappingList.filter(x => x.productId === editData?.id)} pagination={false}
|
<Input placeholder="device/subscribe" />
|
||||||
columns={[
|
</Form.Item>
|
||||||
{ title: '标准字段', dataIndex: 'standardCode' },
|
<Form.Item label="状态" name="status">
|
||||||
{ title: '厂商字段', dataIndex: 'sourceField' },
|
<Select>
|
||||||
{ title: '转换规则', dataIndex: 'convertRule' },
|
<Option value={1}>启用</Option>
|
||||||
{
|
<Option value={0}>禁用</Option>
|
||||||
title: '操作', render: r => (
|
</Select>
|
||||||
<Space>
|
</Form.Item>
|
||||||
<Button type="text" onClick={() => openMappingModal(r)}>编辑</Button>
|
</div>
|
||||||
<Popconfirm onConfirm={() => deleteMapping(r.id)}><Button type="text" danger>删除</Button></Popconfirm>
|
|
||||||
</Space>
|
{/* ============ 物模型选择(直接放在基础信息里) ============ */}
|
||||||
)
|
<Divider>物模型属性配置</Divider>
|
||||||
|
<Form.Item label="绑定物模型">
|
||||||
|
<Select
|
||||||
|
placeholder="请选择要绑定的物模型"
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
onChange={(modelId) => {
|
||||||
|
const model = thinsModelList.find(item => item.id === modelId);
|
||||||
|
console.log(model.supportProperties, "物模型")
|
||||||
|
if (model) {
|
||||||
|
setSelectedModelId(modelId);
|
||||||
|
setPropertyList(model.supportProperties || []); // 👈 用 state 立刻刷新
|
||||||
|
} else {
|
||||||
|
setSelectedModelId('');
|
||||||
|
setPropertyList([]);
|
||||||
}
|
}
|
||||||
]}
|
}}
|
||||||
/>
|
>
|
||||||
</TabPane>
|
{thinsModelList.map(item => (
|
||||||
</Tabs>
|
<Option key={item.id} value={item.id}>
|
||||||
|
{item.name}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
{/* 隐藏字段存储数据 */}
|
||||||
|
<Form.Item name="modelId" hidden ><Input /></Form.Item>
|
||||||
|
<Form.Item name="propertyList" hidden ><Input /></Form.Item>
|
||||||
|
|
||||||
|
{/* ============ 自动渲染属性 + min/max输入框 ============ */}
|
||||||
|
{/* ============ 自动渲染属性 + min/max输入框 ============ */}
|
||||||
|
<div style={{ marginTop: 12 }}>
|
||||||
|
{/* 👇 这里从 state 取,同步秒刷新 */}
|
||||||
|
{propertyList?.map((item) => (
|
||||||
|
<div key={item.id} style={{
|
||||||
|
padding: '12px 16px',
|
||||||
|
border: '1px solid #eee',
|
||||||
|
borderRadius: 8,
|
||||||
|
marginBottom: 8
|
||||||
|
}}>
|
||||||
|
<div style={{ marginBottom: 8, fontWeight: 500 }}>
|
||||||
|
{item.propertyName}({item.propertyKey})
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<Form.Item
|
||||||
|
label="最小值"
|
||||||
|
name={['limitConfig', item.propertyKey, 'min']}
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
|
||||||
|
>
|
||||||
|
<InputNumber style={{ width: '100%' }} placeholder="最小值" defaultValue={0} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label="最大值"
|
||||||
|
name={['limitConfig', item.propertyKey, 'max']}
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
>
|
||||||
|
<InputNumber style={{ width: '100%' }} placeholder="最大值" defaultValue={100} />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{(!propertyList || propertyList.length === 0) && (
|
||||||
|
<div style={{ color: '#999', textAlign: 'center', padding: 10 }}>
|
||||||
|
请选择物模型以显示属性
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{modalType === 'model' && (
|
{modalType === 'model' && (
|
||||||
|
|||||||
Reference in New Issue
Block a user