设备接入

This commit is contained in:
mmc
2026-05-09 14:15:26 +08:00
parent e19aee3c14
commit dba6730380

View File

@@ -7,14 +7,11 @@ 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, addProduct, deleteModel, getConnectTypes, getDataTypesApi, getDeviceModelList, getProductPage, updateDeviceModel } from '../../api/deviceAccess.ts'; import { addDeviceModel, addProduct, deleteModel, getConnectTypes, getDataTypesApi, getDeviceModelList, getProductPage, updateDeviceModel, updateProduct } from '../../api/deviceAccess.ts';
const { Option } = Select; const { Option } = Select;
const { TabPane } = Tabs; const { TabPane } = Tabs;
const modelDetailList: Record<number, { const modelDetailList: Record<number, {
props: any[]; props: any[];
events: any[]; events: any[];
@@ -66,7 +63,6 @@ const deviceList = [
} }
]; ];
export default function DeviceAccessPage() { export default function DeviceAccessPage() {
const [activeTab, setActiveTab] = useState('device'); const [activeTab, setActiveTab] = useState('device');
const [form] = Form.useForm(); const [form] = Form.useForm();
@@ -91,14 +87,13 @@ export default function DeviceAccessPage() {
const [paramList, setParamList] = useState<any[]>([]); const [paramList, setParamList] = useState<any[]>([]);
const [dataTypeList, setDataTypeList] = useState([]); const [dataTypeList, setDataTypeList] = useState([]);
// 字段映射 // 字段映射
const [mappingList, setMappingList] = useState(mappingInitList); const [mappingList, setMappingList] = useState(mappingInitList);
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 [propertyList, setPropertyList] = useState([]);
const [selectedModelId, setSelectedModelId] = useState(''); // 选中的模型ID const [selectedModelId, setSelectedModelId] = useState('');
// 筛选条件 // 筛选条件
const [filterForm] = Form.useForm(); const [filterForm] = Form.useForm();
@@ -124,11 +119,10 @@ export default function DeviceAccessPage() {
// 删除物模型 // 删除物模型
const handleDeleteModel = (id) => { const handleDeleteModel = (id) => {
// 这里替换成你的真实删除接口
deleteModel(id).then(res => { deleteModel(id).then(res => {
if (res.code === 200) { if (res.code === 200) {
messageApi.success('删除成功'); messageApi.success('删除成功');
getModel(); // 删除后刷新列表 getModel();
} else { } else {
messageApi.error('删除失败:' + res.msg); messageApi.error('删除失败:' + res.msg);
} }
@@ -140,11 +134,12 @@ export default function DeviceAccessPage() {
setModalType(type); setModalType(type);
setEditData(record); setEditData(record);
form.resetFields(); form.resetFields();
setSelectedModelId('');
setPropertyList([]);
if (record) { if (record) {
form.setFieldsValue(record); form.setFieldsValue(record);
if (type === 'model') { if (type === 'model') {
// 接口数据 → 前端格式转换
const props = record.supportProperties?.map(p => ({ const props = record.supportProperties?.map(p => ({
id: p.id, id: p.id,
code: p.propertyKey, code: p.propertyKey,
@@ -168,27 +163,36 @@ export default function DeviceAccessPage() {
} }
if (type === 'product') { if (type === 'product') {
setProductProtocol(record?.protocolCode || ''); setProductProtocol(record?.protocolCode || '');
// 编辑回显 const modelId = record.thingsModels ? Object.keys(record.thingsModels)[0] : null;
const modelId = Object.keys(record?.thingsModels || {})[0] || ''; const limitConfig = modelId ? record.thingsModels[modelId] : {};
const limitConfig = record?.thingsModels?.[modelId] || {}; if (modelId) {
const targetModel = filteredModelList.find(m => m.id == modelId); const targetModel = thinsModelList.find(m => m.id == modelId);
setSelectedModelId(Number(modelId)); // 让选中值生效
setPropertyList(targetModel?.supportProperties || []);
form.setFieldsValue({ form.setFieldsValue({
...record, ...record,
modelId: modelId, modelId: modelId,
limitConfig: limitConfig, limitConfig: limitConfig
propertyList: targetModel?.supportProperties || []
}); });
setVisible(true); setTimeout(() => {
form.setFieldsValue({ modelId });
}, 100);
} else {
form.setFieldsValue(record);
setSelectedModelId('');
setPropertyList([]);
}
} }
} else { } else {
if (type === 'device') { setDeviceProtocol('onvif'); setModelDetail({ props: [] }); } if (type === 'device') { setDeviceProtocol('onvif'); setModelDetail({ props: [] }); }
else if (type === 'product') { setProductProtocol(''); setPropertyList([]) } else if (type === 'product') { setProductProtocol(''); setPropertyList([]); }
else setModelDetail({ props: [], events: [], actions: [] }); else setModelDetail({ props: [], events: [], actions: [] });
} }
setVisible(true); setVisible(true);
}; };
// 获取物模型列表(带分页 + 筛选) // 获取物模型列表
const getModel = () => { const getModel = () => {
const values = filterForm.getFieldsValue(); const values = filterForm.getFieldsValue();
const params = { const params = {
@@ -206,15 +210,10 @@ export default function DeviceAccessPage() {
}; };
const getModelAll = () => { const getModelAll = () => {
const params = { const params = { pageNum: 1, pageSize: 999999 };
pageNum: 1,
pageSize: 999999,
};
getDeviceModelList(params).then(res => { getDeviceModelList(params).then(res => {
if (res.code === 200) { if (res.code === 200) {
setThingsModelList(res.rows); setThingsModelList(res.rows);
} }
}); });
}; };
@@ -223,7 +222,7 @@ export default function DeviceAccessPage() {
const handleFilter = () => { const handleFilter = () => {
setPagination(prev => ({ ...prev, current: 1 })); setPagination(prev => ({ ...prev, current: 1 }));
if (activeTab === 'model') getModel(); if (activeTab === 'model') getModel();
if (activeTab === 'product') getProductList(); // 产品列表 if (activeTab === 'product') getProductList();
}; };
// 重置 // 重置
@@ -233,13 +232,14 @@ export default function DeviceAccessPage() {
if (activeTab === 'model') getModel(); if (activeTab === 'model') getModel();
if (activeTab === 'product') getProductList(); if (activeTab === 'product') getProductList();
}; };
const getDataTypes = () => { const getDataTypes = () => {
getDataTypesApi("").then(res => { getDataTypesApi("").then(res => {
if (res.code === 200) { if (res.code === 200) {
setDataTypeList(res.data || []); setDataTypeList(res.data || []);
} }
}) })
} };
// 分页切换 // 分页切换
const handleTableChange = (pag) => { const handleTableChange = (pag) => {
@@ -247,7 +247,8 @@ export default function DeviceAccessPage() {
if (activeTab === 'model') getModel(); if (activeTab === 'model') getModel();
if (activeTab === 'product') getProductList(); if (activeTab === 'product') getProductList();
}; };
// ====================== 获取产品列表 ======================
// 获取产品列表
const getProductList = () => { const getProductList = () => {
const values = filterForm.getFieldsValue(); const values = filterForm.getFieldsValue();
const params = { const params = {
@@ -264,7 +265,6 @@ export default function DeviceAccessPage() {
status: values.status ?? '', status: values.status ?? '',
}; };
// 这里调用你的【产品列表接口】
getProductPage(params).then(res => { getProductPage(params).then(res => {
if (res.code === 200) { if (res.code === 200) {
setProductList(res.rows); setProductList(res.rows);
@@ -273,7 +273,7 @@ export default function DeviceAccessPage() {
}); });
}; };
// ===================== 物模型提交 ===================== // 提交
const handleSubmit = () => { const handleSubmit = () => {
form.validateFields().then(values => { form.validateFields().then(values => {
if (modalType === 'model') { if (modalType === 'model') {
@@ -299,21 +299,24 @@ export default function DeviceAccessPage() {
})) }))
}; };
if (editData) { if (editData) {
// 编辑:调用 updateDeviceModel,自动带 id
updateDeviceModel(submitData).then(res => { updateDeviceModel(submitData).then(res => {
if (res.code === 200) { if (res.code === 200) {
messageApi.success('编辑成功'); messageApi.success('编辑成功');
getModel(); getModel();
setVisible(false); setVisible(false);
} else {
messageApi.error(res.msg);
} }
}); });
} else { } else {
// 新增
addDeviceModel(submitData).then(res => { addDeviceModel(submitData).then(res => {
if (res.code === 200) { if (res.code === 200) {
messageApi.success('新增成功'); messageApi.success('新增成功');
getModel(); getModel();
setVisible(false); setVisible(false);
} else {
messageApi.error(res.msg);
} }
}); });
} }
@@ -324,9 +327,6 @@ export default function DeviceAccessPage() {
const newValues = form.getFieldsValue(); const newValues = form.getFieldsValue();
const { modelId, limitConfig, ...params } = newValues; const { modelId, limitConfig, ...params } = newValues;
// ======================
// 👇 强制给默认值 0 ~ 100
// ======================
const finalLimitConfig = {}; const finalLimitConfig = {};
if (limitConfig) { if (limitConfig) {
Object.keys(limitConfig).forEach(key => { Object.keys(limitConfig).forEach(key => {
@@ -339,26 +339,47 @@ export default function DeviceAccessPage() {
const thingsModels = {}; const thingsModels = {};
if (modelId) { if (modelId) {
thingsModels[modelId] = finalLimitConfig; // 👈 用处理后的 thingsModels[modelId] = finalLimitConfig;
} }
const submitData = { const submitData = {
...params, ...params,
thingsModels: thingsModels, thingsModels: thingsModels,
id: editData?.id,
}; };
addProduct(submitData).then(res => { // ======================
if (res.code == 200) { // 产品:判断新增 / 编辑
messageApi.success('新增产品成功'); // ======================
getProductList() if (editData) {
} // 编辑
}) updateProduct(submitData).then(res => {
} if (res.code === 200) {
messageApi.success('产品编辑成功');
getProductList();
setVisible(false); setVisible(false);
} else {
messageApi.error(res.msg);
}
});
} else {
// 新增
addProduct(submitData).then(res => {
if (res.code === 200) {
messageApi.success('产品新增成功');
getProductList();
setVisible(false);
} else {
messageApi.error(res.msg);
}
});
}
}
}); });
}; };
// 属性编辑 // 属性
const openItemModal = (type: 'props' | 'events' | 'actions', record?: any) => { const openItemModal = (type: 'props' | 'events' | 'actions', record?: any) => {
setItemType(type); setItemType(type);
itemForm.resetFields(); itemForm.resetFields();
@@ -405,6 +426,9 @@ export default function DeviceAccessPage() {
setMappingList(newList); setMappingList(newList);
messageApi.success('删除成功'); messageApi.success('删除成功');
}; };
const handleDeleteProduct = (data) => {
}
const getAlarmProps = () => modelDetail?.props?.filter(item => item.isAlarm) || []; const getAlarmProps = () => modelDetail?.props?.filter(item => item.isAlarm) || [];
@@ -441,60 +465,35 @@ export default function DeviceAccessPage() {
{ {
title: '操作', render: r => ( title: '操作', render: r => (
<Space> <Space>
<Button type="text" icon={<EditOutlined />} onClick={() => openModal('product', r)}>编辑</Button> <Button type="text" style={{ color: '#1677ff' }} icon={<EditOutlined />} onClick={() => openModal('product', r)}>编辑</Button>
<Button type="text" icon={<SwapOutlined />} onClick={() => openModal('product', r)}>字段映射</Button> <Button type="text" icon={<SwapOutlined />} onClick={() => openMappingModal()}>字段映射</Button>
</Space> </Space>
) )
} }
]; ];
// ====================== 已增加属性列 + 指令列 ======================
const modelColumns = [ const modelColumns = [
{ title: '模型名称', dataIndex: 'name' }, { title: '模型名称', dataIndex: 'name' },
{ title: '连接协议', dataIndex: 'connectType' }, { title: '连接协议', dataIndex: 'connectType' },
{ {
title: '属性列表', title: '属性列表', width: 300, render: (record) => {
width: 300,
render: (record) => {
const list = record.supportProperties || []; const list = record.supportProperties || [];
if (list.length === 0) return <span style={{ color: '#999' }}>无属性</span>; if (list.length === 0) return <span style={{ color: '#999' }}>无属性</span>;
return ( return <Space size={[4, 4]} wrap>{list.map(item => <Tag key={item.id} color="blue">{item.propertyName}</Tag>)}</Space>;
<Space size={[4, 4]} wrap>
{list.map(item => (
<Tag key={item.id} color="blue">{item.propertyName}</Tag>
))}
</Space>
);
} }
}, },
{ {
title: '指令列表', title: '指令列表', width: 300, render: (record) => {
width: 300,
render: (record) => {
const list = record.supportActions || []; const list = record.supportActions || [];
if (list.length === 0) return <span style={{ color: '#999' }}>无指令</span>; if (list.length === 0) return <span style={{ color: '#999' }}>无指令</span>;
return ( return <Space size={[4, 4]} wrap>{list.map(item => <Tag key={item.id} color="green">{item.actionName}</Tag>)}</Space>;
<Space size={[4, 4]} wrap>
{list.map(item => (
<Tag key={item.id} color="green">{item.actionName}</Tag>
))}
</Space>
);
} }
}, },
{ {
title: '操作', title: '操作', render: r => (
render: r => (
<Space> <Space>
<Button type="text" icon={<EditOutlined />} onClick={() => openModal('model', r)}>编辑</Button> <Button type="text" icon={<EditOutlined />} onClick={() => openModal('model', r)}>编辑</Button>
<Popconfirm title="确定要删除该物模型吗?" onConfirm={() => handleDeleteModel(r.id)} okText="确定" cancelText="取消">
{/* 增加删除按钮 + 确认框 */}
<Popconfirm
title="确定要删除该物模型吗?"
onConfirm={() => handleDeleteModel(r.id)}
okText="确定"
cancelText="取消"
>
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button> <Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
</Popconfirm> </Popconfirm>
</Space> </Space>
@@ -515,7 +514,6 @@ 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 === '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' && ( {activeTab === 'product' && (
<Card> <Card>
{/* ====================== 产品筛选表单 ====================== */}
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between', alignItems: 'end' }}> <div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between', alignItems: 'end' }}>
<Form <Form
form={filterForm} form={filterForm}
@@ -562,7 +560,8 @@ export default function DeviceAccessPage() {
</Button> </Button>
</div> </div>
{/* ====================== 产品表格 ====================== */} {/* 包一层横向滚动容器 */}
<div style={{ overflowX: 'auto', width: '100%' }}>
<Table <Table
rowKey="id" rowKey="id"
columns={[ columns={[
@@ -581,11 +580,18 @@ export default function DeviceAccessPage() {
render: (s) => <Tag color={s === 1 ? 'green' : 'red'}>{s === 1 ? '启用' : '禁用'}</Tag> render: (s) => <Tag color={s === 1 ? 'green' : 'red'}>{s === 1 ? '启用' : '禁用'}</Tag>
}, },
{ {
title: '操作', title: '操作', width: 180, render: (r) => (
width: 120,
render: (r) => (
<Space> <Space>
<Button type="text" icon={<EditOutlined />} onClick={() => openModal('product', r)}>编辑</Button> <Button type="text" style={{ color: '#1677ff' }} icon={<EditOutlined />} onClick={() => openModal('product', r)}>编辑</Button>
<Button type="text" icon={<SwapOutlined />} onClick={() => openMappingModal()}>字段映射</Button>
<Popconfirm
title="确定要删除该产品吗?"
onConfirm={() => handleDeleteProduct(r.id)}
okText="确定"
cancelText="取消"
>
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
</Popconfirm>
</Space> </Space>
) )
} }
@@ -599,10 +605,12 @@ export default function DeviceAccessPage() {
showTotal: (total) => `共 ${total} 条` showTotal: (total) => `共 ${total} 条`
}} }}
onChange={handleTableChange} onChange={handleTableChange}
scroll={{ x: 'max-content' }}
/> />
</div>
</Card> </Card>
)} )}
{/* 物模型 + 筛选 + 分页 */}
{activeTab === 'model' && ( {activeTab === 'model' && (
<Card> <Card>
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}> <div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
@@ -625,13 +633,7 @@ export default function DeviceAccessPage() {
<Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('model')}>新增物模型</Button> <Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('model')}>新增物模型</Button>
</div> </div>
<Table <Table rowKey="id" columns={modelColumns} dataSource={filteredModelList} pagination={pagination} onChange={handleTableChange} />
rowKey="id"
columns={modelColumns}
dataSource={filteredModelList}
pagination={pagination}
onChange={handleTableChange}
/>
</Card> </Card>
)} )}
@@ -644,7 +646,6 @@ export default function DeviceAccessPage() {
<Form.Item label="设备名称" name="name" rules={[{ required: true }]}><Input /></Form.Item> <Form.Item label="设备名称" name="name" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item label="设备SN" name="sn" rules={[{ required: true }]}><Input /></Form.Item> <Form.Item label="设备SN" name="sn" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item label="关联产品" name="productId" rules={[{ required: true }]}><Select>{productList.map(p => <Option key={p.id} value={p.id}>{p.name}</Option>)}</Select></Form.Item> <Form.Item label="关联产品" name="productId" rules={[{ required: true }]}><Select>{productList.map(p => <Option key={p.id} value={p.id}>{p.name}</Option>)}</Select></Form.Item>
{/*<Form.Item label="关联物模型" name="modelId" rules={[{ required: true }]}><Select onChange={val => setModelDetail(modelDetailList[val] || { props: [] })}>{modelList.map(m => <Option key={m.id} value={m.id}>{m.name}</Option>)}</Select></Form.Item>*/}
</TabPane> </TabPane>
<TabPane tab="协议配置" key="protocol"> <TabPane tab="协议配置" key="protocol">
<Form.Item label="设备协议类型" name="protocolType" rules={[{ required: true }]}> <Form.Item label="设备协议类型" name="protocolType" rules={[{ required: true }]}>
@@ -691,7 +692,6 @@ export default function DeviceAccessPage() {
)} )}
{modalType === 'product' && ( {modalType === 'product' && (
<> <>
<div className="grid grid-cols-2 gap-4"> <div className="grid grid-cols-2 gap-4">
<Form.Item label="产品编号" name="code" rules={[{ required: true }]}> <Form.Item label="产品编号" name="code" rules={[{ required: true }]}>
@@ -733,18 +733,22 @@ export default function DeviceAccessPage() {
</Form.Item> </Form.Item>
</div> </div>
{/* ============ 物模型选择(直接放在基础信息里) ============ */}
<Divider>物模型属性配置</Divider> <Divider>物模型属性配置</Divider>
<Form.Item label="绑定物模型"> <Form.Item label="绑定物模型">
<Select <Select
placeholder="请选择要绑定的物模型" placeholder="请选择要绑定的物模型"
style={{ width: '100%' }} style={{ width: '100%' }}
value={selectedModelId}
onChange={(modelId) => { onChange={(modelId) => {
const model = thinsModelList.find(item => item.id === modelId); const model = thinsModelList.find(item => item.id === modelId);
console.log(model.supportProperties, "物模型")
if (model) { if (model) {
setSelectedModelId(modelId); setSelectedModelId(Number(modelId));
setPropertyList(model.supportProperties || []); // 👈 用 state 立刻刷新 setPropertyList(model.supportProperties || []);
const defaultLimit = {};
model.supportProperties?.forEach(attr => {
defaultLimit[attr.propertyKey] = { min: 0, max: 100 };
});
form.setFieldsValue({ limitConfig: defaultLimit });
} else { } else {
setSelectedModelId(''); setSelectedModelId('');
setPropertyList([]); setPropertyList([]);
@@ -759,45 +763,23 @@ export default function DeviceAccessPage() {
</Select> </Select>
</Form.Item> </Form.Item>
{/* 隐藏字段存储数据 */}
<Form.Item name="modelId" hidden ><Input /></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 }}> <div style={{ marginTop: 12 }}>
{/* 👇 这里从 state 取,同步秒刷新 */}
{propertyList?.map((item) => ( {propertyList?.map((item) => (
<div key={item.id} style={{ <div key={item.id} style={{ padding: '12px 16px', border: '1px solid #eee', borderRadius: 8, marginBottom: 8 }}>
padding: '12px 16px',
border: '1px solid #eee',
borderRadius: 8,
marginBottom: 8
}}>
<div style={{ marginBottom: 8, fontWeight: 500 }}> <div style={{ marginBottom: 8, fontWeight: 500 }}>
{item.propertyName}({item.propertyKey}) {item.propertyName}({item.propertyKey})
</div> </div>
<div className="flex gap-3"> <div className="flex gap-3">
<Form.Item <Form.Item label="最小值" name={['limitConfig', item.propertyKey, 'min']} style={{ flex: 1 }}>
label="最小值" <InputNumber style={{ width: '100%' }} placeholder="最小值" />
name={['limitConfig', item.propertyKey, 'min']}
style={{ flex: 1 }}
>
<InputNumber style={{ width: '100%' }} placeholder="最小值" initialValue={0}
/>
</Form.Item> </Form.Item>
<Form.Item <Form.Item label="最大值" name={['limitConfig', item.propertyKey, 'max']} style={{ flex: 1 }}>
label="最大值" <InputNumber style={{ width: '100%' }} placeholder="最大值" />
name={['limitConfig', item.propertyKey, 'max']}
style={{ flex: 1 }}
>
<InputNumber style={{ width: '100%' }} placeholder="最大值" initialValue={100} />
</Form.Item> </Form.Item>
</div> </div>
</div> </div>
))} ))}
{(!propertyList || propertyList.length === 0) && ( {(!propertyList || propertyList.length === 0) && (
<div style={{ color: '#999', textAlign: 'center', padding: 10 }}> <div style={{ color: '#999', textAlign: 'center', padding: 10 }}>
请选择物模型以显示属性 请选择物模型以显示属性
@@ -805,7 +787,6 @@ export default function DeviceAccessPage() {
)} )}
</div> </div>
</> </>
)} )}
{modalType === 'model' && ( {modalType === 'model' && (
@@ -900,9 +881,7 @@ export default function DeviceAccessPage() {
<Form.Item label="类型" name="type"> <Form.Item label="类型" name="type">
<Select> <Select>
{dataTypeList.map(item => ( {dataTypeList.map(item => (
<Option key={item.code} value={item.code}> <Option key={item.code} value={item.code}>{item.name}</Option>
{item.name}
</Option>
))} ))}
</Select> </Select>
</Form.Item> </Form.Item>
@@ -933,40 +912,16 @@ export default function DeviceAccessPage() {
<Input placeholder="指令名称" value={currentAction?.actionName} onChange={e => setCurrentAction({ ...currentAction, actionName: e.target.value })} style={{ flex: 1 }} /> <Input placeholder="指令名称" value={currentAction?.actionName} onChange={e => setCurrentAction({ ...currentAction, actionName: e.target.value })} style={{ flex: 1 }} />
</div> </div>
<Divider>指令参数</Divider> <Divider>指令参数</Divider>
<div className="flex gap-2 items-center"> <div className="flex gap-2 items-center">
<Input <Input placeholder="参数名" value={paramList[0]?.paramKey || ''} onChange={e => setParamList([{ ...paramList[0], paramKey: e.target.value }])} />
placeholder="参数名" <Select value={paramList[0]?.type || 'int'} style={{ width: 100 }} onChange={v => setParamList([{ ...paramList[0], type: v }])}>
value={paramList[0]?.paramKey || ''}
onChange={e => setParamList([{ ...paramList[0], paramKey: e.target.value }])}
/>
<Select
value={paramList[0]?.type || 'int'}
style={{ width: 100 }}
onChange={v => setParamList([{ ...paramList[0], type: v }])}
>
{/* 👇 接口数据渲染 */}
{dataTypeList.map(item => ( {dataTypeList.map(item => (
<Option key={item.code} value={item.code}> <Option key={item.code} value={item.code}>{item.code}</Option>
{item.code}
</Option>
))} ))}
</Select> </Select>
<Input <Input placeholder="描述" value={paramList[0]?.desc || ''} onChange={e => setParamList([{ ...paramList[0], desc: e.target.value }])} />
placeholder="描述" <Input placeholder="默认值" value={paramList[0]?.defaultValue || ''} onChange={e => setParamList([{ ...paramList[0], defaultValue: e.target.value }])} />
value={paramList[0]?.desc || ''} <Input placeholder="枚举(,分隔)" value={(paramList[0]?.enum || []).join(',')} onChange={e => setParamList([{ ...paramList[0], enum: e.target.value.split(',').map(s => s.trim()) }])} />
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> </div>
</Modal> </Modal>