import SwiftUI import XuqmSDK struct LoginView: View { @ObservedObject var viewModel: AuthViewModel @State private var userId: String = "user_a" @State private var password: String = "123456" var body: some View { VStack(spacing: 20) { Spacer() Text("XuqmGroup IM") .font(.largeTitle) .fontWeight(.bold) Text("iOS Demo") .font(.subheadline) .foregroundStyle(.secondary) Spacer().frame(height: 40) VStack(spacing: 16) { TextField("用户 ID", text: $userId) .textContentType(.username) #if os(iOS) .autocapitalization(.none) #endif .padding() .background(Color.gray.opacity(0.15)) .clipShape(RoundedRectangle(cornerRadius: 12)) SecureField("密码", text: $password) .textContentType(.password) .padding() .background(Color.gray.opacity(0.15)) .clipShape(RoundedRectangle(cornerRadius: 12)) } if case .error(let msg) = viewModel.state { Text(msg) .font(.caption) .foregroundStyle(.red) .multilineTextAlignment(.center) } Button { viewModel.login(userId: userId.trimmingCharacters(in: .whitespaces), password: password) } label: { HStack { if case .loading = viewModel.state { ProgressView() .tint(.white) } Text("登录") .fontWeight(.semibold) } .frame(maxWidth: .infinity) .padding() .background(Color.accentColor) .foregroundStyle(.white) .clipShape(RoundedRectangle(cornerRadius: 12)) } .disabled(viewModel.state == .loading || userId.isEmpty || password.isEmpty) Spacer() Text("演示环境: https://dev.xuqinmin.com") .font(.caption2) .foregroundStyle(.secondary) } .padding(.horizontal, 32) } }