SettingViewController.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 Flutter
  16. class SettingViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
  17. @IBOutlet weak var settingHeaderView: SettingHeaderView!
  18. @IBOutlet weak var iconImageView: UIImageView!
  19. @IBOutlet weak var nameLabel: UILabel!
  20. @IBOutlet weak var settingItemTableView: UITableView!
  21. @IBOutlet weak var SettingHeaderViewTopConstraint: NSLayoutConstraint!
  22. var itemModels:[Int:[SettingHomeCellModel]] {
  23. let item1 = SettingHomeCellModel(iconName: "setting_accout", title: "账号与安全", status: nil,segueIdentifier:"showInfoAndSecuritySegue")
  24. let itemSkin = SettingHomeCellModel(iconName: "icon_skin", title: "个性换肤", status: nil,segueIdentifier:"showSkinViewSegue")
  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:[itemSkin, item2,item3],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.settingHeaderView.theme_backgroundColor = ThemeColorPicker(keyPath: "Base.base_color")
  47. self.iconImageView.layer.masksToBounds = true
  48. self.iconImageView.layer.cornerRadius = 75 / 2.0
  49. self.iconImageView.layer.borderColor = UIColor.white.cgColor
  50. self.iconImageView.layer.borderWidth = 1
  51. self.settingItemTableView.delegate = self
  52. self.settingItemTableView.dataSource = self
  53. self.loadAvatar()
  54. }
  55. override var preferredStatusBarStyle : UIStatusBarStyle {
  56. return .lightContent
  57. }
  58. func numberOfSections(in tableView: UITableView) -> Int {
  59. return itemModels.keys.count
  60. }
  61. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  62. return (itemModels[section]?.count)!
  63. }
  64. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  65. let cell = tableView.dequeueReusableCell(withIdentifier: "SettingHomeCellIdentifier", for: indexPath) as! SettingHomeCell
  66. cell.cellModel = itemModels[(indexPath as NSIndexPath).section]![(indexPath as NSIndexPath).row]
  67. return cell
  68. }
  69. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  70. let cellModel = self.itemModels[indexPath.section]?[indexPath.row]
  71. if let segue = cellModel?.segueIdentifier {
  72. if segue == "showIdeaBackSegue" {
  73. // PgyManager.shared().showFeedbackView()
  74. // self.testShowPicker()
  75. }else{
  76. self.performSegue(withIdentifier: segue, sender: nil)
  77. }
  78. }
  79. }
  80. @IBAction func showPersonDetail(_ sender: UITapGestureRecognizer) {
  81. self.performSegue(withIdentifier: "showPersonSegue", sender: nil)
  82. }
  83. // In a storyboard-based application, you will often want to do a little preparation before navigation
  84. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  85. }
  86. @objc private func loadAvatar() {
  87. DDLogInfo("刷新头像和名字。。。。。。。。。。。。。。。。。。。。。")
  88. let me = O2AuthSDK.shared.myInfo()
  89. self.nameLabel.text = me?.name
  90. let avatarUrlString = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKeyV2, query: ContactContext.personIconByNameQueryV2, parameter: ["##name##":me?.id as AnyObject])
  91. let avatarUrl = URL(string: avatarUrlString!)
  92. self.iconImageView.hnk_setImageFromURL(avatarUrl!)
  93. }
  94. }