Files
shaguabijia-app-ios/App/Features/Profile/ProfileView.swift
T
marco 98b7600797 初始化傻瓜比价正式版 iOS 客户端
对标安卓正式版、对接 app-server(8770)的 SwiftUI 客户端。iOS 无障碍受限、无比价核心,做自成一体:美团 CPS 导购 + 福利(签到/任务/金币)+ 查看(比价记录/省钱战绩)。
功能完整 M0-M5:脚手架、短信登录(JWT+Keychain+401 自动刷新)、首页券 feed 导购、比价记录+省钱战绩、福利、我的(资料/反馈/设置/注销)。
单 target、0 三方依赖、XcodeGen 生成工程;Debug/Release 双 plist 分流 ATS。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 00:54:11 +08:00

103 lines
3.5 KiB
Swift

import SwiftUI
/// ; + ( M3/M5 ) + 退
struct ProfileView: View {
@Environment(SessionStore.self) private var session
@State private var showLogoutConfirm = false
var body: some View {
NavigationStack {
Group {
if session.isLoggedIn {
loggedInContent
} else {
LoginRequiredView(message: "登录后查看你的账户、比价记录与省钱战绩")
}
}
.navigationTitle("我的")
.task { await session.refreshProfile() }
}
}
private var loggedInContent: some View {
List {
Section {
NavigationLink {
ProfileEditView()
} label: {
HStack(spacing: 14) {
avatarView
VStack(alignment: .leading, spacing: 4) {
Text(session.user?.nickname ?? "傻瓜比价用户")
.font(.headline)
if let phone = session.user?.phone {
Text(phone.maskedPhone)
.font(.subheadline)
.foregroundStyle(.secondary)
}
}
}
.padding(.vertical, 6)
}
}
Section {
NavigationLink {
CompareRecordsView()
} label: {
Label("我的比价记录", systemImage: "list.bullet.rectangle")
}
NavigationLink {
SavingsView()
} label: {
Label("省钱战绩", systemImage: "chart.line.uptrend.xyaxis")
}
}
Section {
NavigationLink {
FeedbackView()
} label: {
Label("帮助与反馈", systemImage: "questionmark.circle")
}
NavigationLink {
InviteView()
} label: {
Label("邀请好友", systemImage: "person.2")
}
NavigationLink {
SettingsView()
} label: {
Label("设置", systemImage: "gearshape")
}
}
Section {
Button(role: .destructive) {
showLogoutConfirm = true
} label: {
Text("退出登录").frame(maxWidth: .infinity)
}
}
}
.alert("确认退出登录?", isPresented: $showLogoutConfirm) {
Button("退出", role: .destructive) { Task { await session.logout() } }
Button("取消", role: .cancel) {}
}
}
private var avatarView: some View {
AsyncImage(url: AppConfig.mediaURL(session.user?.avatarUrl)) { phase in
if case .success(let image) = phase {
image.resizable().aspectRatio(contentMode: .fill)
} else {
Image(systemName: "person.crop.circle.fill")
.resizable()
.foregroundStyle(AppColors.gray300)
}
}
.frame(width: 52, height: 52)
.clipShape(Circle())
}
}