소스 검색

【会员系统】验证码Send按钮,默认置灰,email符合规则后允许点击

wanjun 4 달 전
부모
커밋
88b43010a5
2개의 변경된 파일19개의 추가작업 그리고 15개의 파일을 삭제
  1. 11 2
      PDF Office/PDF Master/MemberCenter/View/KMSignUpView.swift
  2. 8 13
      PDF Office/PDF Master/MemberCenter/ViewModel/KMSignUpViewModel.swift

+ 11 - 2
PDF Office/PDF Master/MemberCenter/View/KMSignUpView.swift

@@ -105,7 +105,11 @@ class KMSignUpView: KMBaseXibView {
         emailErrorLabel.font = NSFont.SFProTextRegularFont(9)
         passwordBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.gray
         verifficationBox.borderColor = NSColor(named: "FA1E5D") ?? NSColor.gray
-        sendBox.fillColor = NSColor(named: "273C62") ?? NSColor.blue
+        if viewModel.isValidEmail() {
+            sendBox.fillColor = NSColor(named: "273C62") ?? NSColor.blue
+        } else {
+            sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
+        }
         sendBox.borderColor = NSColor(named: "273C62") ?? NSColor.blue
         sendLabel.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
         sendLabel.font = NSFont.SFProTextRegularFont(16)
@@ -159,6 +163,7 @@ class KMSignUpView: KMBaseXibView {
             guard let self = self else { return }
             if self.viewModel.email.count <= 0 { return }
             if self.viewModel.sendBoxSelect { return }
+            if !self.viewModel.isValidEmail() { return }
             if mouseEntered {
                 self.sendBox.fillColor = NSColor(named: "000000_0.1") ?? NSColor.blue
                 self.sendBox.borderWidth = 1
@@ -257,7 +262,11 @@ class KMSignUpView: KMBaseXibView {
         sendLabel.stringValue = viewModel.sendContent
         if viewModel.sendContent == NSLocalizedString("Send", tableName: "MemberCenterLocalizable", comment: "") {
             if viewModel.email.count > 0 {
-                sendBox.fillColor = NSColor(named: "273C62") ?? NSColor.blue
+                if viewModel.isValidEmail() {
+                    sendBox.fillColor = NSColor(named: "273C62") ?? NSColor.blue
+                } else {
+                    sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
+                }
             } else {
                 sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
             }

+ 8 - 13
PDF Office/PDF Master/MemberCenter/ViewModel/KMSignUpViewModel.swift

@@ -79,10 +79,10 @@ class KMSignUpViewModel: ObservableObject {
     }
     
     func countDown(type: KMVerificationCodeType, count: Int = 60) -> Void {
-        getVerificationCode(type)
-        if emailErrorMessage.count > 0 {
+        if emailErrorMessage.count > 0 || !isValidEmail() {
             return
         }
+        getVerificationCode(type)
         
         sendBoxSelect = true
         remainingSeconds = count
@@ -122,12 +122,10 @@ class KMSignUpViewModel: ObservableObject {
         return false
     }
     
-    // MARK: Private Method
-    
     /**
      @abstract 验证邮箱是否合规
      */
-    private func isValidEmail() -> Bool {
+    func isValidEmail() -> Bool {
         let emailRegex = "^[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"
         let emailTest = NSPredicate(format: "SELF MATCHES %@", emailRegex)
         return emailTest.evaluate(with: email)
@@ -136,12 +134,14 @@ class KMSignUpViewModel: ObservableObject {
     /**
      @abstract 验证验证码是否合规
      */
-    private func isValidVerificationCode() -> Bool {
+    func isValidVerificationCode() -> Bool {
         let pattern = "^\\d{6}$"
         let regex = try! NSRegularExpression(pattern: pattern)
         return regex.firstMatch(in: verificationCode, options: [], range: NSRange(location: 0, length: verificationCode.utf16.count)) != nil
     }
     
+    // MARK: Private Method
+        
     /**
      @abstract 刷新用户个人信息
      */
@@ -171,7 +171,7 @@ class KMSignUpViewModel: ObservableObject {
         
         var code: String = ""
         if signUpState == .verificationCode {
-            if verificationCode.count <= 0 || verificationCode.count > 6 {
+            if verificationCode.count <= 0 || verificationCode.count > 6 || !isValidVerificationCode() {
                 passwordErrorMessage = NSLocalizedString("*Please enter right Verification code", tableName: "MemberCenterLocalizable", comment: "")
                 return
             }
@@ -269,12 +269,7 @@ class KMSignUpViewModel: ObservableObject {
      @param
      */
     func enterVerificationCodeNextAction(_ complete: @escaping ForgotPasswordComplete) -> Void {
-        if verificationCode.count <= 0 {
-            emailErrorMessage = NSLocalizedString("*Please enter right Verification code", tableName: "MemberCenterLocalizable", comment: "")
-            complete(false, "")
-            return
-        }
-        if !isValidVerificationCode() {
+        if verificationCode.count <= 0 || !isValidVerificationCode() {
             emailErrorMessage = NSLocalizedString("*Please enter right Verification code", tableName: "MemberCenterLocalizable", comment: "")
             complete(false, "")
             return