AccountCenterController.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // AccountCenterController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/10/29.
  6. //
  7. import Cocoa
  8. class AccountCenterController: NSViewController {
  9. @IBOutlet weak var contentBox: NSBox!
  10. private lazy var closeButton_: NSButton = {
  11. let view = NSButton()
  12. view.isBordered = false
  13. view.title = ""
  14. return view
  15. }()
  16. private var profileC_ = AccountProfileController()
  17. private var moreBenefitC = AccountMoreBenefitsController()
  18. var rightDatas: [String] = []
  19. var model: AccountRightModel?
  20. var infoModel: AccountInfoModel?
  21. var goLoginBlock: KMCommonBlock?
  22. convenience init() {
  23. self.init(nibName: "AccountCenterController", bundle: MainBundle)
  24. }
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27. // Do view setup here.
  28. self.contentBox.borderWidth = 0
  29. self.view.addSubview(self.closeButton_)
  30. self.closeButton_.km_add_right_constraint(constant: -25)
  31. self.closeButton_.km_add_top_constraint(constant: 20)
  32. self.closeButton_.km_add_size_constraint(size: .init(width: 16, height: 16))
  33. self.closeButton_.target = self
  34. self.closeButton_.action = #selector(_closeAction)
  35. self.closeButton_.image = NSImage(named: "KMImageNameAccountClose2")
  36. self.gotoProfile()
  37. }
  38. func gotoProfile() {
  39. self.profileC_.rightDatas = self.rightDatas
  40. self.profileC_.model = self.model
  41. self.profileC_.userInfoModel = self.infoModel
  42. self.contentBox.contentView = self.profileC_.view
  43. self.profileC_.itemClick = { [weak self] idx, _ in
  44. if idx == 1 { // 更多权益
  45. self?.gotoMoreBenefit()
  46. }
  47. }
  48. self.profileC_.goLoginBlock = self.goLoginBlock
  49. }
  50. func gotoMoreBenefit() {
  51. self.moreBenefitC.rightDatas = self.rightDatas
  52. self.moreBenefitC.datas = self.model?.moreBenefits ?? []
  53. self.contentBox.contentView = self.moreBenefitC.view
  54. self.moreBenefitC.itemClick = { [weak self] idx, _ in
  55. self?.gotoProfile()
  56. }
  57. }
  58. // MARK: - Private Methods
  59. @objc private func _closeAction() {
  60. self.view.window?.windowController?.km_quick_endSheet()
  61. }
  62. }