123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- //
- // KMVerficationCodeWindowController.swift
- // PDF Master
- //
- // Created by lizhe on 2023/2/24.
- //
- import Cocoa
- var verficationCodeController: KMVerficationCodeWindowController?
- var verficationCodeMainWindow: NSWindow?
- typealias KMVerficationCodeWindowControllerDidCancellation = () -> ()
- class KMVerficationCodeWindowController: NSWindowController {
- @IBOutlet weak var verificationCodeView: KMVerificationCodeView!
- @IBOutlet weak var networkView: KMLightNoNetworkView!
-
- var didCancellation: KMVerficationCodeWindowControllerDidCancellation?
- var inputType: DataNavigationViewButtonActionType?
-
- deinit {
- KMPrint("KMVerficationCodeWindowController 释放")
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- self.setup()
- }
-
- //MARK: 打开文件
- static func show(window: NSWindow, _ type: DataNavigationViewButtonActionType = .Batch, _ logType: KMRegisterLogType = .login) -> KMVerficationCodeWindowController {
- let controller: KMVerficationCodeWindowController = KMVerficationCodeWindowController.init(windowNibName: "KMVerficationCodeWindowController")
- controller.inputType = type
- window.beginSheet(controller.window!)
- controller.window?.center()
- controller.verificationCodeView.inputType = .accountInfo
- controller.verificationCodeView.model.email = KMLightMemberManager.manager.info.email
- controller.sendVerifyCode(sender: nil)
- verficationCodeController = controller
- verficationCodeMainWindow = window
- return controller
- }
-
- func setup() {
- self.window?.contentView?.backgroundColor(NSColor.km_init(hex: "#FFFFFF"))
-
- self.verificationCodeView.closeAction = { view in
- KMPrint("关闭")
- verficationCodeMainWindow?.endSheet(view.window!)
- view.window?.close()
- verficationCodeController = nil
- verficationCodeMainWindow = nil
- }
-
- self.verificationCodeView.cancelAction = { view in
- KMPrint("登出")
- verficationCodeMainWindow?.endSheet(view.window!)
- view.window?.close()
- verficationCodeController = nil
- verficationCodeMainWindow = nil
- }
-
- self.verificationCodeView.doneAction = { [unowned self] (view, data , sender) in
- KMPrint("注销")
- KMRequestServerManager.manager.logOff(verifyCode: data.verifyCode, complete: { [weak self] success, result in
- if self?.verificationCodeView != nil {
- if success {
- verficationCodeMainWindow?.endSheet(view.window!)
- view.window?.close()
- verficationCodeController = nil
- verficationCodeMainWindow = nil
- self?.didCancellation?()
- } else {
- self?.verificationCodeView.showAlert(result: result)
- }
- self?.verificationCodeView.changeDoneButtonState(enable: true)
- }
- })
- }
-
- self.verificationCodeView.reSendAction = {[weak self] view, sender in
- self?.sendVerifyCode(sender: sender)
- }
-
- self.verificationCodeView.verificationCodeAction = { [weak self] (view, data, codeString) in
- KMRequestServerManager.manager.verificationCode(account: data.email, verifyCode: codeString, verifyCodeType: view.verifyCodeType) { success, result in
- if self?.verificationCodeView != nil {
- if success {
- self?.verificationCodeView.updateNetworkingState(complete: true, codeIsTure: true)
- } else {
- self?.verificationCodeView.updateNetworkingState(complete: true, codeIsTure: false)
- self?.verificationCodeView.showAlert(result: result)
- }
- }
- }
- }
-
- KMRequestServer.requestServer.reachabilityStatusChange { [weak self] status in
- if status == .notReachable {
- KMPrint("无网络")
- self?.networkView.isHidden = false
- } else {
- KMPrint("有网络")
- self?.networkView.isHidden = true
- }
- }
- }
-
- func sendVerifyCode(sender: NSTextView?) {
- KMRequestServerManager.manager.getVerifyCode(verifyCodeType: self.verificationCodeView.verifyCodeType, email: self.verificationCodeView.model.email) { [weak self] success, result in
- if self?.verificationCodeView != nil {
- if success {
- self?.verificationCodeView.resetTimer()
- } else {
- self?.verificationCodeView.showAlert(result: result)
- self?.verificationCodeView.time = (self?.verificationCodeView!.startTime)!
- self?.verificationCodeView.updateLanguage()
- }
-
- if sender != nil {
- sender!.isSelectable = true
- }
- }
- }
- }
-
- }
|