Add networking layer and wire up v9 login flow with unit tests.

Introduce APIClient/AuthAPI, complete login with multi-account selection, and polish the login card UI with shadow and keyboard dismiss.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-06 15:33:34 +08:00
co-authored by Cursor
parent b7d74905b7
commit 699f1ba7c4
21 changed files with 2387 additions and 18 deletions
+47
View File
@@ -0,0 +1,47 @@
//
// AuthAPI.swift
// suixinkan
//
import Foundation
@MainActor
/// 登录认证 API,封装 config、v9 登录和账号选择相关接口。
final class AuthAPI {
private let client: APIClient
/// 初始化登录 API,并注入共享网络客户端。
init(client: APIClient) {
self.client = client
}
/// 获取 App 配置,控制注册/验证码登录入口显隐。
func getAppConfig() async throws -> AppConfigResponse {
try await client.send(
APIRequest(method: .get, path: "/api/app/config")
)
}
/// 使用手机号和密码发起 v9 登录,返回临时 token 及可选账号列表。
func login(username: String, password: String) async throws -> V9AuthResponse {
try await client.send(
APIRequest(
method: .post,
path: "/api/app/v9/login",
body: LoginRequest(username: username, password: password)
)
)
}
/// 选择具体景区或门店账号,换取正式登录 token。
func setUser(_ request: SetUserRequest, tokenOverride: String? = nil) async throws -> V9AuthResponse {
try await client.send(
APIRequest(
method: .post,
path: "/api/app/v9/set-user",
body: request
),
tokenOverride: tokenOverride
)
}
}