SmsLoginUIView.swift 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // SmsLoginUIView.swift
  3. // fiveConstant
  4. //
  5. // Created by 李建 on 2023/1/11.
  6. //
  7. import SwiftUI
  8. import AlertToast
  9. import SwiftyUserDefaults
  10. struct SmsLoginUIView: View {
  11. @State private var phoneNumber = ""
  12. @State private var checkCode: String = ""
  13. @State private var isAllow: Bool = false
  14. @EnvironmentObject var proState: ProgressState;
  15. var body: some View {
  16. NavigationView {
  17. VStack {
  18. HStack{
  19. Spacer()
  20. NavigationLink {
  21. PasswordLoginUIView()
  22. } label: {
  23. Text("密码登录")
  24. .font(.title2)
  25. .fontWeight(.bold)
  26. .padding()
  27. .foregroundColor(Color.primary)
  28. }
  29. }
  30. VStack(spacing: 50) {
  31. Spacer()
  32. VStack(alignment: .leading, spacing: 60) {
  33. VStack(alignment: .leading, spacing: 10.0) {
  34. Text("手机号码快捷登录")
  35. .font(.title)
  36. .fontWeight(.bold)
  37. Text("首次登录将自动创建帐号")
  38. .foregroundColor(Color.gray)
  39. }
  40. VStack {
  41. VStack(alignment: .center, spacing: 10) {
  42. VStack {
  43. HStack(spacing: 3) {
  44. Image(systemName: "phone.fill")
  45. .foregroundColor(Color("MainColor"))
  46. TextField("请输入您的手机号", text: $phoneNumber)
  47. .disableAutocorrection(true)
  48. .keyboardType(.numbersAndPunctuation)
  49. .padding(8)
  50. }
  51. Divider().foregroundColor(Color.gray)
  52. .opacity(0.5)
  53. }
  54. ZStack(alignment: .trailing) {
  55. VStack {
  56. HStack(spacing: 3) {
  57. Image(systemName: "envelope.fill")
  58. .foregroundColor(Color("MainColor"))
  59. TextField("请输入验证码", text: $checkCode)
  60. .disableAutocorrection(true)
  61. .keyboardType(.numberPad)
  62. .padding(8)
  63. }
  64. Divider().foregroundColor(Color.gray)
  65. .opacity(0.5)
  66. }
  67. GetCheckCodeButton {
  68. let data = GetCheckCodeReq(tel: phoneNumber, bzty: 1)
  69. HttpRequest<CheckCodeResp>.loadData(target: LoginAPI.getCheckCode(data: data)) { _ in
  70. HUD.show(title: "验证码已经发送成功!")
  71. } failure: { code, message in
  72. HUD.show(title: message!)
  73. }
  74. }
  75. }
  76. }.padding(.bottom, 20)
  77. Button(action: {
  78. // 登录
  79. guard self.isAllow else {
  80. HUD.show(title: "请先阅读并同意《用户协议》及《隐私协议》")
  81. return
  82. }
  83. let param = SMSLoginReq(phone: phoneNumber, code: checkCode)
  84. HttpRequest<SMSLoginResp>.loadData(target: LoginAPI.smsLogin(param: param)) { returnData in
  85. Defaults[\.token]? = returnData.access_token
  86. if returnData.app_first_login {
  87. // 跳转设置密码
  88. proState.isNeedLogin = false
  89. } else {
  90. proState.isNeedLogin = false
  91. }
  92. } failure: { _, message in
  93. HUD.show(title: message!)
  94. }
  95. }, label: {
  96. Text("登录")
  97. .foregroundColor(.white)
  98. .padding()
  99. .frame(maxWidth: .infinity)
  100. .background(
  101. Color("MainColor")
  102. .cornerRadius(8)
  103. )
  104. .border(Color("MainColor"), width: 0)
  105. })
  106. Spacer()
  107. HStack (spacing: 0){
  108. RadioButton(selected: $isAllow)
  109. Text("我已阅读并同意")
  110. .font(.caption)
  111. Text("《用户服务协议》")
  112. .font(.caption)
  113. .foregroundColor(Color("MainColor"))
  114. .onTapGesture {
  115. }
  116. Text("以及")
  117. .font(.caption)
  118. Text("《隐私协议》")
  119. .font(.caption)
  120. .foregroundColor(Color("MainColor"))
  121. }
  122. }
  123. }
  124. }.padding()
  125. }
  126. .navigationBarHidden(true)
  127. }
  128. }
  129. }
  130. struct SmsLoginUIView_Previews: PreviewProvider {
  131. static var previews: some View {
  132. SmsLoginUIView()
  133. }
  134. }