简化逻辑
This commit is contained in:
parent
77d7e95eae
commit
97194e501e
@ -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 {
|
||||
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 {
|
||||
|
||||
@ -218,7 +218,7 @@ struct NetworkDeviceGroupView: View {
|
||||
.listStyle(.sidebar)
|
||||
.navigationSplitViewColumnWidth(min: 200, ideal: 220)
|
||||
} detail: {
|
||||
if let selectedNode = appContext.networkContext.nodeList.first(where: { $0.id == selectedId }) {
|
||||
if let selectedNode = appContext.networkContext.getNode(id: selectedId) {
|
||||
NetworkNodeDetailView(node: selectedNode)
|
||||
} else {
|
||||
ContentUnavailableView("选择成员设备", systemImage: "macbook.and.iphone", description: Text("查看详细网络信息和服务"))
|
||||
@ -226,7 +226,7 @@ struct NetworkDeviceGroupView: View {
|
||||
}
|
||||
.onAppear {
|
||||
if selectedId == nil {
|
||||
selectedId = appContext.networkContext.nodeList.first?.id
|
||||
selectedId = appContext.networkContext.firstNodeId()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user