CNLiveHomePageViewModel.swift
6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// CNLiveHomePageViewModel.swift
// metaCode
//
// Created by zx on 2024/1/8.
//
import Foundation
import CNLiveRequestBastKit
class CNLiveHomePageViewModel:NSObject{
/// 获取首页原生页面数据
static func requestGetHomePageConfigList( resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/commonApi/homePageConfigList", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic, CNLiveHomePageModel.self)
resultBlock(dataMdl,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页我的专辑收藏数据
static func requestGetHomePageMyAlbum(page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("\(page)", forKey: "page")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/myAlbum", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataArr = resp["data"] as! Array<Any>
var resArr = []
if dataArr.count > 0{
//有在追短剧
for dataDic in dataArr {
let dataMdl = newDictionaryToModel(dataDic as! [String : Any], CNLiveAlbumMsgModel.self)
resArr.append(dataMdl)
}
}else{
//没有在追短剧
}
resultBlock(resArr,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页-全部专辑列表
static func getBlockContents(blockId:String,page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(blockId, forKey: "blockId")
param.setValue("\(page)", forKey: "page")
// param.setValue("10", forKey: "pageSize")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getBlockContents", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataList = dataDic["list"] as! Array<Any>
var listArr = Array<Any>()
for listDic in dataList{
let dataMdl = newDictionaryToModel(listDic as! [String : Any], CNLiveAlbumModel.self)
listArr.append(dataMdl)
}
resultBlock(listArr,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页-专辑详情简介
static func getAlbumMsg(aid:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getAlbumMsg", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic, CNLiveAlbumMsgModel.self)
resultBlock(dataMdl,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页-专辑视频列表详情
static func getAlbumList(aid:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/ugcApi/albumList", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataList = dataDic["list"] as! Array<Any>
var listArr = Array<Any>()
for listDic in dataList{
let dataMdl = newDictionaryToModel(listDic as! [String : Any], CNLiveAlbumListModel.self)
listArr.append(dataMdl)
}
resultBlock(listArr,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
}