Veloria/Veloria/Class/Home/ViewModel/VPHomeViewModel.swift

89 lines
2.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// VPHomeViewModel.swift
// Veloria
//
// Created by Veloria on 2025/5/20.
//
import UIKit
class VPHomeViewModel: VPModel {
/// 使
var oldModuleList: [VPHomeModuleItem]? {
didSet {
filterModuleData()
}
}
///
private(set) lazy var newModuleList: [VPHomeModuleItem] = []
///
var needUpdateCategory = true
///
private(set) lazy var categoryList: [VPCategoryModel] = []
private(set) lazy var categoryTitleList: [String] = []
var rawCategoryList: [VPCategoryModel] = [] {
didSet {
let allCategory = VPCategoryModel()
allCategory.name = "All".localized
allCategory.id = "0"
categoryList.removeAll()
categoryTitleList.removeAll()
categoryList.append(allCategory)
categoryList += rawCategoryList
categoryList.forEach { model in
categoryTitleList.append(model.name ?? "")
}
}
}
///
private(set) lazy var marqueeArr: [VPShortModel] = []
///
private func filterModuleData() {
newModuleList.removeAll()
oldModuleList?.forEach({
if let key = $0.module_key {
if key == .banner {
newModuleList.insert($0, at: 0)
}
/* else if key == .category_navigation { //
if needUpdateCategory {
categoryList.removeAll()
categoryTitleList.removeAll()
let allCategory = VPCategoryModel()
allCategory.name = "All".localized
allCategory.id = "0"
categoryList.append(allCategory)
categoryList += ($0.categoryList ?? [])
categoryList.forEach { model in
categoryTitleList.append(model.name ?? "")
}
}
}*/
else if key == .marquee { //
marqueeArr = $0.list ?? []
} else {
newModuleList.append($0)
}
}
})
}
}