feat: 跳转登录页面

This commit is contained in:
jinyaqiu 2025-08-18 15:54:00 +08:00
parent 8eecd42076
commit a8f6be62e1
4 changed files with 95 additions and 293 deletions

View File

@ -7,7 +7,7 @@
<key>wake.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
<integer>0</integer>
</dict>
</dict>
</dict>

View File

@ -11,37 +11,25 @@ extension AnyTransition {
}
}
// MARK: -
enum Route: Hashable {
case settings //
}
// MARK: -
struct ContentView: View {
// MARK: -
@State private var showModal = false //
@State private var showSettings = false //
@State private var navigationPath = NavigationPath() //
@State private var contentOffset: CGFloat = 0 //
@State private var showLogin = false
// MARK: -
var body: some View {
NavigationStack(path: $navigationPath) {
//
let _ = Self._printChanges()
let _ = print("导航路径已更新: \(navigationPath)")
//
NavigationView {
ZStack {
//
//
VStack {
VStack(spacing: 20) {
//
Spacer().frame(height: UIApplication.shared.windows.first?.safeAreaInsets.top ?? 0)
Text("Wake")
.font(.custom("SankeiCutePopanime", size: 27))
// -
//
HStack {
//
Button(action: showUserProfile) {
@ -49,33 +37,24 @@ struct ContentView: View {
.font(.title2)
.padding()
}
Spacer() //
Spacer()
//
NavigationLink(destination: LoginView()) {
Text("登录")
.font(.headline)
.padding(.horizontal, 16)
.padding(.vertical, 8)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
}
.padding(.trailing)
}
Spacer()
VStack(alignment: .leading, spacing: 16) {
Text("这是主标题")
.font(Typography.font(for: .headline))
Text("这是次级标题")
.font(Typography.font(for: .title))
Text("这是正文内容,适用于段落和说明文字。")
.font(Typography.font(for: .body))
Text("这是副标题")
.font(Typography.font(for: .subtitle))
.foregroundColor(.secondary)
Text("ABCDEFG").font(Typography.font(for: .headline))
Text("脚注信息")
.font(Typography.font(for: .footnote))
}
.padding()
.onAppear {
//
print("当前字体缩放级别: \(UIView.appearance().traitCollection.preferredContentSizeCategory)")
}
//
List {
Section(header: Text("我的收藏")) {
@ -136,13 +115,10 @@ struct ContentView: View {
}
.listStyle(GroupedListStyle())
.padding(.top, 0)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(.systemBackground))
//
.offset(x: showModal ? UIScreen.main.bounds.width * 0.8 : 0)
//
.animation(.spring(response: 0.6, dampingFraction: 0.8), value: showModal)
.edgesIgnoringSafeArea(.all)
}
@ -157,35 +133,30 @@ struct ContentView: View {
showSettings: $showSettings
)
}
//
.offset(x: showSettings ? UIScreen.main.bounds.width : 0)
.animation(.spring(response: 0.6, dampingFraction: 0.8), value: showSettings)
//
ZStack {
//
if showSettings {
Color.black.opacity(0)
Color.black.opacity(0.3)
.edgesIgnoringSafeArea(.all)
.onTapGesture(perform: hideSettings)
.transition(.opacity)
}
//
if showSettings {
SettingsView(isPresented: $showSettings)
.transition(.move(edge: .leading)) //
.zIndex(1) //
.onAppear(perform: resetNavigationPath)
.transition(.move(edge: .leading))
.zIndex(1)
}
}
.animation(.spring(response: 0.6, dampingFraction: 0.8), value: showSettings)
}
.navigationBarHidden(true)
}
}
// MARK: -
///
private func showUserProfile() {
withAnimation(.spring(response: 0.6, dampingFraction: 0.8)) {
@ -206,11 +177,6 @@ struct ContentView: View {
showSettings = false
}
}
///
private func resetNavigationPath() {
navigationPath.removeLast(navigationPath.count)
}
}
// MARK: -

View File

@ -7,264 +7,100 @@ struct Post: Codable {
let body: String
let userId: Int
}
struct Login: Encodable {
let account: String
let password: String
}
struct LoginView: View {
@Environment(\.dismiss) private var dismiss
@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
@State private var username = ""
@State private var password = ""
@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)
//
NavigationView {
ZStack {
VStack {
// Back button and settings
HStack {
Spacer()
Button(action: {
withAnimation(.spring(response: 0.5, dampingFraction: 0.8)) {
showModal = true
Button(action: { dismiss() }) {
HStack {
Image(systemName: "chevron.left")
Text("返回")
}
.padding()
}
}) {
Spacer()
Button(action: { showModal = true }) {
Image(systemName: "gearshape")
.font(.title2)
.padding()
}
}
Text("邮箱登录").font(.title)
// Login form
VStack(spacing: 20) {
Text("邮箱登录").font(.title)
//
// Username field
TextField("请输入用户名", text: $username)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding(.horizontal)
// Password field
SecureField("请输入密码", text: $password)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding(.horizontal)
// Login button
Button(action: handleLogin) {
if isLoading {
ProgressView()
} else {
Text("登录")
}
}
.buttonStyle(.borderedProminent)
.disabled(isLoading)
.padding()
}
Spacer()
}
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
// Modal view
if showModal {
Color.black.opacity(0.4)
.edgesIgnoringSafeArea(.all)
.onTapGesture { showModal = false }
// Your modal content here
VStack {
//
CustomTextField(
placeholder: "请输入用户名",
type: .username,
value: $username
)
//
CustomTextField(
placeholder: "请输入密码",
type: .password,
value: $password
)
//
CustomButton(
text: "登录",
type: .primary,
size: .large,
fullWidth: true,
isLoading: isLoading
) {
handleLogin()
}
Text("Settings")
Button("Close") { showModal = false }
}
.padding()
Spacer()
.frame(width: 300, height: 200)
.background(Color.white)
.cornerRadius(20)
}
.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)
}
}
}
}
func handleLogin() {
isLoading = true
// Your login logic here
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
isLoading = false
}
}
}
#Preview {
LoginView()
}