Commit c0c1eadb authored by Alex朱枝文's avatar Alex朱枝文

测试bug修复

parent 73f1ee3d
...@@ -499,12 +499,26 @@ extension YHCirclePublishViewController: UITextViewDelegate { ...@@ -499,12 +499,26 @@ extension YHCirclePublishViewController: UITextViewDelegate {
} }
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if textView == self.textView {
let currentText = textView.text ?? "" let currentText = textView.text ?? ""
guard let stringRange = Range(range, in: currentText) else { return false } guard let stringRange = Range(range, in: currentText) else { return false }
let updatedText = currentText.replacingCharacters(in: stringRange, with: text) let updatedText = currentText.replacingCharacters(in: stringRange, with: text)
return updatedText.count <= 100
if textView == self.textView {
// 标题限制20个字符
if updatedText.count > 20 {
YHHUD.flash(message: "标题最多20个字符")
return false
}
return true
} else if textView == self.detailTextView {
// 详情限制1000个字符
if updatedText.count > 1000 {
YHHUD.flash(message: "内容最多1000个字符")
return false
}
return true
} }
return true return true
} }
} }
......
...@@ -17,6 +17,8 @@ class YHResourceViewController: YHBaseViewController { ...@@ -17,6 +17,8 @@ class YHResourceViewController: YHBaseViewController {
// 添加高度约束属性 // 添加高度约束属性
private var categoryViewHeightConstraint: Constraint? private var categoryViewHeightConstraint: Constraint?
private var searchWorkItem: DispatchWorkItem?
lazy var viewModel: YHResourceViewModel = { lazy var viewModel: YHResourceViewModel = {
let viewModel = YHResourceViewModel() let viewModel = YHResourceViewModel()
return viewModel return viewModel
...@@ -315,7 +317,9 @@ private extension YHResourceViewController { ...@@ -315,7 +317,9 @@ private extension YHResourceViewController {
viewModel.getResourceCategories { [weak self] categories, error in viewModel.getResourceCategories { [weak self] categories, error in
guard let self = self else { return } guard let self = self else { return }
if let categories = categories { if var categories = categories {
let all = YHResourceCategory.allCategory
categories.insert(all, at: 0)
self.allCategories = categories self.allCategories = categories
self.categoryView.setCategories(categories) self.categoryView.setCategories(categories)
} else if let error = error { } else if let error = error {
...@@ -394,9 +398,15 @@ private extension YHResourceViewController { ...@@ -394,9 +398,15 @@ private extension YHResourceViewController {
industryButton.setTitleColor(UIColor.brandGrayColor7, for: .normal) industryButton.setTitleColor(UIColor.brandGrayColor7, for: .normal)
industryButton.titleLabel?.font = UIFont.PFSC_R(ofSize: 13) industryButton.titleLabel?.font = UIFont.PFSC_R(ofSize: 13)
} else if selectedCategories.count == 1 { } else if selectedCategories.count == 1 {
if selectedCategories.first?.id == YHResourceCategory.allCategory.id {
industryButton.setTitle("全部行业", for: .normal)
industryButton.setTitleColor(UIColor.brandGrayColor8, for: .normal)
industryButton.titleLabel?.font = UIFont.PFSC_M(ofSize: 13)
} else {
industryButton.setTitle(selectedCategories.first?.name ?? "全部行业", for: .normal) industryButton.setTitle(selectedCategories.first?.name ?? "全部行业", for: .normal)
industryButton.setTitleColor(UIColor.brandGrayColor8, for: .normal) industryButton.setTitleColor(UIColor.brandGrayColor8, for: .normal)
industryButton.titleLabel?.font = UIFont.PFSC_M(ofSize: 13) industryButton.titleLabel?.font = UIFont.PFSC_M(ofSize: 13)
}
} else { } else {
industryButton.setTitle("已选\(selectedCategories.count)个行业", for: .normal) industryButton.setTitle("已选\(selectedCategories.count)个行业", for: .normal)
industryButton.setTitleColor(UIColor.brandGrayColor8, for: .normal) industryButton.setTitleColor(UIColor.brandGrayColor8, for: .normal)
...@@ -538,8 +548,19 @@ private extension YHResourceViewController { ...@@ -538,8 +548,19 @@ private extension YHResourceViewController {
extension YHResourceViewController: YHCustomSearchViewDelegate { extension YHResourceViewController: YHCustomSearchViewDelegate {
func searchView(_ searchView: YHCustomSearchView, didSearchWithText text: String?) { func searchView(_ searchView: YHCustomSearchView, didSearchWithText text: String?) {
viewModel.searchKeyword = text // 取消之前的延迟任务
getData() searchWorkItem?.cancel()
// 创建新的延迟任务
let workItem = DispatchWorkItem { [weak self] in
self?.viewModel.searchKeyword = text
self?.getData()
}
searchWorkItem = workItem
// 1秒后执行
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: workItem)
} }
func searchViewDidBeginEditing(_ searchView: YHCustomSearchView) { func searchViewDidBeginEditing(_ searchView: YHCustomSearchView) {
......
...@@ -198,6 +198,13 @@ class YHResourceListModel: SmartCodable { ...@@ -198,6 +198,13 @@ class YHResourceListModel: SmartCodable {
// MARK: - 资源分类模型 // MARK: - 资源分类模型
class YHResourceCategory: SmartCodable { class YHResourceCategory: SmartCodable {
static var allCategory: YHResourceCategory = {
let all = YHResourceCategory()
all.name = "全部行业"
all.id = "-9999"
return all
}()
required init() {} required init() {}
var id: String = "" var id: String = ""
......
...@@ -43,6 +43,7 @@ class YHCustomSearchView: UIView { ...@@ -43,6 +43,7 @@ class YHCustomSearchView: UIView {
textField.addTarget(self, action: #selector(textFieldEditingDidBegin(_:)), for: .editingDidBegin) textField.addTarget(self, action: #selector(textFieldEditingDidBegin(_:)), for: .editingDidBegin)
textField.addTarget(self, action: #selector(textFieldEditingDidEnd(_:)), for: .editingDidEnd) textField.addTarget(self, action: #selector(textFieldEditingDidEnd(_:)), for: .editingDidEnd)
textField.returnKeyType = .search textField.returnKeyType = .search
textField.clearButtonMode = .whileEditing
textField.attributedPlaceholder = NSAttributedString.init(string: "搜索企业名称、企业供需", attributes: [.foregroundColor: UIColor.brandGrayColor6, .font: UIFont.PFSC_R(ofSize: 14)]) textField.attributedPlaceholder = NSAttributedString.init(string: "搜索企业名称、企业供需", attributes: [.foregroundColor: UIColor.brandGrayColor6, .font: UIFont.PFSC_R(ofSize: 14)])
return textField return textField
}() }()
......
...@@ -186,6 +186,17 @@ extension YHResourceCategoryView: UICollectionViewDataSource, UICollectionViewDe ...@@ -186,6 +186,17 @@ extension YHResourceCategoryView: UICollectionViewDataSource, UICollectionViewDe
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let category = categories[indexPath.item] let category = categories[indexPath.item]
if category.id == YHResourceCategory.allCategory.id {
// 全部行业的处理逻辑
if selectedCategories.contains(where: { $0.id == YHResourceCategory.allCategory.id }) {
selectedCategories.removeAll()
} else {
selectedCategories = [category]
}
} else {
// 其他行业的处理逻辑
selectedCategories.removeAll(where: { $0.id == YHResourceCategory.allCategory.id })
// 原有的切换逻辑
// 切换选中状态(支持多选) // 切换选中状态(支持多选)
if let index = selectedCategories.firstIndex(where: { $0.id == category.id }) { if let index = selectedCategories.firstIndex(where: { $0.id == category.id }) {
// 如果已选中,则取消选中 // 如果已选中,则取消选中
...@@ -194,6 +205,7 @@ extension YHResourceCategoryView: UICollectionViewDataSource, UICollectionViewDe ...@@ -194,6 +205,7 @@ extension YHResourceCategoryView: UICollectionViewDataSource, UICollectionViewDe
// 如果未选中,则添加到选中列表 // 如果未选中,则添加到选中列表
selectedCategories.append(category) selectedCategories.append(category)
} }
}
// 刷新UI // 刷新UI
collectionView.reloadData() collectionView.reloadData()
...@@ -279,14 +291,14 @@ class YHResourceCategoryCell: UICollectionViewCell { ...@@ -279,14 +291,14 @@ class YHResourceCategoryCell: UICollectionViewCell {
} }
func configure(with category: YHResourceCategory, isSelected: Bool) { func configure(with category: YHResourceCategory, isSelected: Bool) {
// 设置图标(如果有) // // 设置图标(如果有)
if !category.icon.isEmpty { // if !category.icon.isEmpty {
iconLabel.text = category.icon // iconLabel.text = category.icon
iconLabel.isHidden = false // iconLabel.isHidden = false
} else { // } else {
// iconLabel.isHidden = true
// }
iconLabel.isHidden = true iconLabel.isHidden = true
}
titleLabel.text = category.name titleLabel.text = category.name
if isSelected { if isSelected {
......
...@@ -54,7 +54,8 @@ class YHResourceViewModel: NSObject { ...@@ -54,7 +54,8 @@ class YHResourceViewModel: NSObject {
"page_size": pageSize, "page_size": pageSize,
"type": currentType == .service ? 1 : 2 // 1-服务 2-需求 "type": currentType == .service ? 1 : 2 // 1-服务 2-需求
] ]
// 如果包含全部行业就移除
selectedCategories.removeAll(where: { $0.id == YHResourceCategory.allCategory.id })
// 添加分类筛选(多选)- 转为Int数组 // 添加分类筛选(多选)- 转为Int数组
if !selectedCategories.isEmpty { if !selectedCategories.isEmpty {
let categoryIds = selectedCategories.compactMap { Int($0.id) } let categoryIds = selectedCategories.compactMap { Int($0.id) }
......
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