import SwiftUI import Alamofire struct Post: Codable { let id: Int let title: String let body: String let userId: Int } struct Login: Encodable { let account: String let password: String } struct LoginView: View { @State private var showModal = false @State private var showSettings = false @State private var contentOffset: CGFloat = 0 // 用户名称/邮箱 @State private var username="" // 密码 @State private var password="" // 登录loading @State private var isLoading=false // 登录点击事件 func handleLogin() { withAnimation { isLoading = true } // 示例调用 passwordLogin(username: "jyq@memo.cn", password: "111111") // 注意:这里应该在网络请求完成后设置 isLoading = false // 例如在 passwordLogin 的回调中 DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { withAnimation { self.isLoading = false } } } // get 请求 func get(){ AF.request("http://192.168.31.156:31646/api/v1/iam/access-token-refresh").response { response in debugPrint(response) } } // post 请求 func post(){ let login = Login(account: username, password: password) print(login) AF.request("http://192.168.31.156:31646/api/v1/iam/login/password-login", method: .post,parameters: login).response{ response in debugPrint(response) } } // func createPost() { // Task { // do { // print("12132412354365342") // let newPost = try await NetworkManager.shared.request( // endpoint: "/iam/login/password-login", // method: .post, // parameters: [ // "account": username, // "password": password // ] // ) as Post // // 在字符串中添加变量 \(变量) // print("登录成功:$newPost.id)\(username)") // } catch { // print("登录失败:$error)") // // } // } // } var body: some View { ZStack { // Main content with slide effect VStack { VStack(spacing: 20) { // This spacer ensures content stays below the status bar Spacer().frame(height: UIApplication.shared.windows.first?.safeAreaInsets.top ?? 0) // 顶部栏 HStack { Spacer() Button(action: { withAnimation(.spring(response: 0.5, dampingFraction: 0.8)) { showModal = true } }) { Image(systemName: "gearshape") .font(.title2) .padding() } } Text("邮箱登录").font(.title) // 登录表单 VStack { // 账号 CustomTextField( placeholder: "请输入用户名", type: .username, value: $username ) // 密码 CustomTextField( placeholder: "请输入密码", type: .password, value: $password ) // 登录 CustomButton( text: "登录", type: .primary, size: .large, fullWidth: true, isLoading: isLoading ) { handleLogin() } } .padding() Spacer() } .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color(.systemBackground)) .offset(x: showModal ? UIScreen.main.bounds.width * 0.35 : 0) .animation(.spring(response: 0.5, dampingFraction: 0.8), value: showModal) .edgesIgnoringSafeArea(.all) } // 添加半透明遮罩层 if showModal { Color.black.opacity(0.4) .edgesIgnoringSafeArea(.all) .onTapGesture { withAnimation(.spring(response: 0.5, dampingFraction: 0.8)) { showModal = false } } .transition(.opacity) } // Modal with animation SlideInModal(isPresented: $showModal, onDismiss: { withAnimation(.spring(response: 0.5, dampingFraction: 0.8)) { showModal = false } }) { VStack(spacing: 20) { // 用户信息区域 HStack(alignment: .center, spacing: 16) { // 头像 Image(systemName: "person.circle.fill") .resizable() .aspectRatio(contentMode: .fill) .frame(width: 60, height: 60) .foregroundColor(.blue) .clipShape(Circle()) // 姓名和ID VStack(alignment: .leading, spacing: 4) { Text("用户名") .font(.headline) .foregroundColor(.primary) Text("ID: 12345678") .font(.subheadline) .foregroundColor(.secondary) } Spacer() } .padding(.horizontal, 16) .padding(.top, 16) VStack(alignment: .leading, spacing: 8) { Text("会员等级") .font(.headline) .foregroundColor(.primary) Text("会员时间") .font(.subheadline) .foregroundColor(.secondary) Text("会员中心") .font(.subheadline) .foregroundColor(.secondary) } .frame(maxWidth: .infinity, alignment: .leading) .padding(16) .background(Color(red: 0.92, green: 0.92, blue: 0.92)) .cornerRadius(10) .padding(.horizontal, 16) VStack(spacing: 12) { // memories Button(action: { print("memories") }) { HStack(spacing: 16) { Image(systemName: "crown.fill") .foregroundColor(.orange) .frame(width: 24, height: 24) Text("My Memories") .font(.headline) .foregroundColor(.primary) Spacer() } .padding() .cornerRadius(10) .contentShape(Rectangle()) // 使整个区域可点击 } .buttonStyle(PlainButtonStyle()) // 移除按钮默认样式 // Box Button(action: { print("Box") }) { HStack(spacing: 16) { Image(systemName: "clock.fill") .foregroundColor(.blue) .frame(width: 24, height: 24) Text("My Bind Box") .font(.headline) .foregroundColor(.primary) Spacer() } .padding() .cornerRadius(10) .contentShape(Rectangle()) // 使整个区域可点击 } .buttonStyle(PlainButtonStyle()) // 移除按钮默认样式 // setting Button(action: { print("Setting") }) { HStack(spacing: 16) { Image(systemName: "person.circle.fill") .foregroundColor(.purple) .frame(width: 24, height: 24) Text("Setting") .font(.headline) .foregroundColor(.primary) Spacer() } .padding() .cornerRadius(10) .contentShape(Rectangle()) // 使整个区域可点击 } .buttonStyle(PlainButtonStyle()) // 移除按钮默认样式 } .padding(.horizontal, 16) // 这里可以添加其他设置项 Spacer() } .padding(.vertical, 8) } } } } #Preview { LoginView() }