机柜可视化页面,优化了机柜机房下拉框
This commit is contained in:
@@ -89,6 +89,7 @@ class ErrorBoundary extends React.Component {
|
|||||||
function RackVisualization() {
|
function RackVisualization() {
|
||||||
const [racks, setRacks] = useState([]);
|
const [racks, setRacks] = useState([]);
|
||||||
const [selectedRack, setSelectedRack] = useState(null);
|
const [selectedRack, setSelectedRack] = useState(null);
|
||||||
|
const [selectedRoom, setSelectedRoom] = useState(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [devices, setDevices] = useState([]);
|
const [devices, setDevices] = useState([]);
|
||||||
const [loadingDevices, setLoadingDevices] = useState(false);
|
const [loadingDevices, setLoadingDevices] = useState(false);
|
||||||
@@ -115,10 +116,20 @@ function RackVisualization() {
|
|||||||
|
|
||||||
setRacks(validRacks);
|
setRacks(validRacks);
|
||||||
if (validRacks.length > 0) {
|
if (validRacks.length > 0) {
|
||||||
setSelectedRack(validRacks[0]);
|
// 自动选择第一个机柜
|
||||||
fetchDevices(validRacks[0].rackId);
|
const firstRack = validRacks[0];
|
||||||
|
setSelectedRack(firstRack);
|
||||||
|
|
||||||
|
// 设置对应的机房
|
||||||
|
if (firstRack?.Room) {
|
||||||
|
const roomKey = firstRack.Room.roomId || firstRack.Room.id || firstRack.Room.name;
|
||||||
|
setSelectedRoom(roomKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchDevices(firstRack.rackId);
|
||||||
} else {
|
} else {
|
||||||
setSelectedRack(null);
|
setSelectedRack(null);
|
||||||
|
setSelectedRoom(null);
|
||||||
setDevices([]);
|
setDevices([]);
|
||||||
message.warning('未找到有效的机柜数据');
|
message.warning('未找到有效的机柜数据');
|
||||||
}
|
}
|
||||||
@@ -511,6 +522,52 @@ function RackVisualization() {
|
|||||||
return marks;
|
return marks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 获取机房列表
|
||||||
|
const getRooms = () => {
|
||||||
|
const roomMap = new Map();
|
||||||
|
racks.forEach(rack => {
|
||||||
|
if (rack?.Room) {
|
||||||
|
const roomKey = rack.Room.roomId || rack.Room.id || rack.Room.name;
|
||||||
|
if (!roomMap.has(roomKey)) {
|
||||||
|
roomMap.set(roomKey, {
|
||||||
|
...rack.Room,
|
||||||
|
key: roomKey
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Array.from(roomMap.values());
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取指定机房下的机柜
|
||||||
|
const getRacksByRoom = (roomId) => {
|
||||||
|
return racks.filter(rack => {
|
||||||
|
const rackRoomId = rack?.Room?.roomId || rack?.Room?.id;
|
||||||
|
return rackRoomId === roomId;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 选择机房
|
||||||
|
const handleRoomChange = (roomId) => {
|
||||||
|
console.log('选择机房:', roomId);
|
||||||
|
setSelectedRoom(roomId);
|
||||||
|
|
||||||
|
// 重置机柜选择
|
||||||
|
setSelectedRack(null);
|
||||||
|
setDevices([]);
|
||||||
|
|
||||||
|
// 如果选择了机房,获取该机房下的机柜
|
||||||
|
if (roomId) {
|
||||||
|
const roomRacks = getRacksByRoom(roomId);
|
||||||
|
if (roomRacks.length > 0) {
|
||||||
|
// 自动选择第一个机柜
|
||||||
|
const firstRack = roomRacks[0];
|
||||||
|
setSelectedRack(firstRack);
|
||||||
|
fetchDevices(firstRack.rackId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 选择机柜
|
// 选择机柜
|
||||||
const handleRackChange = (rackId) => {
|
const handleRackChange = (rackId) => {
|
||||||
const rack = racks.find(r => r.rackId === rackId);
|
const rack = racks.find(r => r.rackId === rackId);
|
||||||
@@ -552,17 +609,33 @@ function RackVisualization() {
|
|||||||
title="机柜可视化"
|
title="机柜可视化"
|
||||||
extra={
|
extra={
|
||||||
<Space>
|
<Space>
|
||||||
|
<Select
|
||||||
|
placeholder="选择机房"
|
||||||
|
style={{ width: 180 }}
|
||||||
|
value={selectedRoom}
|
||||||
|
onChange={handleRoomChange}
|
||||||
|
loading={loading}
|
||||||
|
disabled={loading}
|
||||||
|
allowClear
|
||||||
|
>
|
||||||
|
{getRooms().map(room => (
|
||||||
|
<Option key={room.key} value={room.key}>
|
||||||
|
{room.name || '未知机房'} ({room.roomId || room.id || '无ID'})
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
<Select
|
<Select
|
||||||
placeholder="选择机柜"
|
placeholder="选择机柜"
|
||||||
style={{ width: 200 }}
|
style={{ width: 200 }}
|
||||||
value={selectedRack?.rackId}
|
value={selectedRack?.rackId}
|
||||||
onChange={handleRackChange}
|
onChange={handleRackChange}
|
||||||
loading={loading}
|
loading={loading || loadingDevices}
|
||||||
disabled={loading}
|
disabled={!selectedRoom || loading}
|
||||||
|
allowClear
|
||||||
>
|
>
|
||||||
{racks.map(rack => (
|
{selectedRoom && getRacksByRoom(selectedRoom).map(rack => (
|
||||||
<Option key={rack?.rackId || `rack-${Math.random()}`} value={rack?.rackId}>
|
<Option key={rack?.rackId || `rack-${Math.random()}`} value={rack?.rackId}>
|
||||||
{rack?.Room?.name || '未知机房'} - {rack?.name || '未知机柜'} ({rack?.rackId || '无ID'}) - {rack?.height || 0}U
|
{rack?.name || '未知机柜'} ({rack?.rackId || '无ID'}) - {rack?.height || 0}U
|
||||||
</Option>
|
</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
@@ -577,11 +650,13 @@ function RackVisualization() {
|
|||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Space style={{ marginBottom: 16 }}>
|
<div style={{ marginBottom: 16 }}>
|
||||||
|
<Space wrap>
|
||||||
<Button icon={<ZoomInOutlined />} onClick={handleZoomIn}>放大</Button>
|
<Button icon={<ZoomInOutlined />} onClick={handleZoomIn}>放大</Button>
|
||||||
<Button icon={<ZoomOutOutlined />} onClick={handleZoomOut}>缩小</Button>
|
<Button icon={<ZoomOutOutlined />} onClick={handleZoomOut}>缩小</Button>
|
||||||
<Button icon={<RotateRightOutlined />} onClick={handleResetView}>重置视角</Button>
|
<Button icon={<RotateRightOutlined />} onClick={handleResetView}>重置视角</Button>
|
||||||
</Space>
|
</Space>
|
||||||
|
</div>
|
||||||
|
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user