fix device
This commit is contained in:
parent
82c02739b8
commit
5ab94163a6
@ -12,6 +12,9 @@ import Observation
|
|||||||
class AppContext {
|
class AppContext {
|
||||||
var noticePort: Int
|
var noticePort: Int
|
||||||
|
|
||||||
|
// 调用 "/connect" 之后的网络信息
|
||||||
|
var networkContext: NetworkContext?
|
||||||
|
|
||||||
init(noticePort: Int) {
|
init(noticePort: Int) {
|
||||||
self.noticePort = noticePort
|
self.noticePort = noticePort
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,6 +53,7 @@ struct Node: Codable {
|
|||||||
struct NetworkContext: Codable {
|
struct NetworkContext: Codable {
|
||||||
let ip: String
|
let ip: String
|
||||||
let maskLen: UInt8
|
let maskLen: UInt8
|
||||||
|
// 主机名称
|
||||||
let hostname: String
|
let hostname: String
|
||||||
let identityId: UInt32
|
let identityId: UInt32
|
||||||
let resourceList: [Resource]
|
let resourceList: [Resource]
|
||||||
@ -110,13 +111,15 @@ class NetworkModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect(networkSession: UserContext.NetworkSession) async throws {
|
func connect(networkSession: UserContext.NetworkSession) async throws -> NetworkContext {
|
||||||
let params: [String: Any] = [
|
let params: [String: Any] = [
|
||||||
"client_id": SystemConfig.getClientId(),
|
"client_id": SystemConfig.getClientId(),
|
||||||
"access_token": networkSession.accessToken
|
"access_token": networkSession.accessToken
|
||||||
]
|
]
|
||||||
|
|
||||||
self.networkContext = try await SDLAPIClient.doPost(path: "/connect", params: params, as: NetworkContext.self)
|
self.networkContext = try await SDLAPIClient.doPost(path: "/connect", params: params, as: NetworkContext.self)
|
||||||
|
|
||||||
|
return self.networkContext
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -190,9 +190,11 @@ extension NetworkView {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try await networkModel.connect(networkSession: session)
|
let context = try await networkModel.connect(networkSession: session)
|
||||||
|
|
||||||
|
// 登陆后需要保存到app的上线文
|
||||||
|
self.appContext.networkContext = context
|
||||||
|
|
||||||
let context = networkModel.networkContext
|
|
||||||
if let options = SystemConfig.getOptions(
|
if let options = SystemConfig.getOptions(
|
||||||
networkId: UInt32(session.networkId),
|
networkId: UInt32(session.networkId),
|
||||||
networkDomain: session.networkDomain,
|
networkDomain: session.networkDomain,
|
||||||
|
|||||||
@ -8,36 +8,115 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct SettingsDeviceView: View {
|
struct SettingsDeviceView: View {
|
||||||
|
@Environment(AppContext.self) var appContext: AppContext
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading) {
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
Text("设备")
|
VStack(alignment: .leading, spacing: 28) {
|
||||||
|
|
||||||
HStack {
|
// MARK: - 设备概览标题
|
||||||
Text("设备名称")
|
HStack(spacing: 16) {
|
||||||
Text("史蒂夫的air")
|
Image(systemName: "laptopcomputer")
|
||||||
|
.font(.system(size: 36))
|
||||||
|
.foregroundStyle(.blue.gradient)
|
||||||
|
.frame(width: 60, height: 60)
|
||||||
|
.background(Color.blue.opacity(0.1))
|
||||||
|
.cornerRadius(12)
|
||||||
|
|
||||||
Button {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text(self.appContext.networkContext?.hostname ?? "为定义")
|
||||||
|
.font(.title3.bold())
|
||||||
|
|
||||||
} label: {
|
Text(SystemConfig.systemInfo)
|
||||||
Text("修改")
|
.font(.subheadline)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
.padding(.horizontal, 4)
|
||||||
|
|
||||||
HStack {
|
// MARK: - 详细参数卡片
|
||||||
Text("虚拟IPv4")
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
Text("192.168.1.1")
|
// 设备名称行
|
||||||
}
|
DevicePropertyRow(title: "设备名称", value: self.appContext.networkContext?.hostname ?? "为定义") {
|
||||||
|
Button {
|
||||||
|
// 修改逻辑
|
||||||
|
} label: {
|
||||||
|
Text("修改")
|
||||||
|
.font(.subheadline.bold())
|
||||||
|
.padding(.horizontal, 12)
|
||||||
|
.padding(.vertical, 4)
|
||||||
|
.background(Capsule().fill(Color.blue.opacity(0.1)))
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
|
||||||
HStack {
|
Divider().padding(.leading, 16)
|
||||||
Text("虚拟IPv6")
|
|
||||||
Text("ab:ef:1")
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
// IPv4 行
|
||||||
|
DevicePropertyRow(title: "虚拟 IPv4", value: self.appContext.networkContext?.ip ?? "0.0.0.0") {
|
||||||
|
Image(systemName: "info.circle")
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
|
||||||
|
Divider().padding(.leading, 16)
|
||||||
|
|
||||||
|
// // IPv6 行
|
||||||
|
// DevicePropertyRow(title: "虚拟 IPv6", value: "fe80::ab:ef:1") {
|
||||||
|
// Text("已加密")
|
||||||
|
// .font(.caption2.bold())
|
||||||
|
// .padding(.horizontal, 6)
|
||||||
|
// .padding(.vertical, 2)
|
||||||
|
// .background(Color.green.opacity(0.1))
|
||||||
|
// .foregroundColor(.green)
|
||||||
|
// .cornerRadius(4)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
.background(Color.primary.opacity(0.03))
|
||||||
|
.cornerRadius(12)
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(Color.primary.opacity(0.05), lineWidth: 1))
|
||||||
|
|
||||||
|
// MARK: - 底部说明
|
||||||
|
Text("此设备在虚拟网络中是唯一的,修改名称不会影响连接标识。")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.padding(.horizontal, 4)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(32)
|
||||||
|
.frame(maxWidth: 600, alignment: .leading)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
// MARK: - 子组件:设备属性行
|
||||||
SettingsDeviceView()
|
struct DevicePropertyRow<Content: View>: View {
|
||||||
|
let title: String
|
||||||
|
let value: String
|
||||||
|
let trailingContent: () -> Content
|
||||||
|
|
||||||
|
init(title: String, value: String, @ViewBuilder trailingContent: @escaping () -> Content) {
|
||||||
|
self.title = title
|
||||||
|
self.value = value
|
||||||
|
self.trailingContent = trailingContent
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack {
|
||||||
|
Text(title)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.frame(width: 100, alignment: .leading)
|
||||||
|
|
||||||
|
Text(value)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
.font(.system(.body, design: .monospaced)) // 使用等宽字体显示 IP 更专业
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
trailingContent()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 16)
|
||||||
|
.padding(.vertical, 14)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,8 +50,7 @@ struct punchnetApp: App {
|
|||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup(id: "main") {
|
WindowGroup(id: "main") {
|
||||||
// RootView()
|
RootView()
|
||||||
SettingsView()
|
|
||||||
.navigationTitle("")
|
.navigationTitle("")
|
||||||
.environment(self.appContext)
|
.environment(self.appContext)
|
||||||
.environment(self.userContext)
|
.environment(self.userContext)
|
||||||
@ -72,6 +71,7 @@ struct punchnetApp: App {
|
|||||||
Window("设置", id: "settings") {
|
Window("设置", id: "settings") {
|
||||||
SettingsView()
|
SettingsView()
|
||||||
.environment(self.userContext)
|
.environment(self.userContext)
|
||||||
|
.environment(self.appContext)
|
||||||
}
|
}
|
||||||
.defaultSize(width: 800, height: 500)
|
.defaultSize(width: 800, height: 500)
|
||||||
.defaultPosition(.center)
|
.defaultPosition(.center)
|
||||||
@ -79,6 +79,7 @@ struct punchnetApp: App {
|
|||||||
Window("重置密码", id: "resetPassword") {
|
Window("重置密码", id: "resetPassword") {
|
||||||
ResetPasswordRootView()
|
ResetPasswordRootView()
|
||||||
.environment(self.userContext)
|
.environment(self.userContext)
|
||||||
|
.environment(self.appContext)
|
||||||
}
|
}
|
||||||
.defaultSize(width: 800, height: 500)
|
.defaultSize(width: 800, height: 500)
|
||||||
.defaultPosition(.center)
|
.defaultPosition(.center)
|
||||||
@ -86,6 +87,7 @@ struct punchnetApp: App {
|
|||||||
Window("注册", id: "register") {
|
Window("注册", id: "register") {
|
||||||
ResetPasswordRootView()
|
ResetPasswordRootView()
|
||||||
.environment(self.userContext)
|
.environment(self.userContext)
|
||||||
|
.environment(self.appContext)
|
||||||
}
|
}
|
||||||
.defaultSize(width: 800, height: 500)
|
.defaultSize(width: 800, height: 500)
|
||||||
.defaultPosition(.center)
|
.defaultPosition(.center)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user