feat: 跳转登录页面
This commit is contained in:
parent
8eecd42076
commit
a8f6be62e1
Binary file not shown.
@ -7,7 +7,7 @@
|
||||
<key>wake.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>3</integer>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
|
||||
@ -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,14 +177,9 @@ struct ContentView: View {
|
||||
showSettings = false
|
||||
}
|
||||
}
|
||||
|
||||
/// 重置导航路径
|
||||
private func resetNavigationPath() {
|
||||
navigationPath.removeLast(navigationPath.count)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - 预览
|
||||
#Preview {
|
||||
ContentView()
|
||||
}
|
||||
}
|
||||
@ -7,263 +7,99 @@ 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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user