CNLiveHomeSearchViewModel.swift
4.06 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
//
// CNLiveHomeSearchViewModel.swift
// metaCode
//
// Created by zx on 2025/3/8.
//
import Foundation
import CNLiveRequestBastKit
import CNLiveBusinessTools
class CNLiveHomeSearchViewModel:NSObject,URLSessionTaskDelegate{
static let shared = CNLiveHomeSearchViewModel()
//搜索热点列表 contentApi/getHotList 参数type=3
static func getSearchHotListApi(resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue("3", forKey: "type")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getHotList", 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], CNLiveHomeSearchHotModel.self)
resArr.append(dataMdl)
}
}else{
//没有
resultBlock(NSNull(),.failed)
}
resultBlock(resArr,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
//搜索结果 搜索:contentApi/search 参数:modelId(专辑搜索:album,单集搜索:1)、keyword、siteId = 113、page、pageSize
static func getSearchResultApi(modelId:String,keyword:String,page:String,pageSize:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(modelId, forKey: "modelId")
param.setValue(keyword, forKey: "keyword")
param.setValue("113", forKey: "siteId")
param.setValue(page, forKey: "page")
param.setValue(pageSize, forKey: "pageSize")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/search", 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") {
if resp["data"] is NSNull {
resultBlock(NSNull(), .failed)
} else {
let listModel = dictionaryToModel(resp["data"] as! [String : Any], CNLiveHomeSearchResultListBaseModel.self,"") as! CNLiveHomeSearchResultListBaseModel
resultBlock(listModel, .success)
}
} else {
showMessage(message: resp["errorMessage"] as! String)
resultBlock(NSNull(),.failed)
}
}else{
resultBlock(NSNull(),.failed)
}
}
}
}