fxi view
This commit is contained in:
parent
a87978e89b
commit
b1f128f4c4
@ -31,7 +31,7 @@ class NetworkState {
|
|||||||
var schema: String
|
var schema: String
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Device: Equatable, Hashable {
|
struct Device {
|
||||||
var id: Int
|
var id: Int
|
||||||
var status: Int
|
var status: Int
|
||||||
var name: String
|
var name: String
|
||||||
@ -54,11 +54,14 @@ class NetworkState {
|
|||||||
var name: String
|
var name: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 状态管理
|
||||||
var connectState: ConnectState = .connected
|
var connectState: ConnectState = .connected
|
||||||
var model: NetworkModel = .init(name: "123@abc.com的网络")
|
var model: NetworkModel = .init(name: "123@abc.com的网络")
|
||||||
|
|
||||||
var showModel: ShowMode = .device
|
var showModel: ShowMode = .device
|
||||||
|
|
||||||
|
// 当前选中的设备
|
||||||
|
var selectedDevice: Device?
|
||||||
|
|
||||||
var resources: [Resource] = [
|
var resources: [Resource] = [
|
||||||
.init(id: 1, status: 1, name: "OA", schema: "http://100.92.108.1:8080"),
|
.init(id: 1, status: 1, name: "OA", schema: "http://100.92.108.1:8080"),
|
||||||
.init(id: 2, status: 0, name: "数据资源", schema: "http://100.92.108.1:8080"),
|
.init(id: 2, status: 0, name: "数据资源", schema: "http://100.92.108.1:8080"),
|
||||||
@ -73,9 +76,9 @@ class NetworkState {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
self.devices = [
|
self.devices = [
|
||||||
.init(id: 1, status: 1, name: "阿里云1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
.init(id: 1, status: 1, name: "test1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
||||||
.init(id: 2, status: 1, name: "阿里云1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
.init(id: 2, status: 1, name: "test2", ipv4: "192.168.1.2", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
||||||
.init(id: 3, status: 1, name: "阿里云1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
.init(id: 3, status: 1, name: "test3", ipv4: "192.168.1.3", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
||||||
.init(id: 4, status: 1, name: "阿里云1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
.init(id: 4, status: 1, name: "阿里云1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
||||||
.init(id: 5, status: 1, name: "阿里云1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
.init(id: 5, status: 1, name: "阿里云1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
||||||
.init(id: 15, status: 1, name: "阿里云1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
.init(id: 15, status: 1, name: "阿里云1", ipv4: "192.168.1.1", ipv6: "fa9d.fa9d.fa9d.fa9d", system: "MacOS 12", resources: self.resources),
|
||||||
@ -86,4 +89,12 @@ class NetworkState {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func changeSelectedDevice(deviceId: Int?) {
|
||||||
|
if let deviceId {
|
||||||
|
if let device = self.devices.first(where: { $0.id == deviceId}) {
|
||||||
|
self.selectedDevice = device
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -108,9 +108,9 @@ struct NetworkConnctedView: View {
|
|||||||
Group {
|
Group {
|
||||||
switch state.showModel {
|
switch state.showModel {
|
||||||
case .resource:
|
case .resource:
|
||||||
NetworkResourceGroupView(resources: self.state.resources)
|
NetworkResourceGroupView(state: self.state)
|
||||||
case .device:
|
case .device:
|
||||||
NetworkDeviceGroupView(devices: self.state.devices, selection: self.state.devices[0])
|
NetworkDeviceGroupView(state: self.state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,54 +119,58 @@ struct NetworkConnctedView: View {
|
|||||||
|
|
||||||
// 显示资源信息
|
// 显示资源信息
|
||||||
struct NetworkResourceGroupView: View {
|
struct NetworkResourceGroupView: View {
|
||||||
var resources: [NetworkState.Resource]
|
@Bindable var state: NetworkState
|
||||||
|
|
||||||
struct NetworkResourceView: View {
|
|
||||||
var resource: NetworkState.Resource
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack {
|
|
||||||
HStack {
|
|
||||||
Text(resource.status == 1 ? "yes" : "no")
|
|
||||||
|
|
||||||
Text(resource.name)
|
|
||||||
.font(.system(size: 14, weight: .regular))
|
|
||||||
}
|
|
||||||
|
|
||||||
Text(resource.schema)
|
|
||||||
.font(.system(size: 14, weight: .regular))
|
|
||||||
.padding(.leading, 30)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 3), spacing: 8) {
|
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 3), spacing: 8) {
|
||||||
ForEach(resources, id: \.id) { resource in
|
ForEach(self.state.resources, id: \.id) { resource in
|
||||||
NetworkResourceView(resource: resource)
|
NetworkResourceView(resource: resource)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct NetworkResourceView: View {
|
||||||
|
var resource: NetworkState.Resource
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
HStack {
|
||||||
|
Text(resource.status == 1 ? "yes" : "no")
|
||||||
|
|
||||||
|
Text(resource.name)
|
||||||
|
.font(.system(size: 14, weight: .regular))
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(resource.schema)
|
||||||
|
.font(.system(size: 14, weight: .regular))
|
||||||
|
.padding(.leading, 30)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 显示设备信息
|
// 显示设备信息
|
||||||
struct NetworkDeviceGroupView: View {
|
struct NetworkDeviceGroupView: View {
|
||||||
var devices: [NetworkState.Device]
|
@Bindable var state: NetworkState
|
||||||
@State private var selection: NetworkState.Device
|
@State private var selectedId: Int?
|
||||||
|
|
||||||
init(devices: [NetworkState.Device], selection: NetworkState.Device) {
|
|
||||||
self.devices = devices
|
|
||||||
self.selection = selection
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationSplitView {
|
NavigationSplitView {
|
||||||
List(devices, id: \.id, selection: $selection) { device in
|
List(self.state.devices, id: \.id, selection: $selectedId) { device in
|
||||||
NetworkDeviceHeadView(device: device)
|
NetworkDeviceHeadView(device: device)
|
||||||
}
|
}
|
||||||
|
.listStyle(.sidebar)
|
||||||
|
.onChange(of: selectedId) {
|
||||||
|
self.state.changeSelectedDevice(deviceId: selectedId)
|
||||||
|
}
|
||||||
|
.onAppear {
|
||||||
|
if selectedId == nil {
|
||||||
|
selectedId = self.state.devices.first?.id
|
||||||
|
}
|
||||||
|
}
|
||||||
} detail: {
|
} detail: {
|
||||||
NetworkDeviceDetailView(device: $selection)
|
NetworkDeviceDetailView(device: $state.selectedDevice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,50 +196,59 @@ struct NetworkDeviceHeadView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct NetworkDeviceDetailView: View {
|
struct NetworkDeviceDetailView: View {
|
||||||
@Binding var device: NetworkState.Device
|
@Binding var device: NetworkState.Device?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
Group {
|
||||||
HStack {
|
if let device {
|
||||||
Text("连接状态")
|
List {
|
||||||
|
Section {
|
||||||
Text("\(device.status)")
|
HStack {
|
||||||
}
|
Text("连接状态")
|
||||||
|
|
||||||
HStack {
|
Text("\(device.status)")
|
||||||
Text("虚拟IPv4")
|
|
||||||
|
Spacer()
|
||||||
Text("\(device.ipv4)")
|
}
|
||||||
}
|
|
||||||
|
HStack {
|
||||||
HStack {
|
Text("虚拟IPv4")
|
||||||
Text("虚拟IPv6")
|
|
||||||
|
Text("\(device.ipv4)")
|
||||||
Text("\(device.ipv6)")
|
Spacer()
|
||||||
}
|
}
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Text("操作系统")
|
Text("虚拟IPv6")
|
||||||
|
|
||||||
Text("\(device.system)")
|
Text("\(device.ipv6)")
|
||||||
}
|
Spacer()
|
||||||
|
}
|
||||||
VStack {
|
|
||||||
Text("服务列表")
|
HStack {
|
||||||
|
Text("操作系统")
|
||||||
List(device.resources, id: \.id) { resource in
|
|
||||||
HStack {
|
Text("\(device.system)")
|
||||||
Text("\(resource.name)")
|
Spacer()
|
||||||
Text("\(resource.schema)")
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Section("服务列表") {
|
||||||
|
ForEach(device.resources, id: \.id) { resource in
|
||||||
|
HStack {
|
||||||
|
Text("\(resource.name)")
|
||||||
|
Text("\(resource.schema)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
EmptyView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
NetworkView()
|
NetworkView()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ struct punchnetApp: App {
|
|||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup(id: "mainWindow") {
|
WindowGroup(id: "mainWindow") {
|
||||||
//IndexView(noticeServer: self.noticeServer)
|
//IndexView(noticeServer: self.noticeServer)
|
||||||
LoginView()
|
NetworkView()
|
||||||
.onAppear {
|
.onAppear {
|
||||||
// 获取主屏幕的尺寸
|
// 获取主屏幕的尺寸
|
||||||
guard let screenFrame = NSScreen.main?.frame else { return }
|
guard let screenFrame = NSScreen.main?.frame else { return }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user