KMComparativeTableViewController.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // KMComparativeTableViewController.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/2/24.
  6. //
  7. import Cocoa
  8. typealias KMComparativeTableViewControllerLoginAction = (_ controller: KMComparativeTableViewController) -> Void
  9. typealias KMComparativeTableViewControllerSignUpAction = (_ controller: KMComparativeTableViewController) -> Void
  10. var comparativeController: KMComparativeTableViewController?
  11. var comparativeMainWindow: NSWindow?
  12. class KMComparativeTableViewController: NSWindowController {
  13. @IBOutlet weak var comparativeTableView: KMComparativeTableView!
  14. var inputType: DataNavigationViewButtonActionType?
  15. var loginAction: KMComparativeTableViewControllerLoginAction?
  16. var signUpAction: KMComparativeTableViewControllerSignUpAction?
  17. deinit {
  18. print("KMComparativeTableViewController 释放")
  19. }
  20. //MARK: 打开文件
  21. /**
  22. @abstract 弹出比较表
  23. @param window 弹出window
  24. @param type 从什么页面跳转到比较表 默认batch
  25. */
  26. static func show(window: NSWindow, _ type: DataNavigationViewButtonActionType = .Batch) -> KMComparativeTableViewController {
  27. let controller: KMComparativeTableViewController = KMComparativeTableViewController.init(windowNibName: "KMComparativeTableViewController")
  28. controller.inputType = type
  29. controller.loginAction = { controller in
  30. comparativeController = nil
  31. comparativeMainWindow?.endSheet(controller.window!)
  32. comparativeMainWindow = nil
  33. controller.close()
  34. KMLoginWindowController.show(window: NSApp.mainWindow!, .Batch, .login)
  35. }
  36. controller.signUpAction = { controller in
  37. comparativeController = nil
  38. comparativeMainWindow?.endSheet(controller.window!)
  39. comparativeMainWindow = nil
  40. controller.close()
  41. KMLoginWindowController.show(window: NSApp.mainWindow!, .Batch, .register)
  42. }
  43. window.beginSheet(controller.window!)
  44. comparativeController = controller
  45. comparativeMainWindow = window
  46. return controller
  47. }
  48. override func windowDidLoad() {
  49. super.windowDidLoad()
  50. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  51. self.setup()
  52. }
  53. func setup() {
  54. self.window?.contentView?.backgroundColor(NSColor(hex: "FFFFFF"))
  55. self.comparativeTableView.closeAction = { view in
  56. print("关闭")
  57. comparativeMainWindow?.endSheet(view.window!)
  58. view.window?.close()
  59. comparativeController = nil
  60. comparativeMainWindow = nil
  61. }
  62. self.comparativeTableView.signUpAction = { [weak self] view in
  63. print("注册")
  64. guard let callBack = self?.signUpAction else { return }
  65. callBack(self!)
  66. }
  67. self.comparativeTableView.loginAction = { [weak self] view in
  68. print("登录")
  69. guard let callBack = self?.loginAction else { return }
  70. callBack(self!)
  71. }
  72. }
  73. }