O2SearchResultCell.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // O2SearchResultCell.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2021/5/25.
  6. // Copyright © 2021 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. class O2SearchResultCell: UITableViewCell {
  10. @IBOutlet weak var appLabel: UILabel! // 应用名称
  11. @IBOutlet weak var titleLabel: UILabel!
  12. @IBOutlet weak var createDayLabel: UILabel!
  13. @IBOutlet weak var summaryLabel: UILabel!
  14. @IBOutlet weak var typeNameLabel: UILabel! // 栏目 还是 流程
  15. @IBOutlet weak var typeValueLabel: UILabel! // 栏目名称 流程名称
  16. @IBOutlet weak var deptNameLabel: UILabel!
  17. @IBOutlet weak var personLabel: UILabel!
  18. override func awakeFromNib() {
  19. super.awakeFromNib()
  20. // Initialization code
  21. }
  22. // 边距
  23. override var frame: CGRect {
  24. didSet {
  25. var newFrame = frame
  26. newFrame.origin.x += 10
  27. newFrame.size.width -= 20
  28. newFrame.origin.y += 10
  29. newFrame.size.height -= 20
  30. super.frame = newFrame
  31. }
  32. }
  33. override func setSelected(_ selected: Bool, animated: Bool) {
  34. super.setSelected(selected, animated: animated)
  35. // Configure the view for the selected state
  36. }
  37. func setData(data: O2SearchEntry, currentKey: String) {
  38. if data.type == "cms" {
  39. self.appLabel.text = data.appName
  40. self.typeNameLabel.text = L10n.Search.cmsCategory
  41. self.typeValueLabel.text = data.categoryName
  42. } else {
  43. self.appLabel.text = data.applicationName
  44. self.typeNameLabel.text = L10n.Search.processName
  45. self.typeValueLabel.text = data.processName
  46. }
  47. if let title = data.title, !title.isBlank {
  48. let titleAS = NSMutableAttributedString(string: title)
  49. let keyRange = NSString(string: title).range(of: currentKey)
  50. titleAS.addAttribute(.foregroundColor, value: UIColor.red, range: keyRange)
  51. self.titleLabel.attributedText = titleAS
  52. } else {
  53. self.titleLabel.text = "无标题"
  54. }
  55. let summaryAS = NSMutableAttributedString(string: data.summary ?? "")
  56. let summaryRange = NSString(string: data.summary ?? "").range(of: currentKey)
  57. summaryAS.addAttribute(.foregroundColor, value: UIColor.red, range: summaryRange)
  58. self.summaryLabel.attributedText = summaryAS
  59. self.createDayLabel.text = data.updateTime?.length ?? 0 > 10 ? data.updateTime?.subString(from: 0, to: 10) : data.updateTime
  60. if data.creatorUnit != nil {
  61. self.deptNameLabel.text = data.creatorUnit!.contains("@") ? data.creatorUnit!.split("@")[0] : data.creatorUnit
  62. } else {
  63. self.deptNameLabel.text = ""
  64. }
  65. if data.creatorPerson != nil {
  66. self.personLabel.text = data.creatorPerson!.contains("@") ? data.creatorPerson!.split("@")[0] : data.creatorPerson
  67. } else {
  68. self.personLabel.text = ""
  69. }
  70. }
  71. }