DeviceTableViewCell.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // DeviceTableViewCell.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/5/7.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. class DeviceTableViewCell: UITableViewCell {
  11. var unbindClickDelegate: DeviceUnbindBtnClickListener?
  12. @IBOutlet weak var deviceTitle: UILabel!
  13. @IBOutlet weak var deviceUnbindBtn: UIButton!
  14. @IBAction func unbindClickAction(_ sender: UIButton) {
  15. guard let d = deviceData else {
  16. return
  17. }
  18. DDLogDebug("点击了 \(d.deviceType)")
  19. unbindClickDelegate?.onClick(device: d)
  20. }
  21. var deviceData: O2BindDeviceModel? {
  22. didSet {
  23. if deviceData?.deviceType == nil || deviceData!.deviceType.isBlank {
  24. self.deviceTitle.text = "未知设备"
  25. }else {
  26. self.deviceTitle.text = deviceData!.deviceType + " 设备"
  27. }
  28. let token = O2AuthSDK.shared.bindDevice()?.name
  29. DDLogDebug("本机token:\(token ?? "")")
  30. if token != nil && token == deviceData?.name {
  31. self.deviceUnbindBtn.setTitle("本机", for: .normal)
  32. self.deviceUnbindBtn.setTitle("本机", for: .disabled)
  33. self.deviceUnbindBtn.isEnabled = false
  34. }else {
  35. self.deviceUnbindBtn.setTitle("解除绑定", for: .normal)
  36. }
  37. }
  38. }
  39. override func awakeFromNib() {
  40. super.awakeFromNib()
  41. }
  42. override func setSelected(_ selected: Bool, animated: Bool) {
  43. super.setSelected(selected, animated: animated)
  44. }
  45. }