xx
This commit is contained in:
@@ -96,6 +96,27 @@ export function deleteModel(id) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//新增设备
|
||||||
|
|
||||||
|
export function addIotDevice(data) {
|
||||||
|
return request({
|
||||||
|
url: `/system/iotDevice/add`,
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//编辑设备
|
||||||
|
|
||||||
|
export function updateIotDevice(data) {
|
||||||
|
return request({
|
||||||
|
url: `/system/iotDevice/update`,
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
AppstoreOutlined, SwapOutlined, VideoCameraOutlined
|
AppstoreOutlined, SwapOutlined, VideoCameraOutlined
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { addDeviceModel, addProduct, deleteModel, deleteProduct, getConnectTypes, getDataTypesApi, getDeviceModelList, getProductPage, updateDeviceModel, updateProduct } from '../../api/deviceAccess.ts';
|
import { addDeviceModel, addProduct, deleteModel, deleteProduct, getConnectTypes, getDataTypesApi, getDeviceModelList, getProductPage, updateDeviceModel, updateProduct } from '../../api/deviceAccess.ts';
|
||||||
|
import { Z_FIXED } from 'zlib';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
const { TabPane } = Tabs;
|
const { TabPane } = Tabs;
|
||||||
@@ -197,6 +198,7 @@ export default function DeviceAccessPage() {
|
|||||||
await fetchProtocolList();
|
await fetchProtocolList();
|
||||||
await fetchDataTypeList();
|
await fetchDataTypeList();
|
||||||
await fetchAllModelList();
|
await fetchAllModelList();
|
||||||
|
await fetchProductPageList();
|
||||||
|
|
||||||
if (record) {
|
if (record) {
|
||||||
form.setFieldsValue(record);
|
form.setFieldsValue(record);
|
||||||
@@ -238,7 +240,7 @@ export default function DeviceAccessPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (type === 'device') { setDeviceProtocol('onvif'); setModelDetail({ props: [] }); }
|
if (type === 'device') { setDeviceProtocol(''); setModelDetail({ props: [] }); }
|
||||||
else if (type === 'product') { setProductProtocol(''); setPropertyList([]); form.setFieldsValue({ status: 1 }); }
|
else if (type === 'product') { setProductProtocol(''); setPropertyList([]); form.setFieldsValue({ status: 1 }); }
|
||||||
else setModelDetail({ props: [], events: [], actions: [] });
|
else setModelDetail({ props: [], events: [], actions: [] });
|
||||||
}
|
}
|
||||||
@@ -404,7 +406,7 @@ export default function DeviceAccessPage() {
|
|||||||
{ title: '物模型', dataIndex: 'modelName' },
|
{ title: '物模型', dataIndex: 'modelName' },
|
||||||
{ title: '协议', render: t => <Tag>{t.protocolType.toUpperCase()}</Tag> },
|
{ title: '协议', render: t => <Tag>{t.protocolType.toUpperCase()}</Tag> },
|
||||||
{ title: '状态', render: r => <Tag color={r.onlineStatus ? 'green' : 'red'}>{r.onlineStatus ? '在线' : '离线'}</Tag> },
|
{ title: '状态', render: r => <Tag color={r.onlineStatus ? 'green' : 'red'}>{r.onlineStatus ? '在线' : '离线'}</Tag> },
|
||||||
{ title: '操作', render: r => <Button type="text" icon={<EditOutlined />} onClick={() => openModal('device', r)}>编辑</Button> }
|
{ title: '操作', fixed: "right", render: r => <Button type="text" icon={<EditOutlined />} onClick={() => openModal('device', r)}>编辑</Button> }
|
||||||
];
|
];
|
||||||
|
|
||||||
const modelColumns = [
|
const modelColumns = [
|
||||||
@@ -425,7 +427,7 @@ export default function DeviceAccessPage() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作', render: r => (
|
title: '操作', fixed: "right", 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="取消">
|
||||||
@@ -446,7 +448,14 @@ export default function DeviceAccessPage() {
|
|||||||
</Tabs>
|
</Tabs>
|
||||||
</Card>
|
</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 === 'device' && <Card><Space className="mb-3"><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('device')}>新增设备</Button></Space>
|
||||||
|
<div style={{ overflowX: 'auto', width: '100%' }}>
|
||||||
|
<Table rowKey="id" columns={deviceColumns} dataSource={deviceList} scroll={{ x: 'max-content' }} />
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</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', }}>
|
||||||
@@ -513,7 +522,7 @@ 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: '操作', width: 180, render: (r) => (
|
title: '操作', fixed: "right", width: 180, render: (r) => (
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="text" style={{ color: '#1677ff' }} 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>
|
<Button type="text" icon={<SwapOutlined />} onClick={() => openMappingModal()}>字段映射</Button>
|
||||||
@@ -565,8 +574,10 @@ export default function DeviceAccessPage() {
|
|||||||
</Form>
|
</Form>
|
||||||
<Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('model')}>新增物模型</Button>
|
<Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('model')}>新增物模型</Button>
|
||||||
</div>
|
</div>
|
||||||
|
<div style={{ overflowX: 'auto', width: '100%' }}>
|
||||||
|
<Table rowKey="id" columns={modelColumns} dataSource={filteredModelList} pagination={pagination} onChange={handleTableChange} scroll={{ x: 'max-content' }} />
|
||||||
|
|
||||||
<Table rowKey="id" columns={modelColumns} dataSource={filteredModelList} pagination={pagination} onChange={handleTableChange} />
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -596,7 +607,29 @@ export default function DeviceAccessPage() {
|
|||||||
name="productId"
|
name="productId"
|
||||||
rules={[{ required: true, message: '请选择关联产品' }]}
|
rules={[{ required: true, message: '请选择关联产品' }]}
|
||||||
>
|
>
|
||||||
<Select placeholder="请选择关联产品">
|
<Select
|
||||||
|
placeholder="请选择关联产品"
|
||||||
|
onChange={(val) => {
|
||||||
|
// 核心逻辑:选择产品后自动加载协议并回填
|
||||||
|
const targetProduct = productList.find(p => p.id === val);
|
||||||
|
if (targetProduct) {
|
||||||
|
const protocol = targetProduct.protocolCode || '';
|
||||||
|
// 自动设置协议并回填表单
|
||||||
|
setDeviceProtocol(protocol.toUpperCase());
|
||||||
|
form.setFieldsValue({ protocolType: protocol });
|
||||||
|
|
||||||
|
// 自动回填产品里的协议配置
|
||||||
|
const configFields = ['ip', 'port', 'username', 'password', 'rtspUrl', 'mqttServer', 'mqttPort', 'clientId', 'mqttUsername', 'mqttPassword'];
|
||||||
|
const configValues = {};
|
||||||
|
configFields.forEach(field => {
|
||||||
|
if (targetProduct[field] !== undefined) {
|
||||||
|
configValues[field] = targetProduct[field];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
form.setFieldsValue(configValues);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
{productList.map(p => (
|
{productList.map(p => (
|
||||||
<Option key={p.id} value={p.id}>
|
<Option key={p.id} value={p.id}>
|
||||||
{p.name}
|
{p.name}
|
||||||
@@ -605,23 +638,7 @@ export default function DeviceAccessPage() {
|
|||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
label="设备协议类型"
|
|
||||||
name="protocolType"
|
|
||||||
rules={[{ required: true, message: '请选择协议类型' }]}
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
value={deviceProtocol}
|
|
||||||
onChange={setDeviceProtocol}
|
|
||||||
placeholder="请选择协议类型"
|
|
||||||
>
|
|
||||||
{protocolList.map(p => (
|
|
||||||
<Option key={p.code} value={p.code}>
|
|
||||||
{p.name}
|
|
||||||
</Option>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user