AccountCenterController.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. convenience init() {
  22. self.init(nibName: "AccountCenterController", bundle: MainBundle)
  23. }
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. // Do view setup here.
  27. self.contentBox.borderWidth = 0
  28. self.view.addSubview(self.closeButton_)
  29. self.closeButton_.km_add_right_constraint(constant: -25)
  30. self.closeButton_.km_add_top_constraint(constant: 20)
  31. self.closeButton_.km_add_size_constraint(size: .init(width: 16, height: 16))
  32. self.closeButton_.target = self
  33. self.closeButton_.action = #selector(_closeAction)
  34. self.closeButton_.image = NSImage(named: "KMImageNameAccountClose2")
  35. self.gotoProfile()
  36. }
  37. func gotoProfile() {
  38. self.profileC_.rightDatas = self.rightDatas
  39. self.profileC_.model = self.model
  40. self.profileC_.userInfoModel = self.infoModel
  41. self.contentBox.contentView = self.profileC_.view
  42. self.profileC_.itemClick = { [weak self] idx, _ in
  43. if idx == 1 { // 更多权益
  44. self?.gotoMoreBenefit()
  45. }
  46. }
  47. }
  48. func gotoMoreBenefit() {
  49. self.moreBenefitC.rightDatas = self.rightDatas
  50. self.moreBenefitC.datas = self.model?.moreBenefits ?? []
  51. self.contentBox.contentView = self.moreBenefitC.view
  52. self.moreBenefitC.itemClick = { [weak self] idx, _ in
  53. self?.gotoProfile()
  54. }
  55. }
  56. // MARK: - Private Methods
  57. @objc private func _closeAction() {
  58. self.view.window?.windowController?.km_quick_endSheet()
  59. }
  60. }