// // ContentView.swift // iOSFirst // // Created by 孙宇峰 on 2023/1/31. // import SwiftUI import RxSwift import RxCocoa import RxRelay struct LoginView: View { private var viewModel = LoginViewModel() var bag = DisposeBag() @State private var inputAccountMessage:String = "" @State private var isPresent:Bool = false @State private var checked:Bool = true @State private var inputPasswordMessage:String = "" @Environment(\.presentationMode) var presentationMode; var body: some View { VStack(alignment:.leading,spacing: 0) { HStack{ Spacer() Image("ic_setting") .imageScale(.large) .foregroundColor(.accentColor) Text("设置").font(.system(size: 14)) } Text("欢迎来到") .foregroundColor(.gray) .font(.system(size: 30)) .multilineTextAlignment(.center) .bold() .padding(.top,20) HStack{ Image("app_logo") .resizable() .imageScale(.large) .foregroundColor(.accentColor) .scaledToFill() .frame(width: 50,height: 50) Image("txtlogo") .imageScale(.large) .foregroundColor(.accentColor) .frame(width: 240,height: 35) }.frame(height: 40) .padding(.top,20) .padding(.bottom,100) VStack(alignment: .leading, spacing: 400) { HStack(alignment: .center, spacing: 15) { Image("ic_person") .imageScale(.large) .foregroundColor(.accentColor) TextField("请输入手机号",text:$inputAccountMessage) .keyboardType(UIKeyboardType.namePhonePad) .font(.system(size: 16)) .frame(maxWidth: .infinity,alignment: .center) } } .frame(height: 80) Divider() VStack(alignment: .leading, spacing: 400) { HStack(alignment: .center, spacing: 15) { Image("ic_pwd") .imageScale(.large) .foregroundColor(.accentColor) SecureField("请输入密码",text:$inputPasswordMessage) .textContentType(.oneTimeCode) .keyboardType(UIKeyboardType.namePhonePad) .font(.system(size: 16)) .frame(maxWidth: .infinity,alignment: .center) } }.frame(height: 80) Divider().padding(.bottom,20) VStack(alignment: .trailing, spacing: 400) { VStack(alignment: .trailing, spacing: 15) { HStack { CheckBoxView(checked: $checked) Text("我已阅读并同意") .foregroundColor(.black) .font(.system(size: 15)) Text("《星火云鸽用户协议》") .foregroundColor(.blue) .font(.system(size: 15)) Spacer() } Spacer().frame(height: 15) Button(action: { if(inputAccountMessage.isEmpty){ SUIToast.show(messageItem: .init( message: "账号不能为空", bgColor: .gray, messageColor: .white )) }else if(inputPasswordMessage.isEmpty){ SUIToast.show(messageItem: .init( message: "密码不能为空", bgColor: .gray, messageColor: .white )) }else { viewModel.loginUser(username: inputAccountMessage, password: inputPasswordMessage) if (!viewModel.userResponse.hasObservers){ viewModel.userResponse.subscribe { event in isPresent=true print("接收到的token值\(String(describing: event.element?.token_value))") // 这里需要返回首页,登陆成功后销毁本页面 self.presentationMode.wrappedValue.dismiss() } } } }){ Text("登录") .font(.system(size: 17)) .bold() .frame(minWidth: 0, maxWidth: .infinity) .padding() .foregroundColor(.white) .background(.blue) .cornerRadius(30) }.fullScreenCover(isPresented: $isPresent) { TestView(settingPagePresented: $isPresent) } } } HStack{ Text("验证码登录").font(.system(size:15)).onTapGesture { let msg="点击了验证码登录" print(msg) SUIToast.show(messageItem: .init( message: msg, bgColor: .gray, messageColor: .white )) } Spacer () Text("忘记密码?").font(.system(size:15)).onTapGesture { let msg="点击了密码" print(msg) SUIToast.show(messageItem: .init( message: msg, bgColor: .gray, messageColor: .white )) }.padding(.vertical,20).font(.system(size: 15)) } Spacer() }.padding() .frame(width: .infinity,height: .infinity) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { LoginView() } } struct CheckBoxView: View { @Binding var checked: Bool var body: some View { Image(systemName: checked ? "checkmark.square.fill" : "square") .foregroundColor(checked ? Color(UIColor.systemBlue) : Color.secondary) .onTapGesture { self.checked.toggle() } } }