diff --git a/WePeiYang.xcodeproj/project.pbxproj b/WePeiYang.xcodeproj/project.pbxproj index 92270e9..9594864 100644 --- a/WePeiYang.xcodeproj/project.pbxproj +++ b/WePeiYang.xcodeproj/project.pbxproj @@ -2470,7 +2470,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 202012011630; + CURRENT_PROJECT_VERSION = 202012032200; DEVELOPMENT_TEAM = A4JNABY964; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = WePeiYangWidget/Info.plist; @@ -2506,7 +2506,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 202012011630; + CURRENT_PROJECT_VERSION = 202012032200; DEVELOPMENT_TEAM = A4JNABY964; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = WePeiYangWidget/Info.plist; @@ -2647,7 +2647,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 202012011630; + CURRENT_PROJECT_VERSION = 202012032200; DEVELOPMENT_TEAM = A4JNABY964; INFOPLIST_FILE = WePeiYang/main/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; @@ -2676,7 +2676,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 202012011630; + CURRENT_PROJECT_VERSION = 202012032200; DEVELOPMENT_TEAM = A4JNABY964; INFOPLIST_FILE = WePeiYang/main/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; diff --git a/WePeiYang/FeedBack/Controller/FBNewQuestionController.swift b/WePeiYang/FeedBack/Controller/FBNewQuestionController.swift index 0c94ed6..3ec71e3 100644 --- a/WePeiYang/FeedBack/Controller/FBNewQuestionController.swift +++ b/WePeiYang/FeedBack/Controller/FBNewQuestionController.swift @@ -22,7 +22,8 @@ class FBNewQuestionViewController: UIViewController, UITextFieldDelegate, UIText var tagSelectionView: SelectionView! var tagDesLabel: UILabel! // 问题描述 - var contentsLabel: UILabel! + var contentCountLabel: UILabel! + var contentLabel: UILabel! var contentField: UITextView! // 插入图片 var photoLabel: UILabel! @@ -166,16 +167,26 @@ extension FBNewQuestionViewController { addSymmetryLine(y: 235, isDotted: true) - contentsLabel = UILabel() - contentsLabel.text = "问题描述:" - contentsLabel.textColor = UIColor.black - contentsLabel.font = .systemFont(ofSize: LABEL_FONT_SIZE) - view.addSubview(contentsLabel) - contentsLabel.snp.makeConstraints { (make) in + contentLabel = UILabel() + contentLabel.text = "问题描述:" + contentLabel.textColor = UIColor.black + contentLabel.font = .systemFont(ofSize: LABEL_FONT_SIZE) + view.addSubview(contentLabel) + contentLabel.snp.makeConstraints { (make) in make.top.equalTo(tagDesLabel.snp.bottom).offset(20) make.left.equalTo(LEFT_PADDING) } + contentCountLabel = UILabel() + contentCountLabel.text = "0/200" + contentCountLabel.textColor = .gray + contentCountLabel.font = .systemFont(ofSize: LABEL_FONT_SIZE - 2) + view.addSubview(contentCountLabel) + contentCountLabel.snp.makeConstraints { (make) in + make.centerY.equalTo(contentLabel) + make.right.equalTo(view.snp.right).offset(-LEFT_PADDING) + } + contentField = UITextView() contentField.layer.borderWidth = 1 contentField.layer.cornerRadius = 5 @@ -188,7 +199,7 @@ extension FBNewQuestionViewController { contentField.font = .systemFont(ofSize: 14) view.addSubview(contentField) contentField.snp.makeConstraints{ (make) in - make.top.equalTo(contentsLabel.snp.bottom).offset(10) + make.top.equalTo(contentLabel.snp.bottom).offset(10) make.height.equalTo(100) make.left.equalTo(LEFT_PADDING) make.right.equalTo(-LEFT_PADDING) @@ -282,8 +293,10 @@ extension FBNewQuestionViewController { case .success(let questionId): if let imgs = self.photoCollectionView.images { guard imgs.count != 1 else { - NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_HAD_SEND_QUESTION))) + NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_NEED_RELOAD))) + NotificationCenter.default.post(Notification(name: Notification.Name(FB_SHOULD_RELOAD_NEWQUESTIONVC))) SwiftMessages.hideLoading() + SwiftMessages.showSuccessMessage(body: "发布成功") self.dismiss(animated: true) return } @@ -305,8 +318,10 @@ extension FBNewQuestionViewController { } } group.notify(queue: .main) { - NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_HAD_SEND_QUESTION))) + NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_NEED_RELOAD))) + NotificationCenter.default.post(Notification(name: Notification.Name(FB_SHOULD_RELOAD_NEWQUESTIONVC))) SwiftMessages.hideLoading() + SwiftMessages.showSuccessMessage(body: "发布成功") self.dismiss(animated: true) } } @@ -345,6 +360,7 @@ extension FBNewQuestionViewController { let currentString: NSString = textView.text! as NSString let newString: NSString = currentString.replacingCharacters(in: range, with: text) as NSString + contentCountLabel.text = "\(newString.length)/200" return newString.length <= maxLength } diff --git a/WePeiYang/FeedBack/Controller/FeedBackDetailViewController.swift b/WePeiYang/FeedBack/Controller/FeedBackDetailViewController.swift index 6254425..1c8c847 100644 --- a/WePeiYang/FeedBack/Controller/FeedBackDetailViewController.swift +++ b/WePeiYang/FeedBack/Controller/FeedBackDetailViewController.swift @@ -108,7 +108,11 @@ extension FeedBackDetailViewController { } @objc func likeOrDislike() { + NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_NEED_RELOAD))) if self.isLiked ?? false { + if let count = (tableView.tableHeaderView as? FBDetailHeaderView)?.likesLabel.text { + (tableView.tableHeaderView as? FBDetailHeaderView)?.likesLabel.text = String((Int(count) ?? 0) - 1) + } FBQuestionHelper.dislikeQuestion(id: questionOfthisPage?.id ?? 0) { (result) in switch result { case .success(let str): @@ -119,6 +123,9 @@ extension FeedBackDetailViewController { } } } else { + if let count = (tableView.tableHeaderView as? FBDetailHeaderView)?.likesLabel.text { + (tableView.tableHeaderView as? FBDetailHeaderView)?.likesLabel.text = String((Int(count) ?? 0) + 1) + } FBQuestionHelper.likeQuestion(id: questionOfthisPage?.id ?? 0) { (result) in switch result { case .success(let str): @@ -314,13 +321,14 @@ extension FeedBackDetailViewController: UITableViewDataSource, UITableViewDelega textView.textColor = .black } if (text == "\n") { - textView.resignFirstResponder() - guard textView.text! != "" else { + guard textView.text != "发表你的看法" && textView.text! != "" else { return true } + textView.resignFirstResponder() textView.endEditing(true) FBCommentHelper.addComment(questionId: (questionOfthisPage?.id)!, contain: textView.text) { (string) in SwiftMessages.showSuccessMessage(body: "评论发布成功!") + NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_NEED_RELOAD))) self.loadData() textView.text = "发表你的看法" textView.textColor = UIColor(hex6: 0xdbdbdb) diff --git a/WePeiYang/FeedBack/Controller/FeedBackMainViewController.swift b/WePeiYang/FeedBack/Controller/FeedBackMainViewController.swift index c3b954c..368b413 100644 --- a/WePeiYang/FeedBack/Controller/FeedBackMainViewController.swift +++ b/WePeiYang/FeedBack/Controller/FeedBackMainViewController.swift @@ -17,15 +17,13 @@ let SCREEN = UIScreen.main.bounds class FeedBackMainViewController: UIViewController { // MARK: - UI - + // 搜索框 var searchController: UISearchController! - + // 问题列表 var tableView: UITableView! - -// var tagCollectionView: UICollectionView! + // 标签视图 var tagSelectionView: SelectionView! - - // MARK: - Data + // 可用标签 var availableTags = [ FBTagModel(id: 0, name: "教务处", children: nil), FBTagModel(id: 0, name: "后保部", children: nil), @@ -37,13 +35,15 @@ class FeedBackMainViewController: UIViewController { tableView.mj_header.beginRefreshing() } } - // means no tag is selected + // 选择标签下标 var selectedTag: Int = -1 { didSet { self.tableView.mj_header.beginRefreshing() } } - + //MARK: - DATA + var newQuestionController: FBNewQuestionViewController? + // 问题数据 var questions = [FBQuestionModel]() { didSet { tableView.reloadData() @@ -52,7 +52,7 @@ class FeedBackMainViewController: UIViewController { } } } - + // 当前Page数 var curPage = 1 { didSet { if curPage != 1 { @@ -75,7 +75,7 @@ class FeedBackMainViewController: UIViewController { } } } - + // CELL 注册ID private let collectionViewCellId = "feedBackCollectionViewCellID" private let tableViewCellId = "feedBackQuestionTableViewCellID" @@ -85,10 +85,10 @@ class FeedBackMainViewController: UIViewController { self.view.backgroundColor = UIColor.white setUp() - tableView.mj_header.beginRefreshing() loadData() - NotificationCenter.default.addObserver(self, selector: #selector(headerRefresh), name: Notification.Name(rawValue: FB_NOTIFICATIONFLAG_HAD_SEND_QUESTION), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(loadData), name: Notification.Name(rawValue: FB_NOTIFICATIONFLAG_NEED_RELOAD), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(reloadNewQuestionVC), name: Notification.Name(rawValue: FB_SHOULD_RELOAD_NEWQUESTIONVC), object: nil) } override func viewWillLayoutSubviews() { @@ -228,14 +228,14 @@ extension FeedBackMainViewController: UISearchControllerDelegate { self.navigationController?.pushViewController(vc, animated: true) } floaty.addItem("添加问题", icon: UIImage(named: "feedback_add_question")) { (_) in - let addVC = FBNewQuestionViewController() - addVC.availableTags = self.availableTags - self.present(addVC, animated: true, completion: nil) + if self.newQuestionController == nil { + self.newQuestionController = FBNewQuestionViewController() + self.newQuestionController?.availableTags = self.availableTags + } + self.present(self.newQuestionController!, animated: true, completion: nil) } view.addSubview(floaty) } - - } // MARK: - TableView Delegate & cell @@ -277,7 +277,9 @@ extension FeedBackMainViewController: UITableViewDataSource, UITableViewDelegate // MARK: - Data Control extension FeedBackMainViewController { - private func loadData() { + @objc private func loadData() { + tableView.mj_header.beginRefreshing() + FBTagsHelper.tagGet { (results) in switch results { case .success(let tags): @@ -299,6 +301,13 @@ extension FeedBackMainViewController { } } } + + @objc private func reloadNewQuestionVC() { + if self.newQuestionController != nil { + self.newQuestionController = FBNewQuestionViewController() + self.newQuestionController?.availableTags = self.availableTags + } + } } // MARK: - Button Methods diff --git a/WePeiYang/FeedBack/Model/FBConsts.swift b/WePeiYang/FeedBack/Model/FBConsts.swift index c6b3dac..fc76c3d 100644 --- a/WePeiYang/FeedBack/Model/FBConsts.swift +++ b/WePeiYang/FeedBack/Model/FBConsts.swift @@ -12,7 +12,8 @@ import Foundation // MARK: - 用户端基础URL let FB_BASE_USER_URL: String = "https://areas.twt.edu.cn/api/user/" let FB_USER_ID: Int = TwTUser.shared.feedbackID ?? 0 -let FB_NOTIFICATIONFLAG_HAD_SEND_QUESTION: String = "HAD_NEW_QUESTION" +let FB_NOTIFICATIONFLAG_NEED_RELOAD: String = "FB_NOTIFICATIONFLAG_NEED_RELOAD" +let FB_SHOULD_RELOAD_NEWQUESTIONVC: String = "FB_SHOULD_RELOAD_NEWQUESTIONVC" extension UIColor { static var feedBackBlue: UIColor = UIColor(hex6: 0x3f54af)