浏览代码

Merge branch 'develop_PDFReaderPro_V4.7.0' of git.kdan.cc:Mac_PDF/PDF_Office into develop_PDFReaderPro_V4.7.0

zenghong 1 周之前
父节点
当前提交
3c4c576431

+ 36 - 0
PDF Office/PDF Master/Class/Common/Category/NSWindowController+KMExtension.swift

@@ -27,6 +27,16 @@ extension NSWindowController {
             }
         }
     }
+    
+    func showWaitingView(to view: NSView) {
+        window?.hideWaitingView()
+        
+        window?.showWaitingView()
+    }
+
+    func hideWaitingView(from view: NSView) {
+        window?.hideWaitingView()
+    }
 }
 
 extension NSWindowController: KMForceProtocol {
@@ -39,6 +49,32 @@ extension NSWindow {
     override func km_window() -> NSWindow? {
         return self
     }
+    
+    func showWaitingView() {
+        hideWaitingView()
+        
+        guard let view = contentView else {
+            return
+        }
+        
+        let waitingView = WaitingView(frame: view.bounds)
+        waitingView.autoresizingMask = [.width, .height]
+        view.addSubview(waitingView)
+        waitingView.startAnimation()
+    }
+
+    func hideWaitingView() {
+        guard let view = contentView else {
+            return
+        }
+        
+        for subview in view.subviews {
+            if subview is WaitingView {
+                subview.removeFromSuperview()
+                break
+            }
+        }
+    }
 }
 
 // MARK: - 互动模式

+ 3 - 1
PDF Office/PDF Master/MemberCenter/Model/KMMemberInfo.swift

@@ -230,7 +230,9 @@ import Cocoa
             dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
             var startTime = Date()
             if KMMemberInfo.shared.vip_endDate.count > 0 {
-                startTime = dateFormatter.date(from: KMMemberInfo.shared.vip_endDate)!
+                if let data = dateFormatter.date(from: KMMemberInfo.shared.vip_endDate) {
+                    startTime = data
+                }
             }
             let currentTime = Date()
             

+ 2 - 2
PDF Office/PDF Master/MemberCenter/View/KMEnterVerificationCodeView.swift

@@ -60,7 +60,7 @@ class KMEnterVerificationCodeView: KMBaseXibView {
         initializeUI()
         sendBoxRefresh()
 
-        viewModel.countDown(type: .reset)
+        viewModel.countDown(type: .reset, callback: nil)
         
         sendBox.moveCallback =  { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
             guard let self = self else { return }
@@ -79,7 +79,7 @@ class KMEnterVerificationCodeView: KMBaseXibView {
             if self.viewModel.sendBoxSelect { return }
             if downEntered {
                 self.sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
-                self.viewModel.countDown(type: .reset)
+                self.viewModel.countDown(type: .reset, callback: nil)
             }
         }
     }

+ 3 - 0
PDF Office/PDF Master/MemberCenter/View/KMForgotPasswordView.swift

@@ -180,7 +180,10 @@ class KMForgotPasswordView: KMBaseXibView {
             return
         }
         viewModel.emailErrorMessage = ""
+        window?.showWaitingView()
         viewModel.forgotPasswordNextAction() { [weak self] success, msg in
+            self?.window?.hideWaitingView()
+            
             guard let self = self else { return }
             if success {
                 self.skipEnterVerificationCodeView()

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

@@ -197,7 +197,7 @@ class KMSignUpView: KMBaseXibView {
             if self.viewModel.sendBoxSelect { return }
             if downEntered {
                 self.sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
-                self.viewModel.countDown(type: .login)
+                self.viewModel.countDown(type: .login, callback: nil)
             }
         }
     }
@@ -408,7 +408,11 @@ class KMSignUpView: KMBaseXibView {
         
         viewModel.emailErrorMessage = ""
         viewModel.passwordErrorMessage = ""
-        viewModel.signUpAction()
+        
+        window?.showWaitingView()
+        viewModel.signUpAction { [weak self] result, _ in
+            self?.window?.hideWaitingView()
+        }
     }
     
     @IBAction func forgetAction(_ sender: NSButton) {

+ 3 - 1
PDF Office/PDF Master/MemberCenter/ViewController/KMUserInfoViewController.swift

@@ -109,7 +109,9 @@ class KMUserInfoViewController: NSViewController {
     private var viewModel = KMUserInfoVCModel()
     private var cancellables = Set<AnyCancellable>()
     
-    
+    deinit {
+        KMPrint("KMUserInfoViewController deinit.")
+    }
 
     override func viewDidLoad() {
         super.viewDidLoad()

+ 23 - 5
PDF Office/PDF Master/MemberCenter/ViewModel/KMSignUpViewModel.swift

@@ -94,11 +94,11 @@ class KMSignUpViewModel: ObservableObject {
         }
     }
     
-    func countDown(type: KMVerificationCodeType, count: Int = 60) -> Void {
+    func countDown(type: KMVerificationCodeType, count: Int = 60, callback: ((Bool?, Any ...)->Void)?) -> Void {
         if emailErrorMessage.count > 0 || !isValidEmail() {
             return
         }
-        getVerificationCode(type)
+        getVerificationCode(type, callback: callback)
         
         sendBoxSelect = true
         remainingSeconds = count
@@ -194,7 +194,7 @@ class KMSignUpViewModel: ObservableObject {
      @abstract KMSignUpView Sign Up 登录按钮响应事件
      @param
      */
-    func signUpAction() -> Void {
+    func signUpAction(callback: ((Bool?, Any ...)->Void)?) -> Void {
         if KMMemberCenterManager.manager.isConnectionAvailable() == false {
             let alert = NSAlert()
             alert.alertStyle = .critical
@@ -202,10 +202,14 @@ class KMSignUpViewModel: ObservableObject {
             alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
             alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
             alert.runModal()
+            
+            callback?(nil)
             return
         }
         if email.count <= 0 || email.count > 100 || !isValidEmail() {
             emailErrorMessage = NSLocalizedString("Email format error. Please enter the correct email.", tableName: "MemberCenterLocalizable", comment: "")
+            
+            callback?(nil)
             return
         }
         
@@ -213,12 +217,16 @@ class KMSignUpViewModel: ObservableObject {
         if signUpState == .verificationCode {
             if verificationCode.count <= 0 || verificationCode.count > 6 || !isValidVerificationCode() {
                 passwordErrorMessage = NSLocalizedString("Verification code error.", tableName: "MemberCenterLocalizable", comment: "")
+                
+                callback?(nil)
                 return
             }
             code = verificationCode
         } else if signUpState == .password {
             if password.count <= 0 || verificationCode.count > 30 {
                 passwordErrorMessage = NSLocalizedString("Password error.", tableName: "MemberCenterLocalizable", comment: "")
+                
+                callback?(nil)
                 return
             }
             code = password
@@ -232,9 +240,13 @@ class KMSignUpViewModel: ObservableObject {
             if (result == .alertFirstButtonReturn) {
                 privacyState = true
             }
+            
+            callback?(nil)
             return
         }
         KMMemberCenterManager.manager.emailLogin(email: email, code: code, type: signUpState) { [weak self] success, wrapper  in
+            callback?(success)
+            
             guard let self = self else { return }
             let resultDict = wrapper! as KMMemberCenterResult
             let msg = resultDict.msg
@@ -289,7 +301,7 @@ class KMSignUpViewModel: ObservableObject {
                     if response == .alertFirstButtonReturn {
                         if(resultDict.code == 317) {
                             self.signUpState = .verificationCode
-                            self.countDown(type: .login)
+                            self.countDown(type: .login, callback: nil)
                         } else {
                             
                         }
@@ -370,7 +382,7 @@ class KMSignUpViewModel: ObservableObject {
      @abstract 获取邮箱验证码
      @param
      */
-    func getVerificationCode(_ type: KMVerificationCodeType) -> Void {
+    func getVerificationCode(_ type: KMVerificationCodeType, callback: ((Bool?, Any ...)->Void)?) -> Void {
         if KMMemberCenterManager.manager.isConnectionAvailable() == false {
             let alert = NSAlert()
             alert.alertStyle = .critical
@@ -378,14 +390,20 @@ class KMSignUpViewModel: ObservableObject {
             alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
             alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
             alert.runModal()
+            
+            callback?(nil)
             return
         }
         
         if !isValidEmail() {
             emailErrorMessage = NSLocalizedString("Please enter the correct email format", tableName: "MemberCenterLocalizable", comment: "")
+            
+            callback?(nil)
             return
         }
         KMMemberCenterManager.manager.getVerificationCode(action: type, receiver: email) { [weak self] success, wrapper  in
+            callback?(success)
+            
             guard let self = self else { return }
             let resultDict = wrapper! as KMMemberCenterResult
             let msg = resultDict.msg

+ 2 - 2
PDF Office/PDF Master/MemberCenter/WindowsController/KMCloseVerificationWC.swift

@@ -41,7 +41,7 @@ class KMCloseVerificationWC: NSWindowController {
         initializeUI()
         signUpModel.email = KMMemberInfo.shared.userEmail
         
-        signUpModel.countDown(type: .logout)
+        signUpModel.countDown(type: .logout, callback: nil)
         
         nextButton.isEnabled = false
         
@@ -114,7 +114,7 @@ class KMCloseVerificationWC: NSWindowController {
             if self.signUpModel.sendBoxSelect { return }
             if downEntered {
                 self.sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
-                self.signUpModel.countDown(type: .logout)
+                self.signUpModel.countDown(type: .logout, callback: nil)
             }
         }
 

+ 3 - 0
PDF Office/PDF Master/MemberCenter/WindowsController/KMMemberCenterWindowController.swift

@@ -184,7 +184,10 @@ class KMMemberCenterWindowController: NSWindowController {
                 return
             }
             
+            showWaitingView(to: window?.contentView ?? NSView())
             KMMemberCenterManager.manager.logoutDevice(deviceId: device.id!, complete: {[weak self] success, result in
+                self?.hideWaitingView(from: self?.window?.contentView ?? NSView())
+                
                 guard let result = result else { return }
                 let resultDict = result as KMMemberCenterResult
                 let msg = resultDict.msg