Commit 209fd132 authored by Steven杜宇's avatar Steven杜宇

// 搜索

parent 12aea708
......@@ -10,11 +10,28 @@ import UIKit
class YHSearchInfomationVC: YHBaseViewController {
var items:[String] = ["阿斯顿法师法师法师","发大水发生大法师懂法守法三大发沙发沙发沙发沙发沙发啥打法上大V撒大V啊三大发啥打法四大法守法","发大水发生大法师懂法守法三大发沙发沙发沙发沙发沙发啥打法上大V撒大V啊三大发啥打法四大法守法发大水发生大法师懂法守法三大发沙发沙发沙发沙发沙发啥打法上大V撒大V啊三大发啥打法四大法守法","啊发顺丰"]
var items:[YHHomeListModel] = []
lazy var viewModel : YHHomePageViewModel = {
let viewModel = YHHomePageViewModel()
return viewModel
}()
lazy var searchBar: YHSearchInfoBar = {
let bar = YHSearchInfoBar(frame: CGRect(x: 20, y: k_Height_NavigationtBarAndStatuBar+8.0, width: KScreenWidth-40, height: 36.0))
bar.searchBlock = {
[weak self] text in
guard let self = self else { return }
self.viewModel.searchArticleList(text ?? "") {
[weak self] success, error in
guard let self = self else { return }
items.removeAll()
if let arr = self.viewModel.arrHomeNewsData {
items.append(contentsOf: arr)
}
self.tableView.reloadData()
}
}
return bar
}()
......@@ -54,6 +71,7 @@ class YHSearchInfomationVC: YHBaseViewController {
view.addSubview(searchBar)
view.addSubview(searchHistoryView)
view.addSubview(tableView)
searchBar.textField.becomeFirstResponder()
searchBar.snp.makeConstraints { make in
make.left.equalToSuperview().offset(20)
......@@ -92,7 +110,7 @@ extension YHSearchInfomationVC: UITableViewDelegate, UITableViewDataSource {
if 0 <= indexPath.section && indexPath.section < items.count {
let item = items[indexPath.section]
cell.titleLabel.text = items[indexPath.section]
cell.updateModel(item)
}
return cell
}
......@@ -104,7 +122,7 @@ extension YHSearchInfomationVC: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if 0 <= indexPath.section && indexPath.section < items.count {
let text = items[indexPath.section]
let articleInfo = items[indexPath.section]
self.tableView.isHidden = true
self.searchHistoryView.isHidden = false
}
......
......@@ -7,8 +7,7 @@
//
import UIKit
import Kingfisher
class YHSearchInfoCell: UITableViewCell {
......@@ -41,6 +40,13 @@ class YHSearchInfoCell: UITableViewCell {
return label
}()
func updateModel(_ model: YHHomeListModel) {
titleLabel.text = model.title
if let url = URL(string: model.img_url) {
headImgView.kf.setImage(with: url)
}
}
func setupUI() {
contentView.backgroundColor = .white
......
......@@ -14,7 +14,7 @@ class YHHomePageViewModel : YHBaseViewModel {
var arrHomeNewsData: [YHHomeListModel]?
var banners: [YHBannerModel]?
var classify: [YHHomeClassifyModel]?
var hkList: [YHHKEventModel]?
//首页相关参数
private var curPageIndex : Int = 1
private var page_Size : Int = 10
......@@ -152,7 +152,7 @@ extension YHHomePageViewModel {
"page_size": 10,
"classify_id": classifyID]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Common.article
let _ = YHNetRequest.getRequest(url: strUrl, params: params) { [weak self] json, code in
let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
guard let self = self else { return }
//1. json字符串 转 对象
if json.code == 200 {
......@@ -178,18 +178,26 @@ extension YHHomePageViewModel {
}
}
func getHKEvent(callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Common.hklist
func searchArticleList(_ title: String, callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
let params: [String : Any] = ["page": 1,
"page_size": 10,
"title": title]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Common.article
let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
guard let self = self else { return }
//1. json字符串 转 对象
if json.code == 200 {
let dic = json.data
guard let result = [YHHKEventModel].deserialize(from: dic as? [Any]) else {
guard let result = YHHomeListTotalModel.deserialize(from: dic as? Dictionary) else {
self.arrHomeNewsData = []
callBackBlock(false,nil)
return
}
self.hkList = (result as! [YHHKEventModel])
for item in result.data {
item.calHeightParam()
}
self.arrHomeNewsData = result.data
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
......
......@@ -10,7 +10,7 @@ import UIKit
class YHMyNotifySettingVC: YHBaseViewController {
var items:[YHPermissionItem] = [YHPermissionItem(title: "接收推送消息通知".local, enableStatus: false)]
var items:[YHPermissionItem] = [YHPermissionItem(title: "接收推送消息通知".local, type:.notify, enableStatus: false)]
lazy var tableView: UITableView = {
let tableView = UITableView(frame:.zero, style:.grouped)
......
......@@ -8,22 +8,34 @@
import UIKit
enum YHPermissionType: Int {
case none = 0
case network = 1
case photo = 2
case camera = 3
case location = 4
case file = 5
case notify = 6
}
class YHPermissionItem {
var type: YHPermissionType = .none
var title:String = ""
var enableStatus:Bool = false
init(title: String, enableStatus: Bool) {
init(title: String, type:YHPermissionType, enableStatus: Bool) {
self.title = title
self.type = type
self.enableStatus = enableStatus
}
}
class YHMyPermissionSettingVC: YHBaseViewController {
var items:[YHPermissionItem] = [YHPermissionItem(title: "网络".local, enableStatus: true),
YHPermissionItem(title: "照片".local, enableStatus: true),
YHPermissionItem(title: "相机".local, enableStatus: false),
YHPermissionItem(title: "位置".local, enableStatus: true),
YHPermissionItem(title: "文件".local, enableStatus: false)]
var items:[YHPermissionItem] = [YHPermissionItem(title: "网络".local, type:.network, enableStatus: true),
YHPermissionItem(title: "照片".local, type:.photo, enableStatus: true),
YHPermissionItem(title: "相机".local, type:.camera, enableStatus: false),
YHPermissionItem(title: "位置".local, type:.location, enableStatus: true),
YHPermissionItem(title: "文件".local, type:.file, enableStatus: false)]
lazy var tableView: UITableView = {
let tableView = UITableView(frame:.zero, style:.grouped)
......@@ -76,7 +88,28 @@ extension YHMyPermissionSettingVC: UITableViewDelegate, UITableViewDataSource {
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if 0 <= indexPath.row && indexPath.row < items.count {
let item = items[indexPath.row]
if item.type == .photo || item.type == .camera {
let url = URL(string: UIApplication.openSettingsURLString)
if let url = url, UIApplication .shared.canOpenURL(url) {
UIApplication .shared.open(url, options: [:], completionHandler: {
(success) in
})
}
return
}
if item.type == .location {
if let url = URL(string: "App-prefs:Photos") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
} else if item.type == .file {
}
}
}
private func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> CGFloat {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment