7f6e35908c
- 移除自定义 UI 字体,界面统一系统原生:删 BrandFonts.swift(Orbit/Maple woff2 运行期 CTFontManager 注册 + UIKit 外观代理)+ AppDelegate 的 register 调用 + CDropApp 全局 .environment(\.font, .oBody);9 视图 .font(.o语义) → .font(.语义) 系统语义(日志 LogView 消息行本就 .caption.monospaced() 原生等宽);删 Sources/Fonts/(Orbit/Maple woff2 ~20MB)。仅留品牌字标 Fredoka(logo Wordmark),Justfile ios-fonts 改 Fredoka-only、.gitignore 收窄、新增 Shared/Fonts/README.md - iPad 适配:RootView TabView 加 .tabViewStyle(.sidebarAdaptable)(iPad 常规宽度侧边栏 / iPhone 底部标签栏)+ ConversationView 消息线程 maxWidth 680 居中;project.yml 补方向键 UISupportedInterfaceOrientations(iPhone 竖 + 横)/ ~ipad(全 4 向),消除 iPad 多任务方向构建告警 - 登录页内容约束 maxWidth 420 居中,避免 iPad 宽屏主登录按钮 / 二维码区横向拉满(iPhone 不受影响) - 文档:ios/PLAN.md §11.2 改系统原生字体 + 新增 §13 iPad;ios/PARITY.md 字体分叉条目回退 + 导航条目加 iPad + 2026-07-07 漂移行 - 已装 iPhone 15 Pro C + iPad Pro 13" M4 双端、用户确认
131 lines
4.7 KiB
Swift
131 lines
4.7 KiB
Swift
import CoreImage.CIFilterBuiltins
|
||
import SwiftUI
|
||
import UIKit
|
||
|
||
// 登录界面:主登录=应用内 Broker 账号登录(ASWebAuthenticationSession,直接输账号、无需另一台
|
||
// 设备);扫码登录降级为可展开的备选(需另一台已登录设备扫码批准)。两条流程经 AuthManager。
|
||
struct LoginView: View
|
||
{
|
||
@Environment(AuthManager.self) private var auth
|
||
@State private var showQR = false
|
||
|
||
var body: some View
|
||
{
|
||
VStack(spacing: 20)
|
||
{
|
||
Spacer()
|
||
// 品牌(登录页):吉祥物 + 字标(Fredoka),取代原纯文字标题——首屏即见完整品牌。
|
||
VStack(spacing: 14)
|
||
{
|
||
BrandMark(size: 124)
|
||
Wordmark(size: 30)
|
||
}
|
||
.padding(.bottom, 8)
|
||
|
||
// 主登录:应用内 broker 账号登录。
|
||
Button { Task { await auth.startBrokerLogin() } }
|
||
label:
|
||
{
|
||
Label(t("ios.login.broker"), systemImage: "person.crop.circle")
|
||
.frame(maxWidth: .infinity)
|
||
}
|
||
.buttonStyle(.glassProminent)
|
||
.padding(.horizontal, 40)
|
||
|
||
if !auth.statusText.isEmpty
|
||
{
|
||
Text(auth.statusText)
|
||
.font(.callout)
|
||
.foregroundStyle(auth.qrExpired ? Color.red : Color.secondary)
|
||
.multilineTextAlignment(.center)
|
||
.padding(.horizontal, 40)
|
||
}
|
||
|
||
// 备选:扫码登录(需另一台已登录设备)。展开时才发起二维码,避免无谓请求。
|
||
DisclosureGroup(isExpanded: $showQR)
|
||
{
|
||
VStack(spacing: 16)
|
||
{
|
||
qrArea
|
||
refreshButton
|
||
Text(t("ios.login.guide"))
|
||
.font(.footnote)
|
||
.foregroundStyle(.secondary)
|
||
.multilineTextAlignment(.center)
|
||
}
|
||
.padding(.top, 12)
|
||
}
|
||
label:
|
||
{
|
||
Text(t("ios.login.scanAlt"))
|
||
.font(.subheadline)
|
||
}
|
||
.padding(.horizontal, 40)
|
||
.onChange(of: showQR)
|
||
{
|
||
if showQR, auth.qrPayload == nil { Task { await auth.startQRLogin() } }
|
||
}
|
||
|
||
Spacer()
|
||
}
|
||
// iPad:登录内容约束到可读列宽并水平居中,避免主登录按钮 / 二维码区在宽屏横向拉满
|
||
//(iPhone 宽度不足 420 仍照常填满,不受影响)。
|
||
.frame(maxWidth: 420)
|
||
.frame(maxWidth: .infinity)
|
||
.padding()
|
||
.tint(.cdropAccent)
|
||
}
|
||
|
||
// 刷新二维码:失效后高亮(glassProminent),未失效时也常驻可手动刷新。两种玻璃样式类型
|
||
// 不同,故经 @ViewBuilder 条件分支。
|
||
@ViewBuilder
|
||
private var refreshButton: some View
|
||
{
|
||
let button = Button { Task { await auth.startQRLogin() } }
|
||
label: { Label(t("ios.login.refresh"), systemImage: "arrow.clockwise") }
|
||
if auth.qrExpired { button.buttonStyle(.glassProminent) }
|
||
else { button.buttonStyle(.glass) }
|
||
}
|
||
|
||
@ViewBuilder
|
||
private var qrArea: some View
|
||
{
|
||
if let payload = auth.qrPayload, let img = qrImage(payload)
|
||
{
|
||
Image(uiImage: img)
|
||
.interpolation(.none)
|
||
.resizable()
|
||
.frame(width: 220, height: 220)
|
||
.padding(16)
|
||
.background(.white, in: RoundedRectangle(cornerRadius: 16))
|
||
.opacity(auth.qrExpired ? 0.25 : 1) // 失效后置灰,视觉提示需刷新
|
||
.overlay
|
||
{
|
||
if auth.qrExpired
|
||
{
|
||
Image(systemName: "arrow.clockwise.circle.fill")
|
||
.font(.system(size: 56))
|
||
.foregroundStyle(.secondary)
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ProgressView()
|
||
.frame(width: 220, height: 220)
|
||
}
|
||
}
|
||
|
||
// CoreImage 内建二维码生成(无第三方依赖)。payload 是后端给的完整 /link?r=..&c=.. URL。
|
||
private func qrImage(_ string: String) -> UIImage?
|
||
{
|
||
let filter = CIFilter.qrCodeGenerator()
|
||
filter.message = Data(string.utf8)
|
||
guard let output = filter.outputImage else { return nil }
|
||
let scaled = output.transformed(by: CGAffineTransform(scaleX: 10, y: 10))
|
||
let ctx = CIContext()
|
||
guard let cg = ctx.createCGImage(scaled, from: scaled.extent) else { return nil }
|
||
return UIImage(cgImage: cg)
|
||
}
|
||
}
|