PasswordLoginUIView.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // PasswordLoginUIView.swift
  3. // fiveConstant
  4. //
  5. // Created by 李建 on 2023/1/14.
  6. //
  7. import SwiftUI
  8. import SwiftyUserDefaults
  9. struct PasswordLoginUIView: View {
  10. @State private var phoneNumber: String = ""
  11. @State private var password: String = ""
  12. @State private var isAllow: Bool = false
  13. @EnvironmentObject var proState: ProgressState;
  14. @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
  15. var body: some View {
  16. VStack(spacing: 50) {
  17. Spacer()
  18. VStack(alignment: .leading, spacing: 60) {
  19. VStack(alignment: .leading, spacing: 10.0) {
  20. Text("密码登录")
  21. .font(.title)
  22. .fontWeight(.bold)
  23. }
  24. VStack {
  25. VStack(alignment: .center, spacing: 15) {
  26. VStack {
  27. HStack(spacing: 3) {
  28. Image(systemName: "phone.fill")
  29. .foregroundColor(Color("MainColor"))
  30. TextField("请输入您的手机号", text: $phoneNumber)
  31. .disableAutocorrection(true)
  32. .padding(8)
  33. }
  34. Divider().foregroundColor(Color.gray)
  35. .opacity(0.5)
  36. }
  37. VStack {
  38. ZStack(alignment: .trailing) {
  39. HStack(spacing: 3) {
  40. Image(systemName: "lock.fill")
  41. .foregroundColor(Color("MainColor"))
  42. SecureField("请输入密码", text: $password)
  43. .disableAutocorrection(true)
  44. .padding(8)
  45. }
  46. NavigationLink{
  47. ResetPasswordUIView()
  48. } label: {
  49. Text("忘记密码?").foregroundColor(Color("MainColor"))
  50. }
  51. }
  52. Divider().foregroundColor(Color.gray).opacity(0.5)
  53. }
  54. }.padding(.bottom, 20)
  55. Button(action: {
  56. let params = PasswordLoginReq(phone: self.phoneNumber, password: password)
  57. HttpRequest<SMSLoginResp>.loadData(target: LoginAPI.passwordLogin(param: params)) { returnData in
  58. Defaults[\.token]? = returnData.access_token
  59. if returnData.app_first_login {
  60. // 跳转设置密码
  61. proState.isNeedLogin = false
  62. } else {
  63. proState.isNeedLogin = false
  64. }
  65. } failure: { _, msg in
  66. HUD.show(title: msg!)
  67. }
  68. }, label: {
  69. Text("登录")
  70. .foregroundColor(.white)
  71. .padding()
  72. .frame(maxWidth: .infinity)
  73. .background(
  74. Color("MainColor")
  75. .cornerRadius(8)
  76. )
  77. .border(Color("MainColor"), width: 0)
  78. }
  79. )
  80. Spacer()
  81. HStack (spacing: 0){
  82. RadioButton(selected: $isAllow)
  83. Text("我已阅读并同意")
  84. .font(.caption)
  85. Text("《用户服务协议》")
  86. .font(.caption)
  87. .foregroundColor(Color("MainColor"))
  88. Text("以及")
  89. .font(.caption)
  90. Text("《隐私协议》")
  91. .font(.caption)
  92. .foregroundColor(Color("MainColor"))
  93. }
  94. }
  95. }
  96. }.padding()
  97. .navigationBarBackButtonHidden(true)
  98. .navigationBarItems(leading: Button(action: {
  99. self.presentationMode.wrappedValue.dismiss()
  100. }, label: {
  101. Image(systemName: "chevron.left")
  102. .foregroundColor(.gray)
  103. }))
  104. }
  105. }
  106. struct PasswordLoginUIView_Previews: PreviewProvider {
  107. static var previews: some View {
  108. PasswordLoginUIView()
  109. }
  110. }