Commit 4b03ddaf authored by Steven杜宇's avatar Steven杜宇

// 搜索

parent 7c051f73
......@@ -10,6 +10,7 @@
0414BDA92BC7E81500225367 /* YHMyPermissionSettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0414BDA82BC7E81500225367 /* YHMyPermissionSettingVC.swift */; };
0414BDAB2BC7E9C200225367 /* YHMyPermissionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0414BDAA2BC7E9C200225367 /* YHMyPermissionCell.swift */; };
0414BDAD2BC7F02C00225367 /* YHMyNotifySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0414BDAC2BC7F02C00225367 /* YHMyNotifySettingVC.swift */; };
0414BDB22BCCC0A500225367 /* YHCollectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0414BDB12BCCC0A500225367 /* YHCollectionModel.swift */; };
041B52872B5657B3007EBCEB /* IMAppKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041B52862B5657B3007EBCEB /* IMAppKey.swift */; };
0425E63D2BA9345200A5E763 /* YHSchemeTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0425E63C2BA9345200A5E763 /* YHSchemeTableViewCell.swift */; };
0425E6402BA9357D00A5E763 /* YHScemeItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0425E63F2BA9357D00A5E763 /* YHScemeItemModel.swift */; };
......@@ -450,6 +451,7 @@
0414BDA82BC7E81500225367 /* YHMyPermissionSettingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMyPermissionSettingVC.swift; sourceTree = "<group>"; };
0414BDAA2BC7E9C200225367 /* YHMyPermissionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMyPermissionCell.swift; sourceTree = "<group>"; };
0414BDAC2BC7F02C00225367 /* YHMyNotifySettingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMyNotifySettingVC.swift; sourceTree = "<group>"; };
0414BDB12BCCC0A500225367 /* YHCollectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCollectionModel.swift; sourceTree = "<group>"; };
041B52862B5657B3007EBCEB /* IMAppKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IMAppKey.swift; sourceTree = "<group>"; };
0425E63C2BA9345200A5E763 /* YHSchemeTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSchemeTableViewCell.swift; sourceTree = "<group>"; };
0425E63F2BA9357D00A5E763 /* YHScemeItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHScemeItemModel.swift; sourceTree = "<group>"; };
......@@ -893,6 +895,14 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
0414BDB02BCCC09000225367 /* Model */ = {
isa = PBXGroup;
children = (
0414BDB12BCCC0A500225367 /* YHCollectionModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
041B52852B565798007EBCEB /* IM */ = {
isa = PBXGroup;
children = (
......@@ -1924,6 +1934,7 @@
A5ACE8E72B4564F7002C94D2 /* Mine(我的) */ = {
isa = PBXGroup;
children = (
0414BDB02BCCC09000225367 /* Model */,
048B2A4B2BC7DACF00A93BF0 /* ViewModel */,
A5ACE8EB2B4564F7002C94D2 /* V */,
A5ACE8E92B4564F7002C94D2 /* C */,
......@@ -2719,6 +2730,7 @@
04A7BD132BA42F4200BD35A2 /* YHMyDocumentsDetailViewController.swift in Sources */,
04A671622BA058DE00C1FB91 /* YHCertificateEditSheetView.swift in Sources */,
A5ACE9432B4564F7002C94D2 /* UILable+Extension.swift in Sources */,
0414BDB22BCCC0A500225367 /* YHCollectionModel.swift in Sources */,
A53D38202BC243F1006AE6F7 /* YHStartPageViewController.swift in Sources */,
045EEE882B9F171A0022A143 /* YHPreviewAcademicAndProfessionalQualificationViewController.swift in Sources */,
0435FA7F2BA178C100024EAE /* YHCommonAlertView.swift in Sources */,
......
......@@ -12,6 +12,7 @@ class YHSearchInfomationVC: YHBaseViewController {
static let searchInfoHistoryKey = "searchInfoHistoryKey"
static let searchHistoryMaxCount = 10
var searchStr = ""
var items:[YHHomeListModel] = []
lazy var viewModel: YHHomePageViewModel = {
......@@ -39,9 +40,16 @@ class YHSearchInfomationVC: YHBaseViewController {
bar.searchBlock = {
[weak self] text in
guard let self = self else { return }
searchText(self.searchBar.textField.text ?? "")
if let searchText = self.searchBar.textField.text, searchText.count > 0 {
self.saveSearchHistory(searchText)
searchStr = self.searchBar.textField.text ?? ""
searchStr = searchStr.trimmingCharacters(in: .whitespaces)
if isEmptyString(searchStr) {
searchStr = "香港身份"
self.searchBar.textField.text = "香港身份"
}
searchText(searchStr)
if searchStr.count > 0 {
self.saveSearchHistory(searchStr)
}
}
bar.textChange = {
......@@ -161,7 +169,9 @@ class YHSearchInfomationVC: YHBaseViewController {
func searchText(_ text:String) {
YHHUD.show(.progress(message: "搜索中..."))
self.viewModel.searchArticleList(text) {
// 去除两端的空格
let targetText = text.trimmingCharacters(in: .whitespaces)
self.viewModel.searchArticleList(targetText) {
[weak self] success, error in
YHHUD.hide()
guard let self = self else { return }
......@@ -187,10 +197,13 @@ class YHSearchInfomationVC: YHBaseViewController {
if isEmptyString(text) { return }
var arr = getSearchHistoryList()
// 去除两端的空格
let targetText = text.trimmingCharacters(in: .whitespaces)
// 查找历史记录中是否有相同记录
var targetIndex = -1
for (index, history) in arr.enumerated() {
if history == text {
if history == targetText {
targetIndex = index
break
}
......@@ -202,9 +215,9 @@ class YHSearchInfomationVC: YHBaseViewController {
// 将最近记录放在第一位
if arr.count < Self.searchHistoryMaxCount {
arr.insert(text, at: 0)
arr.insert(targetText, at: 0)
} else {
arr.insert(text, at: 0)
arr.insert(targetText, at: 0)
arr.removeLast()
}
UserDefaults.standard.set(arr, forKey: Self.searchInfoHistoryKey)
......@@ -233,7 +246,7 @@ extension YHSearchInfomationVC: UITableViewDelegate, UITableViewDataSource {
if 0 <= indexPath.section && indexPath.section < items.count {
let item = items[indexPath.section]
cell.updateModel(item)
cell.renderHighLightText(self.searchBar.textField.text ?? "")
cell.renderHighLightText(searchStr)
}
return cell
}
......
......@@ -37,7 +37,7 @@ class YHSearchInfoBar: UIView {
lazy var textField:UITextField = {
let textField = UITextField()
textField.backgroundColor = .clear
textField.attributedPlaceholder = NSAttributedString(string: "大家正在搜香港身份".local, attributes: [NSAttributedString.Key.foregroundColor : UIColor(hex: 0x94A3B8)])
textField.attributedPlaceholder = NSAttributedString(string: "香港身份".local, attributes: [NSAttributedString.Key.foregroundColor : UIColor(hex: 0x94A3B8)])
textField.font = UIFont.PFSC_M(ofSize: 12)
textField.tintColor = UIColor(hex: 0x3570DC)
textField.textColor = UIColor(hexString: "#121A26")
......
......@@ -40,6 +40,8 @@ struct PersonalModuleItem {
class YHMyViewController: YHBaseViewController, ConstraintRelatableTarget {
let viewModel: YHMyLikeViewModel = YHMyLikeViewModel()
lazy var tableView: UITableView = {
let tableView = UITableView(frame: CGRect.zero, style:.grouped)
if #available(iOS 11.0, *) {
......@@ -129,7 +131,11 @@ class YHMyViewController: YHBaseViewController, ConstraintRelatableTarget {
override func viewDidLoad() {
super.viewDidLoad()
initView()
return
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
requestLikeCollectionCount()
}
@objc func clickBtn() {
......@@ -159,51 +165,20 @@ class YHMyViewController: YHBaseViewController, ConstraintRelatableTarget {
}
NotificationCenter.default.addObserver(self, selector: #selector(loginSuccess), name: YhConstant.YhNotification.didLoginSuccessNotifiction, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(logoutSuccess), name: YhConstant.YhNotification.didLogoutSuccessNotifiction, object: nil)
}
func openXLSXRemoteFile(urlString: String) {
guard let url = URL(string: urlString) else { return }
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration)
func requestLikeCollectionCount() {
let task = session.downloadTask(with: url) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil {
// 下载完成,尝试打开文件
let fileManager = FileManager.default
let destination = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(response?.suggestedFilename ?? UUID().uuidString)
try? fileManager.moveItem(at: tempLocalUrl, to: destination)
// 打开文件
self.openXLSXFile(at: destination)
} else {
print("Error downloading the file: \(error?.localizedDescription ?? "Unknown error")")
}
}
task.resume()
}
func openXLSXFile(at fileURL: URL) {
let controller = UIDocumentInteractionController(url: fileURL)
controller.delegate = self
DispatchQueue.main.async {
controller.presentPreview(animated: true)
self.viewModel.getLikeCollectionRecentScanCountInfo {
[weak self] success, error in
guard let self = self else { return }
self.headerView.updateLikeCollectCount(self.viewModel.likeCollectCountInfo)
}
}
}
extension YHMyViewController: UIDocumentInteractionControllerDelegate {
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
}
extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
......
//
// YHCollectionModel.swift
// galaxy
//
// Created by edy on 2024/4/15.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import SmartCodable
struct YHCollectionModel: SmartCodable {
var myCollectCount: Int = 0
var myLikeCount: Int = 0
var myViewCount: Int = 0
enum CodingKeys: String, CodingKey {
case myCollectCount = "my_collect_count"
case myLikeCount = "my_like_count"
case myViewCount = "my_view_count"
}
}
......@@ -178,9 +178,23 @@ class YHUserInfoHeaderView: UIView {
return view
}
func updateLikeCollectCount(_ model: YHCollectionModel) {
let likeCount = showCount(model.myLikeCount)
let collectCount = showCount(model.myCollectCount)
let scanCount = showCount(model.myViewCount)
self.likeLabel.text = "点赞 \(likeCount)"
self.collectLabel.text = "收藏 \(collectCount)"
self.scanLabel.text = "最近浏览 \(scanCount)"
}
func showCount(_ count: Int)-> String {
return count < 10000 ? String(count) : String(format: "%.1fw", Double(count/10000))
}
private func createUI() {
self.addSubview(bgImgView)
self.addSubview(settingView)
settingView.addSubview(settingBtn)
......
......@@ -10,7 +10,7 @@ import UIKit
class YHMyLikeViewModel: YHBaseViewModel {
var arrHomeNewsData: [YHHomeListModel]?
var likeCollectCountInfo: YHCollectionModel = YHCollectionModel()
private var curPageIndex : Int = 1
private var page_Size : Int = 6
private var totalCount : Int = 0
......@@ -130,4 +130,30 @@ extension YHMyLikeViewModel {
callBackBlock(false,err)
}
}
// 获取点赞、收藏、最近浏览数量
func getLikeCollectionRecentScanCountInfo(callBack:((_ success: Bool,_ error:YHErrorModel?)->())?) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Common.likeCollect
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 = YHCollectionModel.deserialize(dict: dic as? Dictionary ) else {
let error = YHErrorModel(errorCode: YHErrorCode.dictParseError.rawValue, errorMsg: YHErrorCode.dictParseError.description())
callBack?(false, error)
return
}
self.likeCollectCountInfo = result as YHCollectionModel
callBack?(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBack?(false, error)
}
} failBlock: { err in
callBack?(false,err)
}
}
}
......@@ -32,6 +32,8 @@ class YHAllApiName {
static let userLook = "infoflow/user/view"
//获取香港办事
static let hklist = "infoflow/tool/list"
// 点赞、收藏、最近浏览数量
static let likeCollect = "infoflow/article/myArticleRecord"
}
//order 模块
......
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