// // NetworkDisconnctedView.swift // punchnet // // Created by 安礼成 on 2026/1/16. // import SwiftUI struct NetworkDisconnctedView: View { @Bindable var state: NetworkState var body: some View { ZStack { Color.clear VStack { Button { Task { try await startVpn() } } label: { Text("连接") .font(.system(size: 14, weight: .regular)) .padding([.top, .bottom], 8) .padding([.leading, .trailing], 30) .foregroundColor(.white) } .background(Color(red: 74/255, green: 207/255, blue: 154/255)) .cornerRadius(5) .frame(width: 120, height: 35) Button { Task { try await VPNManager.shared.disableVpn() } } label: { Text("关闭") .font(.system(size: 14, weight: .regular)) .padding([.top, .bottom], 8) .padding([.leading, .trailing], 30) .foregroundColor(.white) } .background(Color(red: 74/255, green: 207/255, blue: 154/255)) .cornerRadius(5) .frame(width: 120, height: 35) } } } // 执行登陆操作 private func startVpn() async throws { let clientId = SystemConfig.getClientId() let options = SystemConfig.getOptions(networkId: 8, networkDomain: "punchnet.com", ip: "10.211.179.1", maskLen: 24, accessToken: "accessToken1234", hostname: "mysql", noticePort: 123456) // token存在则优先使用token try await VPNManager.shared.enableVpn(options: options!) } } //#Preview { // NetworkDisconnctedView() //}