123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- //
- // TSCollectionViewVM.swift
- // AIRingtone
- //
- // Created by 100Years on 2025/2/28.
- //
- import ObjectMapper
- //MARK: TSColVVMStyple
- enum TSColVVMStyple : Int {
- case themeGuide //主题引导
- case themeContent //主题内容
-
- case posterHistory //生成海报的历史记录
- case photoHistory //生成头像的历史记录
-
- case ringCategories //铃声分类
-
- var config:TSColVVMSizeConfig {
- switch self {
- case .themeGuide:
- return themeGuideConfig
- case .themeContent:
- return themeContentConfig
- case .posterHistory:
- return posterHistoryConfig
- case .photoHistory:
- return photoHistoryConfig
- case .ringCategories:
- return ringCategoriesConfig
- }
- }
-
- var sectionInset: UIEdgeInsets {
- config.sectionInset
- }
-
- var lineSpacing: CGFloat {
- config.lineSpacing
- }
-
- var itemSpacing: CGFloat {
- config.itemSpacing
- }
- var cellSize:CGSize {
- config.cellSize
- }
-
- var cellClass: UICollectionViewCell.Type {
- config.cellClass
- }
-
- var headerViewSize:CGSize {
- config.headerViewSize
- }
-
- var headerView:UICollectionReusableView.Type {
- config.headerView
- }
- }
- //MARK: TSColVVMSectionModel
- class TSColVVMSectionModel: TSBaseModel {
-
- var style:TSColVVMStyple = .themeContent {
- didSet{
- for itemModel in items {
- itemModel.style = style
- }
- }
- }
-
- var name:String = "History"
- var items:[TSColVVMItemModel] = [TSColVVMItemModel]()
- override func mapping(map: ObjectMapper.Map) {
- style <- map["style"]
- name <- map["name"]
- items <- map["items"]
- }
- }
- extension TSColVVMSectionModel : TSCollectionViewSectionComponent{
- var sectionInset: UIEdgeInsets {
- return style.sectionInset
- }
-
- var lineSpacing: CGFloat {
- return style.lineSpacing
- }
-
- var itemSpacing: CGFloat {
- return style.itemSpacing
- }
- var headerComponent: TSCollectionViewReuseViewComponent? {
- return TSColVVMComponentReuseViewModel(sectionModel: self)
- }
-
- var cells: [TSCollectionViewCellComponent] {
- return items
- }
- }
- //MARK: TSColVVMItemModel
- class TSColVVMItemModel: TSBaseModel {
- var style:TSColVVMStyple = .themeContent
- var dataModel:TSBaseModel = TSBaseModel()
- override func mapping(map: ObjectMapper.Map) {
- dataModel <- map["dataModel"]
- style <- map["style"]
- }
- }
- extension TSColVVMItemModel: TSCollectionViewCellComponent{
- var cellClass: UICollectionViewCell.Type {
- style.cellClass
- }
-
- func cellSize(with attrubites: [String : Any]?) -> CGSize {
- style.cellSize
- }
- }
- //MARK: 分区头
- class TSColVVMComponentReuseViewModel : TSBaseModel ,TSCollectionViewReuseViewComponent {
- var sectionModel:TSColVVMSectionModel
-
- var style:TSColVVMStyple = .themeContent
- var dataModel:TSBaseModel = TSBaseModel()
-
- init(sectionModel:TSColVVMSectionModel) {
- self.sectionModel = sectionModel
- }
-
- required convenience init?(json: [String : Any]) {
- fatalError("init(json:) has not been implemented")
- }
-
- required convenience init?(map: ObjectMapper.Map) {
- fatalError("init(map:) has not been implemented")
- }
-
- override func mapping(map: ObjectMapper.Map) {
- sectionModel <- map["sectionModel"]
- }
-
- var viewClass: UICollectionReusableView.Type {
- return style.headerView
- }
-
- var reuseIdentifier: String{
- return viewClass.description()
- }
-
- var viewSize: CGSize {
- return sectionModel.style.headerViewSize
- }
-
- var viewType: TSCollectionViewReuseViewType {
- return .header
- }
- }
|