简化逻辑

This commit is contained in:
anlicheng 2026-03-24 14:46:37 +08:00
parent 77d7e95eae
commit 97194e501e
2 changed files with 22 additions and 15 deletions

View File

@ -59,19 +59,6 @@ extension SDLAPIClient {
} }
} }
enum CodingKeys: String, CodingKey {
case ip
case maskLen = "mask_len"
case hostname
case identityId = "identity_id"
case resourceList = "resource_list"
case nodeList = "node_list"
}
static func `default`() -> Self {
return .init(ip: "", maskLen: 24, hostname: "", identityId: 0, resourceList: [], nodeList: [])
}
// //
struct NodeDetail: Codable { struct NodeDetail: Codable {
let id: Int let id: Int
@ -91,6 +78,26 @@ extension SDLAPIClient {
} }
} }
enum CodingKeys: String, CodingKey {
case ip
case maskLen = "mask_len"
case hostname
case identityId = "identity_id"
case resourceList = "resource_list"
case nodeList = "node_list"
}
static func `default`() -> Self {
return .init(ip: "", maskLen: 24, hostname: "", identityId: 0, resourceList: [], nodeList: [])
}
func getNode(id: Int?) -> Node? {
return nodeList.first(where: { $0.id == id })
}
func firstNodeId() -> Int? {
return nodeList.first?.id
}
} }
static func connectNetwork(accesToken: String) async throws -> NetworkContext { static func connectNetwork(accesToken: String) async throws -> NetworkContext {

View File

@ -218,7 +218,7 @@ struct NetworkDeviceGroupView: View {
.listStyle(.sidebar) .listStyle(.sidebar)
.navigationSplitViewColumnWidth(min: 200, ideal: 220) .navigationSplitViewColumnWidth(min: 200, ideal: 220)
} detail: { } detail: {
if let selectedNode = appContext.networkContext.nodeList.first(where: { $0.id == selectedId }) { if let selectedNode = appContext.networkContext.getNode(id: selectedId) {
NetworkNodeDetailView(node: selectedNode) NetworkNodeDetailView(node: selectedNode)
} else { } else {
ContentUnavailableView("选择成员设备", systemImage: "macbook.and.iphone", description: Text("查看详细网络信息和服务")) ContentUnavailableView("选择成员设备", systemImage: "macbook.and.iphone", description: Text("查看详细网络信息和服务"))
@ -226,7 +226,7 @@ struct NetworkDeviceGroupView: View {
} }
.onAppear { .onAppear {
if selectedId == nil { if selectedId == nil {
selectedId = appContext.networkContext.nodeList.first?.id selectedId = appContext.networkContext.firstNodeId()
} }
} }
} }