Files
e-party-iOS/yana/ContentView.swift
edwinQQQ a0200c8859 feat: 添加项目基础文件和依赖管理
新增.gitignore、Podfile和Podfile.lock文件以管理项目依赖,添加README.md文件提供项目简介和安装步骤,创建NIMSessionManager、ClientConfig、LogManager和NetworkManager等管理类以支持网络请求和日志记录功能,更新AppDelegate和ContentView以集成NIM SDK和实现用户登录功能。
2025-05-29 16:14:28 +08:00

81 lines
2.1 KiB
Swift

//
// ContentView.swift
// yana
//
// Created by P on 2025/4/21.
//
import SwiftUI
struct ContentView: View {
@State private var account = ""
@State private var password = ""
#if DEBUG
init() {
_account = State(initialValue: "3184")
_password = State(initialValue: "a0d5da073d14731cc7a01ecaa17b9174")
}
#endif
@State private var isLoading = false
@State private var loginError: String?
var body: some View {
VStack {
//
Button("测试初始化") {
ClientConfig.shared.initializeClient()
}
.padding(.top, 20)
TextField("账号", text: $account)
.textFieldStyle(.roundedBorder)
.padding()
SecureField("密码", text: $password)
.textFieldStyle(.roundedBorder)
.padding()
Button(action: handleLogin) {
if isLoading {
ProgressView()
} else {
Text("登录")
}
}
.disabled(isLoading)
.alert("登录错误", isPresented: .constant(loginError != nil)) {
Button("确定") { loginError = nil }
} message: {
Text(loginError ?? "")
}
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, yana!")
}
.padding()
}
private func handleLogin() {
isLoading = true
NIMSessionManager.shared
.autoLogin(account: account, token: password) { error in
if let error = error {
loginError = error.localizedDescription
} else {
//
}
}
// NIMSessionManager.shared.login(account: account, token: password) { error in
// isLoading = false
//
// }
}
}
#Preview {
ContentView()
}