SettingViewController.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // SettingViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 16/7/6.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Alamofire
  10. import AlamofireImage
  11. import AlamofireObjectMapper
  12. import SwiftyJSON
  13. import SDWebImage
  14. import CocoaLumberjack
  15. import O2OA_Auth_SDK
  16. import Flutter
  17. class SettingViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
  18. @IBOutlet weak var settingHeaderView: SettingHeaderView!
  19. @IBOutlet weak var iconImageView: UIImageView!
  20. @IBOutlet weak var nameLabel: UILabel!
  21. @IBOutlet weak var settingItemTableView: UITableView!
  22. @IBOutlet weak var SettingHeaderViewTopConstraint: NSLayoutConstraint!
  23. var itemModels:[Int:[SettingHomeCellModel]] {
  24. let item1 = SettingHomeCellModel(iconName: "setting_accout", title: "账号与安全", status: nil,segueIdentifier:"showInfoAndSecuritySegue")
  25. let item2 = SettingHomeCellModel(iconName: "setting_newMessage", title: "新消息通知", status: nil,segueIdentifier:"showMessageNotiSegue")
  26. let item3 = SettingHomeCellModel(iconName: "setting_common", title: "通用", status: nil,segueIdentifier:"showCommonSegue")
  27. let item4 = SettingHomeCellModel(iconName: "setting_myCRM", title: "我的客服", status: nil,segueIdentifier:"showServiceSegue")
  28. let item5 = SettingHomeCellModel(iconName: "setting_ideaback", title: "意见反馈", status: nil,segueIdentifier:"showIdeaBackSegue")
  29. let item6 = SettingHomeCellModel(iconName: "setting_about", title: "关于", status: nil,segueIdentifier:"showAboutSegue")
  30. return [0:[item1],1:[item2,item3,item4,item5],2:[item6]]
  31. }
  32. override func viewWillAppear(_ animated: Bool) {
  33. self.navigationController?.navigationBar.isHidden = true
  34. }
  35. override func viewWillDisappear(_ animated: Bool) {
  36. self.navigationController?.navigationBar.isHidden = false
  37. }
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. //更新头像之后刷新
  41. NotificationCenter.default.addObserver(self, selector: #selector(loadAvatar), name: Notification.Name("reloadMyIcon"), object: nil)
  42. if #available(iOS 11.0, *) {
  43. let topConstant = CGFloat(0 - IOS11_TOP_STATUSBAR_HEIGHT)
  44. self.SettingHeaderViewTopConstraint.constant = topConstant
  45. }
  46. self.iconImageView.layer.masksToBounds = true
  47. self.iconImageView.layer.cornerRadius = 75 / 2.0
  48. self.iconImageView.layer.borderColor = UIColor.white.cgColor
  49. self.iconImageView.layer.borderWidth = 1
  50. self.settingItemTableView.delegate = self
  51. self.settingItemTableView.dataSource = self
  52. self.loadAvatar()
  53. }
  54. override var preferredStatusBarStyle : UIStatusBarStyle {
  55. return .lightContent
  56. }
  57. func numberOfSections(in tableView: UITableView) -> Int {
  58. return itemModels.keys.count
  59. }
  60. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  61. return (itemModels[section]?.count)!
  62. }
  63. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  64. let cell = tableView.dequeueReusableCell(withIdentifier: "SettingHomeCellIdentifier", for: indexPath) as! SettingHomeCell
  65. cell.cellModel = itemModels[(indexPath as NSIndexPath).section]![(indexPath as NSIndexPath).row]
  66. return cell
  67. }
  68. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  69. let cellModel = self.itemModels[indexPath.section]?[indexPath.row]
  70. if let segue = cellModel?.segueIdentifier {
  71. if segue == "showIdeaBackSegue" {
  72. PgyManager.shared().showFeedbackView()
  73. }else{
  74. self.performSegue(withIdentifier: segue, sender: nil)
  75. }
  76. }
  77. }
  78. @IBAction func showPersonDetail(_ sender: UITapGestureRecognizer) {
  79. self.performSegue(withIdentifier: "showPersonSegue", sender: nil)
  80. }
  81. // In a storyboard-based application, you will often want to do a little preparation before navigation
  82. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  83. }
  84. @objc private func loadAvatar() {
  85. DDLogInfo("刷新头像和名字。。。。。。。。。。。。。。。。。。。。。")
  86. let me = O2AuthSDK.shared.myInfo()
  87. self.nameLabel.text = me?.name
  88. let avatarUrlString = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKeyV2, query: ContactContext.personIconByNameQueryV2, parameter: ["##name##":me?.id as AnyObject])
  89. let avatarUrl = URL(string: avatarUrlString!)
  90. self.iconImageView.hnk_setImageFromURL(avatarUrl!)
  91. }
  92. }