Commit f05205a4 authored by David黄金龙's avatar David黄金龙

1、处理 首页的数据刷新

2、处理 数据一致性
parent 7c051f73
......@@ -41,7 +41,6 @@ class YHHomePageViewController: YHBaseViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
loadFirstData()
}
lazy var searchView: YHHomeSearchView = {
......@@ -104,7 +103,7 @@ private extension YHHomePageViewController {
gk_navigationBar.isHidden = true
view.backgroundColor = .white
NotificationCenter.default.addObserver(self, selector: #selector(homepageRefresh), name:YhConstant.YhNotification.refreshHomePageNotifiction, object: nil)
// NotificationCenter.default.addObserver(self, selector: #selector(homepageRefresh), name:YhConstant.YhNotification.refreshHomePageNotifiction, object: nil)
view.addSubview(searchView)
searchView.snp.makeConstraints { make in
......@@ -160,6 +159,18 @@ extension YHHomePageViewController: UICollectionViewDelegate, UICollectionViewDa
let vc = YHHomeWebViewController()
vc.url = YHConfigManager.shared.h5Url + "?id=\(model.id)"
vc.id = model.id
vc.block = { item in
if let arr = self.viewModel.arrHomeNewsData {
for (index,targetItem) in arr.enumerated() {
if targetItem.id == item.id {
targetItem.is_like = item.is_like
targetItem.like_count = item.like_count
self.homeCollectView.reloadItems(at: [IndexPath(index: index)])
}
}
}
}
self.navigationController?.pushViewController(vc)
} else if model.type == 1 {
printLog("直接播放视频")
......
......@@ -10,8 +10,14 @@ import UIKit
import WebKit
class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationDelegate {
var viewModel: YHHomeWebViewModel!
var operationFlag:Bool = false
typealias Block = (YHWebModel) -> ()
var block: Block?
var viewModel: YHHomeWebViewModel!
var webview = WKWebView()
var progBar = UIProgressView()
var bottomView: YHHomeWebBottomView!
......@@ -60,16 +66,22 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD
self.viewModel.getLike(self.id, 1) {[weak self] success, error in
guard let self = self else { return }
if success {
operationFlag = true
YHHUD.flash(message: "已点赞")
self.getData()
} else {
operationFlag = false
}
}
} else {
self.viewModel.getLike(self.id, 0) {[weak self] success, error in
guard let self = self else { return }
if success {
operationFlag = true
YHHUD.flash(message: "已取消点赞")
self.getData()
} else {
operationFlag = false
}
}
}
......@@ -87,16 +99,22 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD
self.viewModel.getStar(self.id, 1) {[weak self] success, error in
guard let self = self else { return }
if success {
operationFlag = true
YHHUD.flash(message: "已收藏")
self.getData()
} else {
operationFlag = false
}
}
} else {
self.viewModel.getStar(self.id, 0) {[weak self] success, error in
guard let self = self else { return }
if success {
operationFlag = true
YHHUD.flash(message: "已取消收藏")
self.getData()
} else {
operationFlag = false
}
}
}
......@@ -132,11 +150,15 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD
func getData() {
viewModel.getWebDetail(self.id) {[weak self] success, error in
guard let self = self else { return }
if success {
guard let model = self.viewModel.mainModel else { return }
bottomView.likeCount = model.like_count
bottomView.starCount = model.collect_count
bottomView.isStar = model.is_collect
bottomView.isLike = model.is_like
self.block?(model)
}
}
}
......
......@@ -18,12 +18,12 @@ class YHHomeListModel: YHBaseModel {
var id: Int = 0
var title: String = ""
var content: String = ""
var view_count: Int = 0
var view_count: Int = 0 //浏览数量
var img_url: String = ""
var type: Int = 0 //文章类型 '文章类型 1视频 2图文 3图片',
var is_like : Bool = false
var media_url : String = ""
var like_count : Int = 0
var like_count : Int = 0 //点赞梳理
......
......@@ -200,6 +200,7 @@ extension YHHomeCollectionViewCell {
if success {
YHHUD.flash(message: "已点赞")
listModel.is_like = true
listModel.like_count = listModel.like_count + 1
updataSubViews()
}
}
......@@ -209,12 +210,11 @@ extension YHHomeCollectionViewCell {
if success {
YHHUD.flash(message: "已取消点赞")
listModel.is_like = false
listModel.like_count = listModel.like_count - 1
updataSubViews()
}
}
}
NotificationCenter.default.post(name:YhConstant.YhNotification.refreshHomePageNotifiction, object: nil)
} else {
let vc = UINavigationController(rootVC: YHPhoneLoginViewController())
vc.modalPresentationStyle = .custom
......
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