SBTLeftMenuVCtr.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // SBTLeftMenuVCtr.swift
  3. // SolarBT
  4. //
  5. // Created by weclouds on 2019/4/22.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import PPNetworkHelper
  10. import AFNetworking
  11. import GYSide
  12. class SBTLeftMenuVCtr: UIViewController {
  13. var tempCell : TempSwitchCell?
  14. lazy var tableView: UITableView = {
  15. let tableView = UITableView(frame: CGRect(x: 0, y: 44-KNavBarHeight , width: KSCREENWIDTH / 2, height: KSCREENHEIGHT + KNavBarHeight - 44 ), style: .plain)
  16. // tableView.backgroundColor = UIColor(hexString: "F8F8F8")
  17. tableView.delegate = self
  18. tableView.dataSource = self
  19. tableView.register(UINib(nibName: "SBTHomeCell", bundle: nil), forCellReuseIdentifier: "cell")
  20. return tableView
  21. }()
  22. override func viewDidLoad() {
  23. super.viewDidLoad()
  24. createUI()
  25. checkTheBlueToothWasActivity()
  26. }
  27. }
  28. extension SBTLeftMenuVCtr {
  29. func createUI(){
  30. view.addSubview(self.tableView)
  31. tableView.separatorStyle = .none
  32. tableView.register(VersionCell.self, forCellReuseIdentifier: "version")
  33. tableView.register(LeftItemCell.self, forCellReuseIdentifier: "item")
  34. tableView.register(TempSwitchCell.self, forCellReuseIdentifier: "tempswitch")
  35. }
  36. }
  37. extension SBTLeftMenuVCtr : UITableViewDelegate,UITableViewDataSource{
  38. func numberOfSections(in tableView: UITableView) -> Int {
  39. return 1
  40. }
  41. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  42. return 6
  43. }
  44. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  45. return 50
  46. }
  47. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  48. return 184
  49. }
  50. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  51. let header = UIImageView(frame: CGRect(x: 0, y: 0, width: KSCREENWIDTH / 2 , height: 184))
  52. header.image = UIImage(named: "侧滑背景图")
  53. let iconImageV = UIImageView(image: UIImage(named: "headerIcon"))
  54. header.addSubview(iconImageV)
  55. iconImageV.layer.masksToBounds = true
  56. iconImageV.layer.cornerRadius = 30
  57. iconImageV.layer.borderColor = UIColor.white.cgColor
  58. iconImageV.layer.borderWidth = 1
  59. iconImageV.snp.makeConstraints { (make) in
  60. make.center.equalToSuperview()
  61. make.width.height.equalTo(60)
  62. }
  63. let versionLabel = UILabel()
  64. let infoDictionary = Bundle.main.infoDictionary
  65. let majorVersion :String? = (infoDictionary! ["CFBundleShortVersionString"] as! String)//主程序版本号
  66. versionLabel.text = "V" + majorVersion!
  67. versionLabel.textColor = UIColor.white
  68. versionLabel.font = UIFont(name: PingFangSC_Semibold, size: 19)
  69. header.addSubview(versionLabel)
  70. versionLabel.snp.makeConstraints { (make) in
  71. make.centerX.equalToSuperview()
  72. make.bottom.equalToSuperview().offset(-20)
  73. }
  74. return header
  75. }
  76. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  77. if indexPath.row == 0 {
  78. let cell = tableView.dequeueReusableCell(withIdentifier: "tempswitch") as! TempSwitchCell
  79. let userDef = UserDefaults.standard
  80. let isCentigrade = userDef.value(forKey: TEMPISCENTIGRADE) as? String
  81. if isCentigrade != nil{
  82. if isCentigrade == "1"{
  83. cell.isCentigrade = true
  84. }else if isCentigrade == "0"{
  85. cell.isCentigrade = false
  86. }
  87. }else{
  88. cell.isCentigrade = true
  89. }
  90. cell.selectionStyle = .none
  91. self.tempCell = cell
  92. return cell
  93. }else if indexPath.row == 2{
  94. let cell = tableView.dequeueReusableCell(withIdentifier: "version") as! VersionCell
  95. cell.selectionStyle = .none
  96. return cell
  97. }else {
  98. let cell = tableView.dequeueReusableCell(withIdentifier: "item") as! LeftItemCell
  99. if indexPath.row == 4 {
  100. cell.titleLabel.text = "Privacy_Policy".da_localizedStr()
  101. }else if (indexPath.row == 1){
  102. cell.titleLabel.text = "Client_language".da_localizedStr()
  103. }else if indexPath.row == 3{
  104. cell.titleLabel.text = "Customer_feedback".da_localizedStr()
  105. }else if indexPath.row == 5 {
  106. cell.titleLabel.text = "Simulation_experience".da_localizedStr()
  107. }
  108. cell.selectionStyle = .none
  109. return cell
  110. }
  111. }
  112. /*
  113. 温度转换 0
  114. 客户端语言 1
  115. 客户版本 2
  116. 用户反馈 3
  117. 演示设备 4
  118. */
  119. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  120. if indexPath.row == 0 {
  121. self.tempCell?.isCentigrade = !self.tempCell!.isCentigrade!
  122. if self.tempCell?.isCentigrade == true{
  123. let userdef = UserDefaults.standard
  124. userdef.set("1", forKey: TEMPISCENTIGRADE)
  125. }else{// 华氏度
  126. let userdef = UserDefaults.standard
  127. userdef.set("0", forKey: TEMPISCENTIGRADE)
  128. }
  129. }else if indexPath.row == 1 {
  130. // self.gy_sidePushViewController(viewController: SBTLanguageVCtr())
  131. self.cw_push(SBTLanguageVCtr())
  132. }else if indexPath.row == 2 {
  133. }else if indexPath.row == 3 {
  134. // self.gy_sidePushViewController(viewController: SBTFeedbackVCtr())
  135. self.cw_push(SBTFeedbackVCtr())
  136. }else if indexPath.row == 4{
  137. let vc = SBTPrivacyPolicyVCtr()
  138. self.cw_push(vc)
  139. //self.gy_sidePushViewController(viewController: vc)
  140. }else{
  141. let vc = SBTDeviceDetaiVCtr()
  142. vc.isDemo = true
  143. // self.gy_sidePushViewController(viewController: vc)
  144. self.cw_push(vc)
  145. }
  146. }
  147. func createBody2(_ dict : [String : String])-> Data{
  148. var body = Data()
  149. //添加参数数据
  150. for (key,value) in dict {
  151. body.append("Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n")
  152. body.append("\(value)\r\n")
  153. }
  154. return body
  155. }
  156. func createBody1(_ dict : [String : [Data]])-> Data{
  157. var body = Data()
  158. //添加参数数据
  159. for (key,value) in dict {
  160. body.append("Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n")
  161. // for data in value{
  162. // body.append("\(data)\r\n")
  163. // }
  164. body.append("\(value)\r\n")
  165. }
  166. return body
  167. }
  168. }