wake-ios/wake/View/Login/Login.swift
2025-08-14 19:49:54 +08:00

271 lines
10 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()
}