SettingViewController.swift 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 SDWebImage
  13. import CocoaLumberjack
  14. //import Flutter
  15. class SettingViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
  16. // @IBOutlet weak var settingHeaderView: SettingHeaderView!
  17. //
  18. // @IBOutlet weak var iconImageView: UIImageView!
  19. //
  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 item0 = SettingHomeCellModel(iconName: "person_avatar", title: "个人信息", status: nil,segueIdentifier:"showPersonSegue")
  25. let item1 = SettingHomeCellModel(iconName: "setting_accout", title: "账号与安全", status: nil,segueIdentifier:"showInfoAndSecuritySegue")
  26. let itemSkin = SettingHomeCellModel(iconName: "icon_skin", title: "个性换肤", status: nil,segueIdentifier:"showSkinViewSegue")
  27. let item2 = SettingHomeCellModel(iconName: "setting_newMessage", title: "新消息通知", status: nil,segueIdentifier:"showMessageNotiSegue")
  28. let item3 = SettingHomeCellModel(iconName: "setting_common", title: "通用", status: nil,segueIdentifier:"showCommonSegue")
  29. // let item4 = SettingHomeCellModel(iconName: "setting_myCRM", title: "我的客服", status: nil,segueIdentifier:"showServiceSegue")
  30. // let item5 = SettingHomeCellModel(iconName: "setting_ideaback", title: "意见反馈", status: nil,segueIdentifier:"showIdeaBackSegue")
  31. let item6 = SettingHomeCellModel(iconName: "setting_about", title: "关于", status: nil,segueIdentifier:"showAboutSegue")
  32. return [0:[item0], 1:[item1], 2:[itemSkin, item2,item3], 3:[item6]]
  33. }
  34. //
  35. // override func viewWillAppear(_ animated: Bool) {
  36. // self.navigationController?.navigationBar.isHidden = true
  37. // }
  38. //
  39. // override func viewWillDisappear(_ animated: Bool) {
  40. // self.navigationController?.navigationBar.isHidden = false
  41. // }
  42. override func viewDidLoad() {
  43. super.viewDidLoad()
  44. self.title = "设置"
  45. //更新头像之后刷新
  46. NotificationCenter.default.addObserver(self, selector: #selector(loadAvatar), name: Notification.Name("reloadMyIcon"), object: nil)
  47. // if #available(iOS 11.0, *) {
  48. // let topConstant = CGFloat(0 - IOS11_TOP_STATUSBAR_HEIGHT)
  49. // self.SettingHeaderViewTopConstraint.constant = topConstant
  50. // }
  51. // self.settingHeaderView.theme_backgroundColor = ThemeColorPicker(keyPath: "Base.base_color")
  52. self.settingItemTableView.separatorStyle = .none
  53. // self.iconImageView.layer.masksToBounds = true
  54. // self.iconImageView.layer.cornerRadius = 75 / 2.0
  55. // self.iconImageView.layer.borderColor = UIColor.white.cgColor
  56. // self.iconImageView.layer.borderWidth = 1
  57. self.settingItemTableView.delegate = self
  58. self.settingItemTableView.dataSource = self
  59. self.loadAvatar()
  60. }
  61. override var preferredStatusBarStyle : UIStatusBarStyle {
  62. return .lightContent
  63. }
  64. func numberOfSections(in tableView: UITableView) -> Int {
  65. return itemModels.keys.count
  66. }
  67. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  68. return (itemModels[section]?.count)!
  69. }
  70. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  71. if indexPath.section == 0 {
  72. return 75
  73. } else {
  74. return 50
  75. }
  76. }
  77. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  78. let cell = tableView.dequeueReusableCell(withIdentifier: "SettingHomeCellIdentifier", for: indexPath) as! SettingHomeCell
  79. // cell.cellModel = itemModels[(indexPath as NSIndexPath).section]![(indexPath as NSIndexPath).row]
  80. if indexPath.section == 0 {
  81. cell.showPersonCell() // 个人信息 特殊处理 cell
  82. } else {
  83. let m = itemModels[indexPath.section]![indexPath.row]
  84. let numberOfRows = tableView.numberOfRows(inSection: indexPath.section)
  85. if (numberOfRows > 1 && indexPath.row != numberOfRows - 1) {
  86. cell.setModel(model: m, isShowBottom: true)
  87. } else {
  88. cell.setModel(model: m, isShowBottom: false)
  89. }
  90. }
  91. return cell
  92. }
  93. /// Cell 圆角背景计算
  94. func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
  95. //圆率
  96. let cornerRadius:CGFloat = 10.0
  97. //大小
  98. let bounds:CGRect = cell.bounds
  99. //行数
  100. let numberOfRows = tableView.numberOfRows(inSection: indexPath.section)
  101. //绘制曲线
  102. var bezierPath: UIBezierPath? = nil
  103. if (indexPath.row == 0 && numberOfRows == 1) {
  104. // bounds.origin.y -= 1.0
  105. // bounds.size.height += 2.0
  106. //一个为一组时,四个角都为圆角
  107. bezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: cornerRadius, height: cornerRadius))
  108. } else if (indexPath.row == 0) {
  109. // bounds.origin.y -= 1.0
  110. //为组的第一行时,左上、右上角为圆角
  111. bezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: cornerRadius, height: cornerRadius))
  112. // bezierPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
  113. } else if (indexPath.row == numberOfRows - 1) {
  114. // bounds.size.height += 2.0
  115. //为组的最后一行,左下、右下角为圆角
  116. bezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: cornerRadius, height: cornerRadius))
  117. } else {
  118. //中间的都为矩形
  119. bezierPath = UIBezierPath(rect: bounds)
  120. }
  121. //cell的背景色透明
  122. cell.backgroundColor = .clear
  123. //新建一个图层
  124. let layer = CAShapeLayer()
  125. //图层边框路径
  126. layer.path = bezierPath?.cgPath
  127. //图层填充色,也就是cell的底色
  128. layer.fillColor = UIColor.white.cgColor
  129. //图层边框线条颜色
  130. /*
  131. 如果self.tableView.style = UITableViewStyleGrouped时,每一组的首尾都会有一根分割线,目前我还没找到去掉每组首尾分割线,保留cell分割线的办法。
  132. 所以这里取巧,用带颜色的图层边框替代分割线。
  133. 这里为了美观,最好设为和tableView的底色一致。
  134. 设为透明,好像不起作用。
  135. */
  136. layer.strokeColor = UIColor.white.cgColor
  137. //将图层添加到cell的图层中,并插到最底层
  138. cell.layer.insertSublayer(layer, at: 0)
  139. // cell.layer.mask = layer
  140. }
  141. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  142. let cellModel = self.itemModels[indexPath.section]?[indexPath.row]
  143. if let segue = cellModel?.segueIdentifier {
  144. if segue == "showIdeaBackSegue" {
  145. // PgyManager.shared().showFeedbackView()
  146. // self.testShowPicker()
  147. }else{
  148. self.performSegue(withIdentifier: segue, sender: nil)
  149. }
  150. }
  151. }
  152. @IBAction func showPersonDetail(_ sender: UITapGestureRecognizer) {
  153. self.performSegue(withIdentifier: "showPersonSegue", sender: nil)
  154. }
  155. // In a storyboard-based application, you will often want to do a little preparation before navigation
  156. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  157. }
  158. @objc private func loadAvatar() {
  159. DDLogInfo("刷新头像和名字。。。。。。。。。。。。。。。。。。。。。")
  160. // let me = O2AuthSDK.shared.myInfo()
  161. // self.nameLabel.text = me?.name
  162. // let avatarUrlString = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKeyV2, query: ContactContext.personIconByNameQueryV2, parameter: ["##name##":me?.id as AnyObject])
  163. // let avatarUrl = URL(string: avatarUrlString!)
  164. // self.iconImageView.hnk_setImageFromURL(avatarUrl!)
  165. }
  166. }