feat: 设置页面

This commit is contained in:
jinyaqiu 2025-08-28 19:00:11 +08:00
parent 2f0d487dc4
commit b6178896ec
2 changed files with 128 additions and 26 deletions

View File

@ -3,7 +3,7 @@ import Foundation
/// API /// API
public enum APIConfig { public enum APIConfig {
/// API URL /// API URL
public static let baseURL = "https://api.memorywake.com/api/v1" public static let baseURL = "https://api-dev.memorywake.com:31274/api/v1"
/// token - Keychain /// token - Keychain
public static var authToken: String { public static var authToken: String {

View File

@ -1,40 +1,117 @@
import SwiftUI import SwiftUI
// User profile model
struct UserProfile: Codable {
let userId: String
let nickname: String
let avatarUrl: String?
let account: String
let email: String
enum CodingKeys: String, CodingKey {
case userId = "user_id"
case nickname
case avatarUrl = "avatar_file_url"
case account
case email
}
}
// API Response wrapper
struct APIResponse<T: Codable>: Codable {
let code: Int
let data: T
}
struct UserProfileModal: View { struct UserProfileModal: View {
@Binding var showModal: Bool @Binding var showModal: Bool
@Binding var showSettings: Bool @Binding var showSettings: Bool
@State private var userProfile: UserProfile?
@State private var isLoading = false
@State private var errorMessage: String?
@State private var isCopied = false
var body: some View { var body: some View {
// Modal content with transparent background
VStack(spacing: 20) { VStack(spacing: 20) {
Spacer() Spacer()
.frame(height: UIApplication.shared.windows.first?.safeAreaInsets.top ?? 0) .frame(height: UIApplication.shared.windows.first?.safeAreaInsets.top ?? 0)
//
if isLoading {
ProgressView()
.padding()
} else if let error = errorMessage {
Text(error)
.foregroundColor(.red)
.padding()
}
HStack(alignment: .center, spacing: 16) { HStack(alignment: .center, spacing: 16) {
Image(systemName: "person.circle.fill") if let avatarUrl = userProfile?.avatarUrl, !avatarUrl.isEmpty, let url = URL(string: avatarUrl) {
.resizable() AsyncImage(url: url) { phase in
.aspectRatio(contentMode: .fill) switch phase {
.frame(width: 60, height: 60) case .success(let image):
.foregroundColor(.blue) image
.clipShape(Circle()) .resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 60, height: 60)
.clipShape(Circle())
default:
Image(systemName: "person.circle.fill")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 60, height: 60)
.foregroundColor(.blue)
}
}
} else {
Image(systemName: "person.circle.fill")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 60, height: 60)
.foregroundColor(.blue)
}
VStack(alignment: .leading, spacing: 10) { VStack(alignment: .leading, spacing: 10) {
Text("Name") Text(userProfile?.nickname ?? "Name")
.font(Typography.font(for: .body)) .font(Typography.font(for: .body))
.fontWeight(.bold) .fontWeight(.bold)
.foregroundColor(.themeTextMessageMain) .foregroundColor(.themeTextMessageMain)
HStack(spacing: 4) { HStack(spacing: 4) {
Text("ID: 12345678") Text("ID: \(userProfile?.userId ?? "")")
.font(.system(size: 14)) .font(.system(size: 14))
.foregroundColor(.themeTextMessageMain) .foregroundColor(.themeTextMessageMain)
.lineLimit(1)
.truncationMode(.tail)
.fixedSize(horizontal: false, vertical: true)
.frame(maxWidth: 120)
Button(action: { Button(action: {
UIPasteboard.general.string = "12345678" print("Copy ID button tapped")
UIPasteboard.general.string = userProfile?.userId
print("Copied to clipboard:", userProfile?.userId ?? "nil")
withAnimation {
isCopied = true
// Reset after 2 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
withAnimation {
isCopied = false
print("Reset copy button state")
}
}
}
}) { }) {
Image(systemName: "doc.on.doc") if isCopied {
.font(.system(size: 12)) Image(systemName: "checkmark")
.foregroundColor(.themeTextMessageMain) .foregroundColor(.themePrimary)
} else {
Image(systemName: "doc.on.doc")
}
} }
.font(.system(size: 12))
.foregroundColor(.themeTextMessageMain)
.animation(.easeInOut, value: isCopied)
.contentShape(Rectangle()) // Make the entire button area tappable
.frame(width: 24, height: 24) // Ensure minimum touch target size
} }
} }
@ -52,8 +129,8 @@ struct UserProfileModal: View {
ZStack(alignment: .center) { ZStack(alignment: .center) {
// SVG - // SVG -
SVGImage(svgName: "Pioneer") SVGImage(svgName: "Pioneer")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.scaledToFill() .scaledToFill()
.frame(maxWidth: .infinity, maxHeight: .infinity)
// //
VStack(alignment: .leading, spacing: 6) { VStack(alignment: .leading, spacing: 6) {
@ -80,9 +157,9 @@ struct UserProfileModal: View {
} }
.frame(height: 112) .frame(height: 112)
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
.cornerRadius(16)
.clipped() // .clipped() //
VStack(spacing: 12) { VStack(spacing: 12) {
// upload // upload
Button(action: { Button(action: {
@ -102,9 +179,9 @@ struct UserProfileModal: View {
} }
.padding() .padding()
.cornerRadius(10) .cornerRadius(10)
.contentShape(Rectangle()) // 使 .contentShape(Rectangle())
} }
.buttonStyle(PlainButtonStyle()) // .buttonStyle(PlainButtonStyle())
// memories // memories
Button(action: { Button(action: {
@ -124,9 +201,9 @@ struct UserProfileModal: View {
} }
.padding() .padding()
.cornerRadius(10) .cornerRadius(10)
.contentShape(Rectangle()) // 使 .contentShape(Rectangle())
} }
.buttonStyle(PlainButtonStyle()) // .buttonStyle(PlainButtonStyle())
// Box // Box
Button(action: { Button(action: {
@ -146,9 +223,9 @@ struct UserProfileModal: View {
} }
.padding() .padding()
.cornerRadius(10) .cornerRadius(10)
.contentShape(Rectangle()) // 使 .contentShape(Rectangle())
} }
.buttonStyle(PlainButtonStyle()) // .buttonStyle(PlainButtonStyle())
// setting // setting
Button(action: { Button(action: {
@ -170,10 +247,9 @@ struct UserProfileModal: View {
} }
.padding() .padding()
.cornerRadius(10) .cornerRadius(10)
.contentShape(Rectangle()) // 使 .contentShape(Rectangle())
} }
.buttonStyle(PlainButtonStyle()) // .buttonStyle(PlainButtonStyle())
} }
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
.padding() .padding()
@ -189,6 +265,32 @@ struct UserProfileModal: View {
.background(Color.themeTextWhiteSecondary) .background(Color.themeTextWhiteSecondary)
.cornerRadius(20, corners: [.topRight, .bottomRight]) .cornerRadius(20, corners: [.topRight, .bottomRight])
.edgesIgnoringSafeArea(.all) .edgesIgnoringSafeArea(.all)
.onAppear {
fetchUserInfo()
}
}
private func fetchUserInfo() {
isLoading = true
errorMessage = nil
NetworkService.shared.get(
path: "/iam/user-info",
parameters: nil
) { (result: Result<APIResponse<UserProfile>, NetworkError>) in
DispatchQueue.main.async {
isLoading = false
switch result {
case .success(let response):
self.userProfile = response.data
print("✅ Successfully fetched user info:", response.data)
case .failure(let error):
self.errorMessage = error.localizedDescription
print("❌ Failed to fetch user info:", error)
}
}
}
} }
} }