Просмотр исходного кода

【轻会员】重复点击规避

lizhe 2 лет назад
Родитель
Сommit
1d634ee5a4

+ 22 - 29
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/KMLoginWindowController.swift

@@ -94,8 +94,8 @@ class KMLoginWindowController: NSWindowController {
         }
 
         //登录界面点击下一步按钮
-        self.loginView.nextAction = { [unowned self] (view, data) in
-            KMRequestServerManager.manager.verificationEmail(userName: data.email, verifyEmailType: .login) { success, result in
+        self.loginView.nextAction = { [unowned self] (view, data, sender) in
+            KMRequestServerManager.manager.verificationEmail(userName: data.email, verifyEmailType: .login) { [unowned self] success, result in
                 if success {
                     self.model.email = data.email
                     self.logType = .loginInputPassword
@@ -120,11 +120,13 @@ class KMLoginWindowController: NSWindowController {
                                 return
                             }
                         }
-                        return
+                        
                     } else {
                         self.loginView.showAlert(result: result)
                     }
                 }
+                sender.isEnabled = true
+                sender.alphaValue = 1
             }
         }
         
@@ -135,7 +137,7 @@ class KMLoginWindowController: NSWindowController {
         }
 
         //注册界面点击下一步按钮
-        self.registerView.nextAction = { [unowned self] (view, data) in
+        self.registerView.nextAction = { [unowned self] (view, data, sender) in
             KMRequestServerManager.manager.verificationEmail(userName: data.email, verifyEmailType: .register) { success, result in
                 if success {
                     KMRequestServerManager.manager.getVerifyCode(verifyCodeType: .register, email: data.email) { success, result in
@@ -152,6 +154,8 @@ class KMLoginWindowController: NSWindowController {
                 } else {
                     self.registerView.showEmailAlert(result: result!)
                 }
+                sender.isEnabled = true
+                sender.alphaValue = 1
             }
         }
         
@@ -170,7 +174,7 @@ class KMLoginWindowController: NSWindowController {
         }
         
         //验证码界面点击完成按钮
-        self.verificationCodeView.doneAction = { [unowned self] (view, data) in
+        self.verificationCodeView.doneAction = { [unowned self] (view, data, sender) in
             if view.inputType == .register {
                 KMRequestServerManager.manager.register(userName: data.email, password: data.password, verifyCode: data.verifyCode) { [unowned self] (success, requestData, result) in
                     if success {
@@ -181,6 +185,8 @@ class KMLoginWindowController: NSWindowController {
                     } else {
                         self.verificationCodeView.showAlert(result: result)
                     }
+                    sender.isEnabled = true
+                    sender.alphaValue = 1
                 }
             } else if view.inputType == .loginInputPassword {
                 KMRequestServerManager.manager.verificationCode(account: data.email, verifyCode: data.verifyCode, verifyCodeType: .resetPassword) { success, result in
@@ -191,25 +197,29 @@ class KMLoginWindowController: NSWindowController {
                     } else {
                         self.verificationCodeView.showAlert(result: result)
                     }
+                    sender.isEnabled = true
+                    sender.alphaValue = 1
                 }
             }
         }
         
         //验证码界面点击重新发送验证码按钮
-        self.verificationCodeView.reSendAction = { [unowned self] view in
+        self.verificationCodeView.reSendAction = { [unowned self] (view, textView) in
             KMRequestServerManager.manager.getVerifyCode(verifyCodeType: self.verificationCodeView.verifyCodeType, email: self.verificationCodeView.model.email) { success, result in
                 if success {
                     self.verificationCodeView.resetTimer()
                 } else {
                     self.verificationCodeView.showAlert(result: result!)
                 }
+                textView.isSelectable = true
+                textView.alphaValue = 1
             }
         }
         
         
         //loginInputPasswordView
         //登录输入密码界面点击登录按钮
-        self.loginInputPasswordView.loginAction = { [unowned self] (view, data) in
+        self.loginInputPasswordView.loginAction = { [unowned self] (view, data, sender) in
             KMRequestServerManager.manager.login(email: data.email, password: data.password) { success, requestData, result in
                 if success {
                     KMRequestServerManager.manager.getUserInfo { success, data, error in
@@ -219,30 +229,11 @@ class KMLoginWindowController: NSWindowController {
                             loginWindowController = nil
                         }
                     }
-                } else if result?.code == 318 {
-                    let alert = NSAlert()
-                    alert.messageText = NSLocalizedString("Unable to log", comment: "")
-                    alert.informativeText = NSLocalizedString("Your account is currently being logged out and cannot be logged in.If you  have questions, you can contact customer service", comment: "")
-                    alert.addButton(withTitle: NSLocalizedString("Contact Customer", comment: ""))
-                    alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
-                    alert.beginSheetModal(for: view.window!) { result in
-                        if (result == .alertFirstButtonReturn) {
-        //                    KMMailHelper.newEmail(withContacts: "support@pdfreaderpro.com", andSubjects: "")
-        //                    NSWorkspace.shared.launchApplication("Mailto:support@pdfreaderpro.com")
-                            NSWorkspace.shared.open(URL(string: "mailto:support@pdfreaderpro.com")!)
-                            
-        //                    let service = NSSharingService(named: NSSharingService.Name.composeEmail)
-        //                    service?.recipients = ["support@pdfreaderpro.com"]
-        //                    service?.subject = "Test Mail"
-        //                    service?.perform(withItems: ["Test Mail body"])
-                        } else if result == .alertSecondButtonReturn {
-                            return
-                        }
-                    }
-                    return
                 } else {
                     self.loginInputPasswordView.showAlert(result: result)
                 }
+                sender.isEnabled = true
+                sender.alphaValue = 1
             }
         }
         
@@ -267,7 +258,7 @@ class KMLoginWindowController: NSWindowController {
         
         //resetPasswordView
         //重置密码界面点击完成按钮
-        self.resetPasswordView.doneAction = { [unowned self] (view, data) in
+        self.resetPasswordView.doneAction = { [unowned self] (view, data, sender) in
             KMRequestServerManager.manager.resetPassword(account: data.email, firstPassword: data.password, secondPassword: data.rePassword, verifyCode: data.verifyCode) {[unowned self] (success, result) in
                 if success {
                     self.model.email = data.email
@@ -275,6 +266,8 @@ class KMLoginWindowController: NSWindowController {
                 } else {
                     self.verificationCodeView.showAlert(result: result!)
                 }
+                sender.isEnabled = true
+                sender.alphaValue = 1
             }
         }
         

+ 5 - 3
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMLoginInputPasswordView.swift

@@ -8,7 +8,7 @@
 import Cocoa
 
 typealias KMLoginInputPasswordViewChangeEmailAction = (_ view: KMLoginInputPasswordView) -> Void
-typealias KMLoginInputPasswordViewLoginAction = (_ view: KMLoginInputPasswordView, _ data: KMRegisterModel) -> Void
+typealias KMLoginInputPasswordViewLoginAction = (_ view: KMLoginInputPasswordView, _ data: KMRegisterModel, _ sender: NSButton) -> Void
 typealias KMLoginInputPasswordViewforgotPasswordAction = (_ view: KMLoginInputPasswordView, _ data: KMRegisterModel) -> Void
 class KMLoginInputPasswordView: KMBaseXibView {
 
@@ -170,10 +170,12 @@ class KMLoginInputPasswordView: KMBaseXibView {
 
 protocol KMLoginInputPasswordViewAction {}
 extension KMLoginInputPasswordView: KMLoginInputPasswordViewAction  {
-    @IBAction func loginButtonAction(_ sender: Any) {
+    @IBAction func loginButtonAction(_ sender: NSButton) {
         guard let callBack = loginAction else { return }
         
-        callBack(self, self.model)
+        sender.isEnabled = false
+        sender.alphaValue = 0.5
+        callBack(self, self.model, sender)
     }
     
     @IBAction func forgotPasswordButtonAction(_ sender: Any) {

+ 3 - 0
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMLoginInputPasswordView.xib

@@ -180,6 +180,9 @@
                             <buttonCell key="cell" type="square" title="Login" bezelStyle="shadowlessSquare" alignment="center" imageScaling="proportionallyDown" inset="2" id="zzl-rj-AU8">
                                 <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                 <font key="font" metaFont="system"/>
+                                <string key="keyEquivalent" base64-UTF8="YES">
+DQ
+</string>
                             </buttonCell>
                             <connections>
                                 <action selector="loginButtonAction:" target="-2" id="FA6-Uk-r07"/>

+ 5 - 3
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMLoginView.swift

@@ -8,7 +8,7 @@
 import Cocoa
 
 typealias KMLoginViewRegisterAction = (_ view: KMLoginView, _ data: KMRegisterModel) -> Void
-typealias KMLoginViewNextAction = (_ view: KMLoginView, _ data: KMRegisterModel) -> Void
+typealias KMLoginViewNextAction = (_ view: KMLoginView, _ data: KMRegisterModel, _ sender: NSButton) -> Void
 
 class KMLoginView: KMBaseXibView {
     
@@ -143,10 +143,12 @@ extension KMLoginView: NSTextFieldDelegate {
 //MARK: 事件
 protocol KMLoginViewAction {}
 extension KMLoginView: KMLoginViewAction {
-    @IBAction func nextButtonAction(_ sender: Any) {
+    @IBAction func nextButtonAction(_ sender: NSButton) {
         guard let callBack = self.nextAction else { return }
         
-        callBack(self, self.model)
+        sender.isEnabled = false
+        sender.alphaValue = 0.5
+        callBack(self, self.model, sender)
     }
     
     func emainDidEndEditing() {

+ 3 - 0
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMLoginView.xib

@@ -117,6 +117,9 @@
                                     <buttonCell key="cell" type="square" title="Next Step" bezelStyle="shadowlessSquare" alignment="center" imageScaling="proportionallyDown" inset="2" id="0Zf-nU-w6r">
                                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                         <font key="font" metaFont="system"/>
+                                        <string key="keyEquivalent" base64-UTF8="YES">
+DQ
+</string>
                                     </buttonCell>
                                     <connections>
                                         <action selector="nextButtonAction:" target="-2" id="Q02-GL-h6w"/>

+ 3 - 0
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMRegisterSuccessView.xib

@@ -56,6 +56,9 @@
                     <buttonCell key="cell" type="square" title="Getting Started" bezelStyle="shadowlessSquare" alignment="center" imageScaling="proportionallyDown" inset="2" id="Z4z-3P-BWh">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                         <font key="font" metaFont="system"/>
+                        <string key="keyEquivalent" base64-UTF8="YES">
+DQ
+</string>
                     </buttonCell>
                     <connections>
                         <action selector="doneButtonAction:" target="-2" id="Eoy-fL-R6H"/>

+ 5 - 3
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMRegisterView.swift

@@ -8,7 +8,7 @@
 import Cocoa
 
 typealias KMRegisterViewLoginAction = (_ view: KMRegisterView, _ data: KMRegisterModel) -> Void
-typealias KMRegisterViewNextAction = (_ view: KMRegisterView, _ data: KMRegisterModel) -> Void
+typealias KMRegisterViewNextAction = (_ view: KMRegisterView, _ data: KMRegisterModel, _ sender: NSButton) -> Void
 
 class KMRegisterView: KMBaseXibView {
     
@@ -256,10 +256,12 @@ extension KMRegisterView: NSTextViewDelegate {
 
 protocol KMRegisterViewAction {}
 extension KMRegisterView: KMRegisterViewAction {
-    @IBAction func nextButtonAction(_ sender: Any) {
+    @IBAction func nextButtonAction(_ sender: NSButton) {
         guard let callBack = self.nextAction else { return }
         print("KMRegisterView 下一步")
-        callBack(self, self.model)
+        sender.isEnabled = false
+        sender.alphaValue = 0.5
+        callBack(self, self.model, sender)
     }
     
     @IBAction func showButtonAction(_ sender: NSButton) {

+ 3 - 0
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMRegisterView.xib

@@ -192,6 +192,9 @@
                                     <buttonCell key="cell" type="square" title="Next Step" bezelStyle="shadowlessSquare" alignment="center" imageScaling="proportionallyDown" inset="2" id="OAQ-RN-7Sv">
                                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                         <font key="font" metaFont="system"/>
+                                        <string key="keyEquivalent" base64-UTF8="YES">
+DQ
+</string>
                                     </buttonCell>
                                     <connections>
                                         <action selector="nextButtonAction:" target="-2" id="p02-hi-cju"/>

+ 5 - 3
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMResetPasswordView.swift

@@ -7,7 +7,7 @@
 
 import Cocoa
 
-typealias KMResetPasswordViewDoneAction = (_ view: KMResetPasswordView, _ data: KMRegisterModel) -> Void
+typealias KMResetPasswordViewDoneAction = (_ view: KMResetPasswordView, _ data: KMRegisterModel, _ sender: NSButton) -> Void
 class KMResetPasswordView: KMBaseXibView {
 
     @IBOutlet weak var titleLabel: NSTextField!
@@ -186,7 +186,7 @@ protocol KMResetPasswordViewAction {}
 extension KMResetPasswordView : KMResetPasswordViewAction {
     
     
-    @IBAction func doneButtonAction(_ sender: Any) {
+    @IBAction func doneButtonAction(_ sender: NSButton) {
         guard let callBack = doneAction else { return }
         
         if self.model.password != self.model.rePassword {
@@ -194,7 +194,9 @@ extension KMResetPasswordView : KMResetPasswordViewAction {
             return
         }
         
-        callBack(self, self.model)
+        sender.isEnabled = false
+        sender.alphaValue = 0.5
+        callBack(self, self.model, sender)
     }
     
     @IBAction func showButtonAction(_ sender: Any) {

+ 3 - 0
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMResetPasswordView.xib

@@ -212,6 +212,9 @@
                     <buttonCell key="cell" type="square" title="OK" bezelStyle="shadowlessSquare" alignment="center" imageScaling="proportionallyDown" inset="2" id="CkC-c8-RDw">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                         <font key="font" metaFont="system"/>
+                        <string key="keyEquivalent" base64-UTF8="YES">
+DQ
+</string>
                     </buttonCell>
                     <connections>
                         <action selector="doneButtonAction:" target="-2" id="dNf-3V-QJI"/>

+ 13 - 8
PDF Office/PDF Office/Class/KMLightMember/Controller/VerificationCode/KMVerficationCodeWindowController.swift

@@ -33,7 +33,7 @@ class KMVerficationCodeWindowController: NSWindowController {
         controller.verificationCodeView.inputType = .accountInfo
         controller.verificationCodeView.model.email = KMLightMemberManager.manager.info.email
         controller.verificationCodeView.beginTimer()
-        controller.sendVerifyCode()
+        controller.sendVerifyCode(sender: nil)
         verficationCodeController = controller
         return controller
     }
@@ -55,9 +55,9 @@ class KMVerficationCodeWindowController: NSWindowController {
             verficationCodeController = nil
         }
         
-        self.verificationCodeView.doneAction = { view, data in
+        self.verificationCodeView.doneAction = { [unowned self] (view, data , sender) in
             print("注销")
-            [KMRequestServerManager.manager.logOff(verifyCode: data.verifyCode, complete: { success, result in
+            KMRequestServerManager.manager.logOff(verifyCode: data.verifyCode, complete: { success, result in
                 if success {
                     NSApp.mainWindow!.endSheet(view.window!)
                     view.window?.close()
@@ -65,21 +65,26 @@ class KMVerficationCodeWindowController: NSWindowController {
                 } else {
                     self.verificationCodeView.showAlert(result: result)
                 }
-            })]
+                sender.isEnabled = true
+            })
         }
         
-        self.verificationCodeView.reSendAction = { view in
-            self.sendVerifyCode()
+        self.verificationCodeView.reSendAction = {[unowned self]  view, sender in
+            self.sendVerifyCode(sender: sender)
         }
     }
     
-    func sendVerifyCode() {
-        KMRequestServerManager.manager.getVerifyCode(verifyCodeType: self.verificationCodeView.verifyCodeType, email: self.verificationCodeView.model.email) { success, result in
+    func sendVerifyCode(sender: NSTextView?) {
+        KMRequestServerManager.manager.getVerifyCode(verifyCodeType: self.verificationCodeView.verifyCodeType, email: self.verificationCodeView.model.email) { [unowned self] success, result in
             if success {
                 self.verificationCodeView.resetTimer()
             } else {
                 self.verificationCodeView.showAlert(result: result)
             }
+            
+            if sender != nil {
+                sender!.isSelectable = true
+            }
         }
     }
     

+ 7 - 5
PDF Office/PDF Office/Class/KMLightMember/Controller/VerificationCode/View/KMVerificationCodeView.swift

@@ -8,9 +8,9 @@
 import Cocoa
 
 typealias KMVerificationCodeViewCancelAction = (_ view: KMVerificationCodeView) -> Void
-typealias KMVerificationCodeViewDoneAction = (_ view: KMVerificationCodeView, _ data: KMRegisterModel) -> Void
+typealias KMVerificationCodeViewDoneAction = (_ view: KMVerificationCodeView, _ data: KMRegisterModel, _ sender: NSButton) -> Void
 typealias KMVerificationCodeViewCloseAction = (_ view: KMVerificationCodeView) -> Void
-typealias KMVerificationCodeViewReSendAction = (_ view: KMVerificationCodeView) -> Void
+typealias KMVerificationCodeViewReSendAction = (_ view: KMVerificationCodeView, _ sender: NSTextView) -> Void
 class KMVerificationCodeView: KMBaseXibView {
 
     @IBOutlet weak var titleLabel: NSTextField!
@@ -303,7 +303,9 @@ extension KMVerificationCodeView: KMVerificationCodeViewAction {
     @IBAction func doneButtonAction(_ sender: NSButton) {
         guard let callBack = doneAction else { return }
         self.model.verifyCode = self.verificationCode
-        callBack(self, self.model)
+        sender.isEnabled = false
+        sender.alphaValue = 0.5
+        callBack(self, self.model, sender)
     }
     
     @IBAction func closeButtonAction(_ sender: Any) {
@@ -323,8 +325,8 @@ extension KMVerificationCodeView: NSTextViewDelegate {
     func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
         if link as! String == "timer://" && self.time == 60 {
             guard let callBack = reSendAction else { return true }
-            
-            callBack(self)
+            textView.isSelectable = false
+            callBack(self, textView)
         }
         return true
     }