diff --git a/src/app/dashboard/components/gatewayConfigs.tsx b/src/app/dashboard/components/gatewayConfigs.tsx index 661245f..d82752c 100644 --- a/src/app/dashboard/components/gatewayConfigs.tsx +++ b/src/app/dashboard/components/gatewayConfigs.tsx @@ -15,8 +15,7 @@ function GatewayConfigContent() { const [loading, setLoading] = useState(false) const [infoData, setInfoData] = useState([]) const [totalCount, setTotalCount] = useState(0) - const [matrixData, setMatrixData] = useState<{ city: string, devices: { [macaddr: string]: GatewayConfig[] } }[]>([]) - const [cities, setCities] = useState([]) + const [matrixData, setMatrixData] = useState<{ inner_ip: string, devices: { [macaddr: string]: GatewayConfig[] } }[]>([]) const [macAddresses, setMacAddresses] = useState([]) const [currentTotal, setCurrentTotal] = useState(0) // 缓存处理先保存初始MAC地址列表 @@ -161,51 +160,51 @@ function GatewayConfigContent() { }) } - const cityMinPortMap: { [city: string]: number } = {} - Object.values(macConfigMap).forEach((configs) => { - configs.forEach((config) => { - const city = config.city - if (!city) return // 跳过无城市的配置 - const currentPortLastOctet = getLastOctet(config.inner_ip) - if (!cityMinPortMap[city] || currentPortLastOctet < cityMinPortMap[city]) { - cityMinPortMap[city] = currentPortLastOctet - } - }) - }) - - // 获取所有唯一的城市 - const allCities = Array.from( + const allPortLines = Array.from( new Set( Object.values(macConfigMap) .flat() - .map(item => item.city) + .map(item => item.inner_ip)// 获取端口和线路 .filter(Boolean), ), - ).sort((cityA, cityB) => { - const portA = cityMinPortMap[cityA!] || 0 - const portB = cityMinPortMap[cityB!] || 0 + ) + const portLineConfigMap: { [key: string]: GatewayConfig } = {} + Object.values(macConfigMap).forEach((configs) => { + configs.forEach((config) => { + const key = config.inner_ip + if (!portLineConfigMap[key]) { + portLineConfigMap[key] = config + } + }) + }) + // 按端口号排序 + const sortedPortLines = allPortLines.sort((a, b) => { + const portA = getLastOctet(a.split('|')[0]) + const portB = getLastOctet(b.split('|')[0]) return portA - portB - }) as string[] + }) // 构建矩阵数据 - const matrix = allCities.map((city) => { + const matrix = sortedPortLines.map((portLine) => { + const [inner_ip] = portLine.split('|') + const config = portLineConfigMap[portLine] + const row = { - city, + inner_ip: inner_ip || '', devices: {} as { [macaddr: string]: GatewayConfig[] }, } // 为每个MAC地址填充该城市的配置数据 macList.forEach((mac) => { - const configsForCity = macConfigMap[mac] - .filter(item => item.city === city) + const configsForPortLine = macConfigMap[mac] + .filter(item => item.inner_ip === inner_ip) .sort(sortByInnerIp) - row.devices[mac] = configsForCity + row.devices[mac] = configsForPortLine }) return row }) setMatrixData(matrix) - setCities(allCities) setMacAddresses(macList) setCurrentTotal(matrix.length) @@ -228,6 +227,7 @@ function GatewayConfigContent() { try { // 获取网关基本信息 const infoResult = await getGatewayInfo() + if (!infoResult.success) { throw new Error(infoResult.error || '查询网关信息失败') } @@ -429,13 +429,13 @@ function GatewayConfigContent() { - - 城市 + + 端口 {macAddresses.map((macaddr, index) => ( {macaddr} @@ -444,18 +444,19 @@ function GatewayConfigContent() { {matrixData.map((row, rowIndex) => ( - - - {row.city} + + +
+ {row.inner_ip || 'N/A'} +
{macAddresses.map((macaddr, colIndex) => { const configs = row.devices[macaddr] || [] - if (configs.length === 0) { return (
-
@@ -465,7 +466,8 @@ function GatewayConfigContent() { return (
{configs.map((item, itemIndex) => { @@ -479,13 +481,12 @@ function GatewayConfigContent() { } return ( -
+
{item.public || 'N/A'}
- {item.user || 'N/A'} - {item.inner_ip || 'N/A'} + {item.city || 'N/A'}