This commit is contained in:
mmc
2026-05-07 17:09:19 +08:00
parent 9cf26ce2bd
commit 5ef889e435
5 changed files with 439 additions and 112 deletions

View File

@@ -5,7 +5,7 @@ import {
} from 'antd';
import {
PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined,
AppstoreOutlined, SwapOutlined, VideoCameraOutlined, AlertOutlined
AppstoreOutlined, SwapOutlined, VideoCameraOutlined
} from '@ant-design/icons';
const { Option } = Select;
@@ -44,7 +44,7 @@ const modelDetailList: Record<number, {
{ id: 2, code: 'record_status', name: '录像状态', type: 'string', rw: 'r', isAlarm: false },
],
events: [{ id: 1, code: 'alarm_perimeter', name: '周界入侵告警' }],
actions: [{ id: 1, code: 'take_snapshot', name: '截图' }]
actions: [{ actionId: 'take_snapshot', actionName: '截图', params: {} }]
},
11: {
props: [
@@ -101,6 +101,11 @@ export default function DeviceAccessPage() {
const [itemType, setItemType] = useState<'props' | 'events' | 'actions'>('props');
const [itemForm] = Form.useForm();
// 指令 + 参数 新增状态
const [actionModal, setActionModal] = useState(false);
const [currentAction, setCurrentAction] = useState<any>(null);
const [paramList, setParamList] = useState<any[]>([]);
// 字段映射(实时增删改查,实时保存)
const [mappingList, setMappingList] = useState(mappingInitList);
const [mappingModal, setMappingModal] = useState(false);
@@ -128,15 +133,35 @@ export default function DeviceAccessPage() {
setVisible(true);
};
// 产品提交
// 提交
const handleSubmit = () => {
form.validateFields().then(values => {
message.success('产品信息保存成功');
if (modalType === 'model') {
const submitData = {
name: values.name,
connectType: values.connectType,
version: "1.0",
deviceType: values.deviceType,
supportProperties: modelDetail.props.map(p => ({
propertyKey: p.code,
propertyName: p.name,
dataType: p.type,
unit: p.unit || "",
required: true,
defaultValue: null
})),
supportActions: modelDetail.actions
};
console.log("最终提交物模型:", submitData);
message.success("物模型保存成功");
} else {
message.success("保存成功");
}
setVisible(false);
});
};
// 物模型
// 属性/事件 编辑
const openItemModal = (type: 'props' | 'events' | 'actions', record?: any) => {
setItemType(type);
itemForm.resetFields();
@@ -163,18 +188,14 @@ export default function DeviceAccessPage() {
else mappingForm.setFieldsValue({ productId: editData?.id });
setMappingModal(true);
};
// 新增/编辑 → 立即保存
const saveMapping = () => {
mappingForm.validateFields().then(val => {
let newList = [...mappingList];
if (val.id) {
// 编辑
const index = newList.findIndex(x => x.id === val.id);
if (index >= 0) newList[index] = val;
message.success('字段映射修改成功');
} else {
// 新增
newList.push({ ...val, id: Date.now() });
message.success('字段映射新增成功');
}
@@ -183,8 +204,6 @@ export default function DeviceAccessPage() {
setMappingModal(false);
});
};
// 删除 → 立即保存
const deleteMapping = (id: number) => {
const newList = mappingList.filter(x => x.id !== id);
setMappingList(newList);
@@ -201,9 +220,9 @@ export default function DeviceAccessPage() {
{ title: 'SN', dataIndex: 'sn' },
{ title: '所属产品', dataIndex: 'productName' },
{ title: '物模型', dataIndex: 'modelName' },
{ title: '协议', dataIndex: 'protocolType', render: t => <Tag>{t.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 => <Space><Button type="text" icon={<EditOutlined />} onClick={() => openModal('device', r)}>编辑</Button></Space> }
{ title: '操作', render: r => <Button type="text" icon={<EditOutlined />} onClick={() => openModal('device', r)}>编辑</Button> }
];
const productColumns = [
@@ -239,8 +258,8 @@ export default function DeviceAccessPage() {
</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' && <Card><Space><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('product')}>新增产品</Button></Space><Table rowKey="id" columns={productColumns} dataSource={productList} /></Card>}
{activeTab === 'model' && <Card><Space><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('model')}>新增物模型</Button></Space><Table rowKey="id" columns={modelColumns} dataSource={modelList} /></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>}
<Modal open={visible} width={850} onCancel={() => setVisible(false)} onOk={handleSubmit} destroyOnClose
title={modalType === 'device' ? '设备配置' : modalType === 'product' ? '产品配置' : '物模型配置'}>
@@ -281,7 +300,6 @@ export default function DeviceAccessPage() {
<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>
<Table size="small" dataSource={mappingList.filter(x => x.productId === editData?.id)} pagination={false}
@@ -305,9 +323,24 @@ export default function DeviceAccessPage() {
{modalType === 'model' && (
<>
<Form.Item label="模型名称" name="name" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item label="模型编码" name="code" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item label="模型描述" name="desc"><Input.TextArea rows={2} /></Form.Item>
<div style={{ display: "flex", gap: 16, marginBottom: 16 }}>
<div style={{ 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>
<div style={{ 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>
<Table size="small" dataSource={modelDetail.props} pagination={false} columns={[
@@ -315,10 +348,41 @@ export default function DeviceAccessPage() {
{ title: '告警', render: r => <Switch checked={r.isAlarm} disabled size="small" /> },
{ 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></Space> }
]} />
<Divider>事件列表</Divider>
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openItemModal('events')} className="mb-2">新增事件</Button>
<Table size="small" dataSource={modelDetail.events} pagination={false} columns={[{ title: '编码', dataIndex: 'code' }, { title: '名称', dataIndex: 'name' }, { title: '操作', render: r => <Button type="text" icon={<EditOutlined />} onClick={() => openItemModal('events', r)}>编辑</Button> }]} />
<Divider>指令列表</Divider>
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => {
setCurrentAction({ actionId: '', actionName: '', params: {} });
setParamList([]);
setActionModal(true);
}} 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 => (
<Space>
<Button type="text" onClick={() => {
setCurrentAction(r);
const arr = [];
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)
})
}}>
<Button type="text" danger>删除</Button>
</Popconfirm>
</Space>
)
}
]} />
</>
)}
</Form>
@@ -333,7 +397,92 @@ export default function DeviceAccessPage() {
</Form>
</Modal>
{/* 字段映射弹窗:操作即保存 */}
{/* 指令 + 参数 弹窗 */}
<Modal
title="配置指令"
open={actionModal}
onCancel={() => setActionModal(false)}
onOk={() => {
const params = paramList.reduce((obj, item) => {
obj[item.paramKey] = {
type: item.type,
description: item.desc || '',
default: item.defaultValue
};
return obj;
}, {});
const action = {
actionId: currentAction.actionId,
actionName: currentAction.actionName,
params
};
const exists = modelDetail.actions.some(x => x.actionId === currentAction.actionId);
let newActions = [];
if (exists) {
newActions = modelDetail.actions.map(x => x.actionId === currentAction.actionId ? action : x);
} else {
newActions = [...modelDetail.actions, action];
}
setModelDetail({ ...modelDetail, actions: newActions });
setActionModal(false);
message.success('保存成功');
}}
width={700}
>
<div style={{ marginBottom: 16 }}>
<Input
placeholder="指令编码 如 restart"
value={currentAction?.actionId}
onChange={(e) => setCurrentAction({ ...currentAction, actionId: e.target.value })}
style={{ width: '48%', marginRight: '4%' }}
/>
<Input
placeholder="指令名称 如 重启设备"
value={currentAction?.actionName}
onChange={(e) => setCurrentAction({ ...currentAction, actionName: e.target.value })}
style={{ width: '48%' }}
/>
</div>
<Divider>指令参数</Divider>
{paramList.map((item, index) => (
<div key={index} style={{ display: 'flex', gap: 8, marginBottom: 10, alignItems: 'center' }}>
<Input placeholder="参数名" value={item.paramKey} onChange={(e) => {
const arr = [...paramList];
arr[index].paramKey = e.target.value;
setParamList(arr);
}} />
<Select value={item.type} style={{ width: 100 }} onChange={(v) => {
const arr = [...paramList];
arr[index].type = v;
setParamList(arr);
}}>
<Select.Option value="int">int</Select.Option>
<Select.Option value="string">string</Select.Option>
</Select>
<Input placeholder="描述" value={item.desc} onChange={(e) => {
const arr = [...paramList];
arr[index].desc = e.target.value;
setParamList(arr);
}} />
<Input placeholder="默认值" value={item.defaultValue} onChange={(e) => {
const arr = [...paramList];
arr[index].defaultValue = e.target.value;
setParamList(arr);
}} />
<Button danger size="small" onClick={() => setParamList(paramList.filter((_, i) => i !== index))}>删</Button>
</div>
))}
<Button size="small" type="dashed" block onClick={() => {
setParamList([...paramList, { paramKey: '', type: 'int', desc: '', defaultValue: '' }])
}}>+ 添加参数</Button>
</Modal>
<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 />

View File

@@ -411,43 +411,46 @@ export default function UserRolePage() {
onChange: (selectedRowKeys) => setSelectedUserIds(selectedRowKeys)
}}
columns={[
{ title: '用户账号', dataIndex: 'userName' },
{ title: '用户昵称', dataIndex: 'nickName' },
{ title: '手机号', dataIndex: 'phonenumber' },
{ title: '邮箱', dataIndex: 'email' },
// 所属机构
{ title: '用户账号', dataIndex: 'userName', ellipsis: true },
{ title: '用户昵称', dataIndex: 'nickName', ellipsis: true },
{ title: '手机号', dataIndex: 'phonenumber', ellipsis: true },
{ title: '邮箱', dataIndex: 'email', ellipsis: true },
{
title: '所属机构',
render: (_, r) => {
const org = orgList.find(o => o.id == r.orgId);
return org ? org.orgName : '—';
}
},
ellipsis: true
},
// 所属场站(纯缓存匹配,无接口)
{
title: '所属场站',
render: (_, r) => {
if (!r.siteId) return '—';
const site = allSiteList.find(s => s.id == r.siteId);
return site ? site.siteName : '—';
}
},
ellipsis: true
},
{
title: '角色',
render: (_, r) => (r.roles || []).map(i => (
<Tag color="blue" key={i.roleId}>{i?.roleKey}</Tag>
))
)),
ellipsis: true
},
{
title: '状态',
title: '状态', dataIndex: 'status', width: 80,
render: (_, s) => s.status === '0'
? <Tag color="green">正常</Tag>
: <Tag color="red">停用</Tag>
},
{
title: '操作',
width: 220,
fixed: 'right',
render: (_, r) => (
<Space>
<Space wrap>
<Button type="text" icon={<EditOutlined style={{ color: '#1890ff' }} />} onClick={() => handleEditUser(r)}>编辑</Button>
<Popconfirm onConfirm={() => handleDeleteUser(r.userId)} title="确定删除该用户吗?">
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
@@ -468,6 +471,8 @@ export default function UserRolePage() {
onChange={(p) => setUserPagination({ ...userPagination, pageNum: p.current!, pageSize: p.pageSize! })}
bordered
size="middle"
// 👇 下面这行是修复不自适应的关键
scroll={{ x: 'max-content' }}
/>
</TabPane>