|
| 1 | +import SwiftUI |
| 2 | +import MagicCore |
| 3 | + |
| 4 | +/** |
| 5 | + * 应用列表空视图 |
| 6 | + * |
| 7 | + * 当应用列表为空时显示的空状态视图。 |
| 8 | + * 根据显示类型(全部/允许/拒绝)显示相应的提示信息。 |
| 9 | + */ |
| 10 | +struct AppListEmptyView: View { |
| 11 | + /// 显示类型 |
| 12 | + let displayType: DisplayType |
| 13 | + |
| 14 | + /// 构建空视图 |
| 15 | + var body: some View { |
| 16 | + VStack(spacing: 16) { |
| 17 | + Image(systemName: "app.badge") |
| 18 | + .font(.system(size: 48)) |
| 19 | + .foregroundColor(.secondary) |
| 20 | + |
| 21 | + Text(title) |
| 22 | + .font(.headline) |
| 23 | + .foregroundColor(.primary) |
| 24 | + |
| 25 | + if let description = description { |
| 26 | + Text(description) |
| 27 | + .font(.subheadline) |
| 28 | + .foregroundColor(.secondary) |
| 29 | + .multilineTextAlignment(.center) |
| 30 | + .padding(.horizontal, 40) |
| 31 | + } |
| 32 | + } |
| 33 | + .frame(maxWidth: .infinity, maxHeight: .infinity) |
| 34 | + } |
| 35 | + |
| 36 | + /// 空状态标题 |
| 37 | + private var title: String { |
| 38 | + switch displayType { |
| 39 | + case .All: |
| 40 | + return "暂无应用" |
| 41 | + case .Allowed: |
| 42 | + return "暂无网络活动" |
| 43 | + case .Rejected: |
| 44 | + return "暂无被拒绝的应用" |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + /// 空状态描述 |
| 49 | + private var description: String? { |
| 50 | + switch displayType { |
| 51 | + case .All: |
| 52 | + return "当前没有应用产生网络活动" |
| 53 | + case .Allowed: |
| 54 | + return "当前没有网络活动" |
| 55 | + case .Rejected: |
| 56 | + return "当前没有拒绝访问网络的应用" |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +// MARK: - Preview |
| 62 | +#Preview("App") { |
| 63 | + ContentView() |
| 64 | + .inRootView() |
| 65 | + .frame(width: 600, height: 600) |
| 66 | +} |
| 67 | + |
| 68 | +#Preview("AppListEmptyView - All") { |
| 69 | + AppListEmptyView(displayType: .All) |
| 70 | + .frame(width: 600, height: 400) |
| 71 | +} |
| 72 | + |
| 73 | +#Preview("AppListEmptyView - Allowed") { |
| 74 | + AppListEmptyView(displayType: .Allowed) |
| 75 | + .frame(width: 600, height: 400) |
| 76 | +} |
| 77 | + |
| 78 | +#Preview("AppListEmptyView - Rejected") { |
| 79 | + AppListEmptyView(displayType: .Rejected) |
| 80 | + .frame(width: 600, height: 400) |
| 81 | +} |
| 82 | + |
0 commit comments