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

测试bug修复

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