feat: 修复BUG
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
CloudServerOutlined,
|
||||
FolderOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import axios from 'axios';
|
||||
import api from '../api';
|
||||
import PortCreateModal from './PortCreateModal';
|
||||
import NetworkCardCreateModal from './NetworkCardCreateModal';
|
||||
import { designTokens } from '../config/theme';
|
||||
@@ -42,13 +42,13 @@ function NetworkCardPanel({ deviceId, deviceName, onRefresh, refreshTrigger }) {
|
||||
try {
|
||||
setLoading(true);
|
||||
const [cardsResponse, networkCardsResponse] = await Promise.all([
|
||||
axios.get(`/api/network-cards/device/${deviceId}/with-ports`),
|
||||
axios.get(`/api/network-cards/device/${deviceId}`),
|
||||
api.get(`/network-cards/device/${deviceId}/with-ports`),
|
||||
api.get(`/network-cards/device/${deviceId}`),
|
||||
]);
|
||||
|
||||
const cardsData = cardsResponse.data || [];
|
||||
const cardsData = cardsResponse.data || cardsResponse || [];
|
||||
setCards(cardsData);
|
||||
setNetworkCards(networkCardsResponse.data || []);
|
||||
setNetworkCards(networkCardsResponse.data || networkCardsResponse || []);
|
||||
|
||||
const initialExpanded = cardsData
|
||||
.filter(card => card.ports && card.ports.length > 0)
|
||||
@@ -70,7 +70,7 @@ function NetworkCardPanel({ deviceId, deviceName, onRefresh, refreshTrigger }) {
|
||||
const handleDeleteCard = useCallback(
|
||||
async card => {
|
||||
try {
|
||||
await axios.delete(`/api/network-cards/${card.nicId}`);
|
||||
await api.delete(`/network-cards/${card.nicId}`);
|
||||
import('antd').then(({ message }) => message.success('网卡删除成功'));
|
||||
fetchData();
|
||||
onRefresh?.();
|
||||
@@ -86,7 +86,7 @@ function NetworkCardPanel({ deviceId, deviceName, onRefresh, refreshTrigger }) {
|
||||
const handleDeletePort = useCallback(
|
||||
async port => {
|
||||
try {
|
||||
await axios.delete(`/api/device-ports/${port.portId}`);
|
||||
await api.delete(`/device-ports/${port.portId}`);
|
||||
import('antd').then(({ message }) => message.success('端口删除成功'));
|
||||
fetchData();
|
||||
onRefresh?.();
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
SettingOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import PortPanel from './PortPanel';
|
||||
import axios from 'axios';
|
||||
import api from '../api';
|
||||
import { designTokens } from '../config/theme';
|
||||
import CloseButton from './CloseButton';
|
||||
|
||||
@@ -47,8 +47,8 @@ const ServerBackplanePanel = ({
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await axios.get(`/api/network-cards/device/${deviceId}/with-ports`);
|
||||
const cardsData = response.data || [];
|
||||
const response = await api.get(`/network-cards/device/${deviceId}/with-ports`);
|
||||
const cardsData = response.data || response || [];
|
||||
setCards(cardsData);
|
||||
} catch (error) {
|
||||
console.error('获取网卡数据失败:', error);
|
||||
|
||||
@@ -120,10 +120,14 @@ const VirtualDeviceList = ({
|
||||
const toggleDeviceExpand = deviceId => {
|
||||
setExpandedDevices(prev => ({
|
||||
...prev,
|
||||
[deviceId]: !prev[deviceId],
|
||||
[deviceId]: prev[deviceId] === true ? false : true,
|
||||
}));
|
||||
};
|
||||
|
||||
const isDeviceExpanded = deviceId => {
|
||||
return expandedDevices[deviceId] === true;
|
||||
};
|
||||
|
||||
const visibleDevices = devices.slice(0, visibleCount);
|
||||
const hasMore = visibleCount < devices.length;
|
||||
|
||||
@@ -172,7 +176,7 @@ const VirtualDeviceList = ({
|
||||
{visibleDevices.map(device => {
|
||||
const deviceId = device.deviceId;
|
||||
const data = groupedPorts[deviceId] || { device, ports: [] };
|
||||
const isExpanded = expandedDevices[deviceId];
|
||||
const isExpanded = isDeviceExpanded(deviceId);
|
||||
const portCount = data.ports?.length || 0;
|
||||
const occupiedCount = data.ports?.filter(p => p.status === 'occupied').length || 0;
|
||||
|
||||
@@ -300,15 +304,21 @@ const VirtualDeviceList = ({
|
||||
type="text"
|
||||
size="small"
|
||||
icon={isExpanded ? <UpOutlined /> : <DownOutlined />}
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
toggleDeviceExpand(deviceId);
|
||||
}}
|
||||
style={{ color: '#64748b' }}
|
||||
/>
|
||||
>
|
||||
{isExpanded ? '收起' : '展开'}
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
{/* 面板内容 - 可折叠 */}
|
||||
{isExpanded && (
|
||||
<div style={{ padding: '16px' }}>
|
||||
{device.type === 'switch' ? (
|
||||
{device.type?.toLowerCase()?.includes('switch') ? (
|
||||
// 交换机使用普通端口面板
|
||||
<PortPanel
|
||||
ports={data.ports || []}
|
||||
|
||||
Reference in New Issue
Block a user