KMAdvertisementModel.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // KMAdvertisementModel.swift
  3. // KMAdvertisement
  4. //
  5. // Created by lizhe on 2022/11/30.
  6. //
  7. //参考链接 https://www.jianshu.com/p/a24cf8f37860
  8. //func encode<T>(of model: T) throws where T: Codable {
  9. // let encoder = JSONEncoder()
  10. // encoder.outputFormatting = .prettyPrinted
  11. // let encodedData = try encoder.encode(model)
  12. // print(String(data: encodedData, encoding: .utf8)!)
  13. //}
  14. //func decode<T>(of jsonString: String, type: T.Type) throws -> T where T: Codable {
  15. // let data = jsonString.data(using: .utf8)!
  16. // let decoder = JSONDecoder()
  17. // let model = try! decoder.decode(T.self, from: data)
  18. // return model
  19. //}
  20. /**
  21. */
  22. @objcMembers public class KMAdvertisementModel: NSObject, Codable {
  23. public var appName: KMAdvertisementAppNameType = .FilmageEditorMac //产品名
  24. public var platform: KMAdvertisementPlatformType = .Mac //平台
  25. public var showType: KMAdvertisementShowType = .view //显示类型
  26. public let startTime: String? //开始时间 时间戳
  27. public let endTime: String? //结束时间 时间戳
  28. public let version: String? //小于等于此版本生效
  29. public let hidden: Bool? //是否显示
  30. let subscribeType: KMAdvertisementSubscribeType? //是否订阅
  31. public var content: [KMAdvertisementModelSection]?
  32. }
  33. @objcMembers public class KMAdvertisementModelSection: NSObject, Codable {
  34. public let sectionTitle: KMAdvertisementModelItem.Text?
  35. public var content: [KMAdvertisementModelItem]?
  36. }
  37. @objcMembers public class KMAdvertisementModelItem: NSObject, Codable {
  38. public var productID: String?
  39. public let startTime: String? //开始时间 时间戳
  40. public let endTime: String? //结束时间 时间戳
  41. public var hidden: Bool?
  42. public var index: Int?
  43. public let title: Text?
  44. public let imageURL: Image?
  45. public let ipadImageURL: Image?
  46. public let linkURL: Language?
  47. public let tips: Language?
  48. public let button: Text?
  49. public var actionType: KMAdvertisementActionType = .URL
  50. public struct Text: Codable {
  51. public let font: Font?
  52. public let color: Color?
  53. public let background: Background?
  54. public let language: Language?
  55. }
  56. public struct Font: Codable {
  57. public let name: String?
  58. public let size: Int?
  59. }
  60. public struct Color: Codable {
  61. let height: ColorState?
  62. let normal: ColorState?
  63. struct ColorState: Codable {
  64. public let dark: ColorInfo?
  65. public let universal: ColorInfo?
  66. struct ColorInfo: Codable {
  67. public var hex: String?
  68. public var alpha: Float?
  69. }
  70. }
  71. }
  72. public struct Background: Codable {
  73. let color: Color?
  74. let layer: Layer?
  75. struct Layer: Codable {
  76. public let cornerRadius: CGFloat?
  77. public let borderWidth: CGFloat?
  78. public let borderColor: Color?
  79. }
  80. }
  81. public struct Image: Codable {
  82. public let height: ImageInfo?
  83. public let normal: ImageInfo?
  84. public let background: Background?
  85. }
  86. public struct ImageInfo: Codable {
  87. public let dark: Language?
  88. public let universal: Language?
  89. }
  90. public class Language: NSObject, Codable {
  91. public let en: String?
  92. public let zh_TW: String?
  93. public let zh_CN: String?
  94. }
  95. }