Publish reviewed history-free open-source snapshot (2026-10-12)

This commit is contained in:
Zonghengjia Open Source
2026-10-11 23:23:20 +00:00
commit 901f27baf5
301 changed files with 32378 additions and 0 deletions
+294
View File
@@ -0,0 +1,294 @@
import SwiftUI
struct ContentView: View {
@EnvironmentObject private var state: AppState
var body: some View {
ZStack {
UCVLColors.background.ignoresSafeArea()
if let profile = state.profile {
DashboardView(profile: profile)
} else {
LoginView()
}
}
.tint(UCVLColors.royal)
.alert("提示", isPresented: Binding(
get: { !state.errorMessage.isEmpty },
set: { if !$0 { state.errorMessage = "" } }
)) {
Button("确定", role: .cancel) { state.errorMessage = "" }
} message: {
Text(state.errorMessage)
}
}
}
private struct BrandHeader: View {
var compact = false
var body: some View {
VStack(spacing: compact ? 8 : 16) {
Image("UCVLLogo")
.resizable()
.scaledToFit()
.frame(width: compact ? 84 : 132, height: compact ? 84 : 132)
.accessibilityLabel("优创未来 Logo")
Text("优创⁺纵横家")
.font(compact ? .title2.bold() : .largeTitle.bold())
.foregroundStyle(.white)
Text("优创未来安全网络")
.font(.subheadline)
.foregroundStyle(UCVLColors.sky)
}
}
}
private struct LoginView: View {
@EnvironmentObject private var state: AppState
@State private var identifier = SecureStore.lastLogin
@State private var password = ""
var body: some View {
ScrollView {
VStack(spacing: 28) {
BrandHeader()
.padding(.top, 34)
VStack(alignment: .leading, spacing: 18) {
Text("公司统一账号登录")
.font(.title2.bold())
.foregroundStyle(UCVLColors.navy)
TextField("用户名或邮箱", text: $identifier)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
.keyboardType(.emailAddress)
.textContentType(.username)
.ucvlField()
SecureField("密码", text: $password)
.textContentType(.password)
.ucvlField()
.onSubmit { Task { await state.login(identifier: identifier, password: password) } }
Button {
Task {
await state.login(identifier: identifier, password: password)
if state.profile != nil { password = "" }
}
} label: {
HStack {
if state.busy { ProgressView().tint(.white) }
Text(state.busy ? "正在登录…" : "安全登录").fontWeight(.semibold)
}
.frame(maxWidth: .infinity)
.padding(.vertical, 14)
}
.buttonStyle(.borderedProminent)
.disabled(state.busy)
Text("账号停用后,设备授权与线路将自动失效。")
.font(.footnote)
.foregroundStyle(.secondary)
HStack {
Text("还没有账号?")
.font(.footnote)
.foregroundStyle(.secondary)
Link("注册新用户", destination: URL(string: "https://vpn.toplc.cn/register/")!)
.font(.footnote.weight(.semibold))
}
}
.padding(24)
.background(.white, in: RoundedRectangle(cornerRadius: 24, style: .continuous))
.shadow(color: .black.opacity(0.14), radius: 24, y: 12)
.frame(maxWidth: 540)
Text("vpn.toplc.cn · © 2026 UCVL")
.font(.footnote)
.foregroundStyle(UCVLColors.sky)
.padding(.bottom, 30)
}
.padding(.horizontal, 20)
}
}
}
private struct DashboardView: View {
@EnvironmentObject private var state: AppState
let profile: ClientProfile
var body: some View {
ScrollView {
VStack(spacing: 18) {
HStack(spacing: 16) {
BrandHeader(compact: true)
Spacer()
VStack(alignment: .trailing, spacing: 4) {
Text("你好,\(profile.displayName.isEmpty ? profile.username : profile.displayName)")
.font(.headline)
.foregroundStyle(.white)
Text("\(profile.email) · \(profile.identityType == "employee" ? "内部员工" : "外部联系人")")
.font(.caption)
.foregroundStyle(UCVLColors.sky)
}
}
.padding(.vertical, 8)
StatusCard()
UCVLCard(title: "工作节点与代理模式", systemImage: "point.3.connected.trianglepath.dotted") {
VStack(spacing: 14) {
HStack {
Text("当前工作节点")
Spacer()
Text(state.currentNode?.displayName ?? "由 vpn-ai 自动选择")
.foregroundStyle(state.currentNode == nil ? .secondary : UCVLColors.royal)
.multilineTextAlignment(.trailing)
}
Divider()
HStack {
Text("代理模式")
Spacer()
Picker("代理模式", selection: $state.selectedRouteID) {
ForEach(profile.routeModes) { route in Text(route.name).tag(route.id) }
}
.pickerStyle(.menu)
.disabled(state.vpn.isConnected || state.busy)
}
Button {
Task { await state.toggleConnection() }
} label: {
HStack {
if state.busy { ProgressView().tint(.white) }
Image(systemName: state.vpn.isConnected ? "stop.fill" : "bolt.shield.fill")
Text(state.vpn.isConnected ? "断开连接" : "连接")
}
.frame(maxWidth: .infinity)
.padding(.vertical, 12)
}
.buttonStyle(.borderedProminent)
.tint(state.vpn.isConnected ? UCVLColors.navy : UCVLColors.royal)
.disabled(state.busy || profile.nodes.isEmpty)
}
}
UsageCard(subscription: profile.subscription)
HStack(spacing: 12) {
Button { Task { await state.refresh() } } label: {
Label("刷新", systemImage: "arrow.clockwise")
.frame(maxWidth: .infinity)
}
.buttonStyle(.bordered)
.disabled(state.busy)
Button(role: .destructive) { Task { await state.logout() } } label: {
Label("退出账号", systemImage: "rectangle.portrait.and.arrow.right")
.frame(maxWidth: .infinity)
}
.buttonStyle(.bordered)
.disabled(state.busy)
}
}
.frame(maxWidth: 760)
.padding(.horizontal, 18)
.padding(.vertical, 18)
}
}
}
private struct StatusCard: View {
@EnvironmentObject private var state: AppState
var body: some View {
UCVLCard(title: "连接状态", systemImage: "network.badge.shield.half.filled") {
HStack(spacing: 14) {
Circle()
.fill(state.statusIsActive ? Color.green : Color.gray)
.frame(width: 13, height: 13)
VStack(alignment: .leading, spacing: 4) {
Text(state.statusTitle).font(.title3.bold())
Text(state.message.isEmpty ? "点击连接,vpn-ai 将自动选择并验证工作节点" : state.message)
.font(.subheadline)
.foregroundStyle(.secondary)
}
Spacer()
}
}
}
}
private struct UsageCard: View {
let subscription: SubscriptionProfile
private var fraction: Double {
guard subscription.trafficLimitBytes > 0 else { return 0 }
return min(1, max(0, Double(subscription.usedBytes) / Double(subscription.trafficLimitBytes)))
}
var body: some View {
UCVLCard(title: "本期流量", systemImage: "chart.bar.fill") {
VStack(alignment: .leading, spacing: 12) {
HStack {
Text(format(subscription.usedBytes))
Spacer()
Text(subscription.trafficLimitBytes > 0 ? format(subscription.trafficLimitBytes) : "不限流量")
.foregroundStyle(UCVLColors.royal)
}
ProgressView(value: fraction)
.tint(UCVLColors.royal)
Text("套餐:\(subscription.plan) · 设备上限 \(subscription.deviceLimit) 台\(expiryText)")
.font(.footnote)
.foregroundStyle(.secondary)
}
}
}
private var expiryText: String {
guard let expiresAt = subscription.expiresAt else { return " · 长期有效" }
return " · 到期 \(String(expiresAt.prefix(10)))"
}
private func format(_ value: Int64) -> String {
ByteCountFormatter.string(fromByteCount: value, countStyle: .file)
}
}
private struct UCVLCard<Content: View>: View {
let title: String
let systemImage: String
let content: Content
init(title: String, systemImage: String, @ViewBuilder content: () -> Content) {
self.title = title
self.systemImage = systemImage
self.content = content()
}
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Label(title, systemImage: systemImage)
.font(.headline)
.foregroundStyle(UCVLColors.navy)
content
}
.padding(20)
.background(.white, in: RoundedRectangle(cornerRadius: 22, style: .continuous))
.shadow(color: .black.opacity(0.08), radius: 14, y: 7)
}
}
private enum UCVLColors {
static let navy = Color(red: 0.02, green: 0.10, blue: 0.26)
static let royal = Color(red: 0.02, green: 0.39, blue: 0.86)
static let sky = Color(red: 0.17, green: 0.73, blue: 0.98)
static let background = LinearGradient(
colors: [navy, Color(red: 0.03, green: 0.25, blue: 0.48)],
startPoint: .topLeading,
endPoint: .bottomTrailing
)
}
private extension View {
func ucvlField() -> some View {
self
.padding(.horizontal, 14)
.frame(height: 52)
.background(Color.gray.opacity(0.08), in: RoundedRectangle(cornerRadius: 13))
.overlay(RoundedRectangle(cornerRadius: 13).stroke(Color.gray.opacity(0.2)))
}
}