CNLiveDownSlideViewModel.swift
3.66 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
//
// CNLiveDownSlideViewModel.swift
// metaCode
//
// Created by zx on 2023/10/19.
//
import Foundation
import CNLiveRequestBastKit
enum CNLiveDownSlideResponseType {
case success
case failed
case noNetwork
case unkonw
}
typealias downSlideResultBlock = (_ result: Any,_ status:CNLiveDownSlideResponseType) -> Void
class CNLiveDownSlideViewModel:NSObject{
/// 获取下滑页原生页面数据
/// - Parameters:
/// - userId: 用户ID
/// - pageId: 页面ID
static func requestGetPage(pageId:NSString, resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "userId")
param.setValue(pageId, forKey: "pageId")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getPage", 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 downSlideModelArr = resp["data"] as! NSArray
var modelArray:[BaseModel] = []
for downSlideDic in downSlideModelArr {
let downSlideModel = newDictionaryToModel(downSlideDic as! [String : Any], CNLiveDownSlideModel.self)
modelArray.append(downSlideModel)
}
resultBlock(modelArray,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取下滑页-幼教原生页面-我的课程数据
static func getYjzgMyCurriculum(page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("\(page)", forKey: "page")
// param.setValue("10", forKey: "pageSize")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/yjzgMyCurriculum", 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 , CNLiveAlbumBaseModel.self)
resultBlock(dataMdl,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
}