| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //
- // SmsLoginUIView.swift
- // fiveConstant
- //
- // Created by 李建 on 2023/1/11.
- //
- import SwiftUI
- import AlertToast
- import SwiftyUserDefaults
- struct SmsLoginUIView: View {
- @State private var phoneNumber = ""
- @State private var checkCode: String = ""
- @State private var isAllow: Bool = false
- @EnvironmentObject var proState: ProgressState;
- var body: some View {
- NavigationView {
- VStack {
- HStack{
- Spacer()
- NavigationLink {
- PasswordLoginUIView()
- } label: {
- Text("密码登录")
- .font(.title2)
- .fontWeight(.bold)
- .padding()
- .foregroundColor(Color.primary)
- }
- }
- VStack(spacing: 50) {
- Spacer()
- VStack(alignment: .leading, spacing: 60) {
- VStack(alignment: .leading, spacing: 10.0) {
- Text("手机号码快捷登录")
- .font(.title)
- .fontWeight(.bold)
-
- Text("首次登录将自动创建帐号")
- .foregroundColor(Color.gray)
- }
- VStack {
- VStack(alignment: .center, spacing: 10) {
- VStack {
- HStack(spacing: 3) {
- Image(systemName: "phone.fill")
- .foregroundColor(Color("MainColor"))
- TextField("请输入您的手机号", text: $phoneNumber)
- .disableAutocorrection(true)
- .keyboardType(.numbersAndPunctuation)
- .padding(8)
- }
- Divider().foregroundColor(Color.gray)
- .opacity(0.5)
- }
- ZStack(alignment: .trailing) {
- VStack {
- HStack(spacing: 3) {
- Image(systemName: "envelope.fill")
- .foregroundColor(Color("MainColor"))
- TextField("请输入验证码", text: $checkCode)
- .disableAutocorrection(true)
- .keyboardType(.numberPad)
- .padding(8)
- }
- Divider().foregroundColor(Color.gray)
- .opacity(0.5)
- }
- GetCheckCodeButton {
-
- let data = GetCheckCodeReq(tel: phoneNumber, bzty: 1)
- HttpRequest<CheckCodeResp>.loadData(target: LoginAPI.getCheckCode(data: data)) { _ in
- HUD.show(title: "验证码已经发送成功!")
- } failure: { code, message in
- HUD.show(title: message!)
- }
- }
- }
- }.padding(.bottom, 20)
- Button(action: {
- // 登录
- guard self.isAllow else {
- HUD.show(title: "请先阅读并同意《用户协议》及《隐私协议》")
- return
- }
- let param = SMSLoginReq(phone: phoneNumber, code: checkCode)
- HttpRequest<SMSLoginResp>.loadData(target: LoginAPI.smsLogin(param: param)) { returnData in
- Defaults[\.token]? = returnData.access_token
- if returnData.app_first_login {
- // 跳转设置密码
- proState.isNeedLogin = false
- } else {
- proState.isNeedLogin = false
- }
- } failure: { _, message in
- HUD.show(title: message!)
- }
- }, label: {
- Text("登录")
- .foregroundColor(.white)
- .padding()
- .frame(maxWidth: .infinity)
- .background(
- Color("MainColor")
- .cornerRadius(8)
- )
- .border(Color("MainColor"), width: 0)
-
- })
- Spacer()
- HStack (spacing: 0){
- RadioButton(selected: $isAllow)
- Text("我已阅读并同意")
- .font(.caption)
- Text("《用户服务协议》")
- .font(.caption)
- .foregroundColor(Color("MainColor"))
- .onTapGesture {
-
- }
- Text("以及")
- .font(.caption)
- Text("《隐私协议》")
- .font(.caption)
- .foregroundColor(Color("MainColor"))
-
- }
- }
- }
- }.padding()
-
- }
- .navigationBarHidden(true)
- }
-
- }
- }
- struct SmsLoginUIView_Previews: PreviewProvider {
- static var previews: some View {
- SmsLoginUIView()
- }
- }
|