From ae8b750a3a10f809836d5ea008025280e8a24f26 Mon Sep 17 00:00:00 2001 From: Zrzzzz <1160026659@qq.com> Date: Mon, 30 Nov 2020 15:32:00 +0800 Subject: [PATCH] sync --- WePeiYang.xcodeproj/project.pbxproj | 20 +- .../Controller/FavViewController.swift | 689 +++++++++--------- WePeiYang/Favorite/View/FeedBackCard.swift | 59 ++ .../FBReplyDetailTVController.swift | 106 +-- .../FeedBackMainViewController.swift | 82 +-- .../FeedBack/Model/FBCommentHelper.swift | 2 +- .../CellView/FBReplyDetailTableViewCell.swift | 244 +++---- .../View/CellView/FBReplyTableViewCell.swift | 366 +++++----- .../FeedBack/View/FBRateCommentView.swift | 248 +++---- WePeiYang/FeedBack/View/FBStarRateView.swift | 14 +- .../Shared/UI_Fundamentals/CardView.swift | 2 +- .../Shared/Utilities/ModuleStateManager.swift | 40 +- 12 files changed, 987 insertions(+), 885 deletions(-) create mode 100644 WePeiYang/Favorite/View/FeedBackCard.swift diff --git a/WePeiYang.xcodeproj/project.pbxproj b/WePeiYang.xcodeproj/project.pbxproj index 4f07c9b..d66d969 100644 --- a/WePeiYang.xcodeproj/project.pbxproj +++ b/WePeiYang.xcodeproj/project.pbxproj @@ -292,6 +292,7 @@ D31D395325224ABD0001137E /* FBUserViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D31D395225224ABD0001137E /* FBUserViewController.swift */; }; D35DE90B25738CB8000F0215 /* FBReplyDetailTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D35DE90A25738CB8000F0215 /* FBReplyDetailTableViewCell.swift */; }; D35DE91D2573967F000F0215 /* FBRateCommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D35DE91C2573967F000F0215 /* FBRateCommentView.swift */; }; + D364F7DB2574B99700815844 /* FeedBackCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = D364F7DA2574B99700815844 /* FeedBackCard.swift */; }; D3849B2F251B6ABE00B49D6C /* FBTagCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3849B2E251B6ABE00B49D6C /* FBTagCollectionViewCell.swift */; }; D3849B35251B8B4E00B49D6C /* FBQuestionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3849B34251B8B4E00B49D6C /* FBQuestionTableViewCell.swift */; }; D3849B3F251BA84300B49D6C /* FBCommentTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3849B3E251BA84300B49D6C /* FBCommentTableViewCell.swift */; }; @@ -429,7 +430,7 @@ 3614D56B21D929FE0007B886 /* LibraryPageContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LibraryPageContentView.swift; sourceTree = ""; }; 3614D56C21D929FE0007B886 /* BookCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookCard.swift; sourceTree = ""; }; 3614D56D21D929FE0007B886 /* BookDetailTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookDetailTableViewCell.swift; sourceTree = ""; }; - 3615A9C421AC80FC001D1522 /* ECardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ECardView.swift; sourceTree = ""; }; + 3615A9C421AC80FC001D1522 /* ECardView.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = ECardView.swift; sourceTree = ""; }; 3615A9C621AC825E001D1522 /* ECardModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ECardModel.swift; sourceTree = ""; }; 3615A9C921ACEBDC001D1522 /* CardTransectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardTransectionViewController.swift; sourceTree = ""; }; 361F884E204AF92100BCFA19 /* HomePageHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomePageHelper.swift; sourceTree = ""; }; @@ -516,7 +517,7 @@ 365A8A1C1FB9BA8500B15443 /* ClasstableDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClasstableDataManager.swift; sourceTree = ""; }; 365A8A271FB9CA1700B15443 /* ClassModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClassModel.swift; sourceTree = ""; }; 365B5398216E5F4000A808EE /* ClassTableSettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassTableSettingViewController.swift; sourceTree = ""; }; - 366767F921BBD4A700EB2F2B /* ModuleStateManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModuleStateManager.swift; sourceTree = ""; }; + 366767F921BBD4A700EB2F2B /* ModuleStateManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = ModuleStateManager.swift; sourceTree = ""; }; 3667E1CF201CB98800E82241 /* DetailSettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailSettingViewController.swift; sourceTree = ""; }; 3668CE542159E121002673BE /* WPYTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WPYTextField.swift; sourceTree = ""; }; 36758FDC1FDA851C0023A99C /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = ""; }; @@ -667,7 +668,7 @@ B10254141EC8547E0064373A /* TabVCTransitioningAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabVCTransitioningAnimator.swift; sourceTree = ""; }; B10254181EC8547E0064373A /* WPYTabBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WPYTabBarController.swift; sourceTree = ""; }; B13F3AE71F0CEE5C00F820A5 /* FAB.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FAB.swift; sourceTree = ""; }; - B181B9571EC5C21700B8198E /* FavViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FavViewController.swift; sourceTree = ""; }; + B181B9571EC5C21700B8198E /* FavViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = FavViewController.swift; sourceTree = ""; }; B19DAB861E6EF5C2004A50B5 /* WePeiYang.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WePeiYang.app; sourceTree = BUILT_PRODUCTS_DIR; }; B19DAB9A1E6EF5C2004A50B5 /* WePeiYangTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WePeiYangTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; B19DAB9E1E6EF5C2004A50B5 /* WePeiYangTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WePeiYangTests.swift; sourceTree = ""; }; @@ -679,15 +680,16 @@ D31D383E251FEAB90001137E /* FBPhotoCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBPhotoCollectionView.swift; sourceTree = ""; }; D31D3844251FEC350001137E /* FBPhotoCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBPhotoCollectionViewCell.swift; sourceTree = ""; }; D31D395225224ABD0001137E /* FBUserViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBUserViewController.swift; sourceTree = ""; }; - D35DE90A25738CB8000F0215 /* FBReplyDetailTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBReplyDetailTableViewCell.swift; sourceTree = ""; }; - D35DE91C2573967F000F0215 /* FBRateCommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBRateCommentView.swift; sourceTree = ""; }; + D35DE90A25738CB8000F0215 /* FBReplyDetailTableViewCell.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = FBReplyDetailTableViewCell.swift; sourceTree = ""; }; + D35DE91C2573967F000F0215 /* FBRateCommentView.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = FBRateCommentView.swift; sourceTree = ""; wrapsLines = 0; }; + D364F7DA2574B99700815844 /* FeedBackCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedBackCard.swift; sourceTree = ""; }; D3849B2E251B6ABE00B49D6C /* FBTagCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBTagCollectionViewCell.swift; sourceTree = ""; }; D3849B34251B8B4E00B49D6C /* FBQuestionTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBQuestionTableViewCell.swift; sourceTree = ""; }; D3849B3E251BA84300B49D6C /* FBCommentTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FBCommentTableViewCell.swift; sourceTree = ""; }; D3849B44251BA97800B49D6C /* FBDetailHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBDetailHeaderView.swift; sourceTree = ""; }; D3849B5A251C5CDA00B49D6C /* FBDetailTabBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBDetailTabBarView.swift; sourceTree = ""; }; - D3959CC02567A9F700AF9035 /* FBReplyDetailTVController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBReplyDetailTVController.swift; sourceTree = ""; }; - D3959CC62567AB1600AF9035 /* FBReplyTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FBReplyTableViewCell.swift; sourceTree = ""; }; + D3959CC02567A9F700AF9035 /* FBReplyDetailTVController.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = FBReplyDetailTVController.swift; sourceTree = ""; }; + D3959CC62567AB1600AF9035 /* FBReplyTableViewCell.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = FBReplyTableViewCell.swift; sourceTree = ""; }; D39A291C25664A4F003EBAB3 /* FBStarRateView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FBStarRateView.swift; sourceTree = ""; }; D39D3F6B2535FDA900D77173 /* GPAModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GPAModel.swift; sourceTree = ""; }; D3AF3C7D2569117000EC72F5 /* TMP.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TMP.swift; sourceTree = ""; }; @@ -1583,6 +1585,7 @@ 3615A9C421AC80FC001D1522 /* ECardView.swift */, 364BDF711FDAE1EF00E61B65 /* GPACard.swift */, 36CAD44B201B9194006F85E3 /* ClassTableCard.swift */, + D364F7DA2574B99700815844 /* FeedBackCard.swift */, ); path = View; sourceTree = ""; @@ -1600,7 +1603,7 @@ D33D5F603943FDFD415D167A /* Frameworks */, 3614D54C21D9282C0007B886 /* Recovered References */, ); - indentWidth = 5; + indentWidth = 4; sourceTree = ""; wrapsLines = 0; }; @@ -2363,6 +2366,7 @@ 2BAB12B0251729FD00FF6EEF /* FBUserHelper.swift in Sources */, DD6A663421A59D260070C4B2 /* AuditCollegeCourseViewController.swift in Sources */, A5E117BD1F99DCF300C86CA2 /* BicycleFitnessTrackerViewController.swift in Sources */, + D364F7DB2574B99700815844 /* FeedBackCard.swift in Sources */, 36449E8F1FA4BAD10036766B /* HandInDetailViewController.swift in Sources */, 3668CE552159E121002673BE /* WPYTextField.swift in Sources */, 4B622542245D782D005EFA6A /* GetQrCodeModel.swift in Sources */, diff --git a/WePeiYang/Favorite/Controller/FavViewController.swift b/WePeiYang/Favorite/Controller/FavViewController.swift index 5542994..2c6386d 100644 --- a/WePeiYang/Favorite/Controller/FavViewController.swift +++ b/WePeiYang/Favorite/Controller/FavViewController.swift @@ -11,354 +11,381 @@ import SnapKit let MessageKey = "MessageKey" class FavViewController: UIViewController { - - // The below override will not be called if current viewcontroller is controlled by a UINavigationController - // We should do self.navigationController.navigationBar.barStyle = UIBarStyleBlack - // override var preferredStatusBarStyle: UIStatusBarStyle { - // return .lightContent - // } - var headerView: UIView! - var fooView: UIView! - var cardTableView: UITableView! - var cardDict: [Module: CardView] = [:] - var cellHeights: [CGFloat] = [] - - var modules: [Module] = [] - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) - navigationController?.setNavigationBarHidden(true, animated: animated) - navigationController?.navigationBar.shadowImage = UIImage() - // - // navigationController?.navigationBar.barStyle = .black - // navigationController?.navigationBar.barTintColor = Metadata.Color.WPYAccentColor - // //Changing NavigationBar Title color - // navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: Metadata.Color.naviTextColor] - // - // navigationItem.title = "常用" - refreshCards(info: Notification(name: NotificationName.NotificationCardWillRefresh.name)) - } - - override func viewDidLoad() { - super.viewDidLoad() - - navigationController?.navigationBar.barStyle = .black - // navigationController?.navigationBar.barTintColor = Metadata.Color.WPYAccentColor - // Changing NavigationBar Title color - navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: Metadata.Color.naviTextColor] - // This is for removing the dark shadows when transitioning - navigationController?.navigationBar.isTranslucent = false - navigationController?.isNavigationBarHidden = true - - navigationItem.title = "常用" - - // view.backgroundColor = Metadata.Color.GlobalViewBackgroundColor - view.backgroundColor = .white - - self.automaticallyAdjustsScrollViewInsets = false - let statusBarHeight: CGFloat = UIScreen.main.bounds.height == 812 ? 44 : 20 - let tabBarHeight = self.tabBarController?.tabBar.height ?? 0 - - let placeholderLabel = UILabel(text: "什么都不加你还想看什么😒", color: .lightGray) - placeholderLabel.font = UIFont.flexibleSystemFont(ofSize: 20, weight: .medium) - placeholderLabel.sizeToFit() - view.addSubview(placeholderLabel) - - cardTableView = UITableView(frame: CGRect(x: 0, y: statusBarHeight, width: deviceWidth, height: deviceHeight-statusBarHeight-tabBarHeight), style: .grouped) - - placeholderLabel.center = cardTableView.center - - view.addSubview(cardTableView) - - cardTableView.delegate = self - cardTableView.dataSource = self - cardTableView.estimatedRowHeight = 300 - cardTableView.rowHeight = UITableView.automaticDimension - cardTableView.separatorStyle = .none - cardTableView.allowsSelection = false - cardTableView.backgroundColor = .white - - // init headerView - headerView = UIView() - headerView.frame = CGRect(x: 0, y: 0, width: 400, height: 80) - let dateLabel = UILabel() - let now = Date() - let formatter = DateFormatter() - formatter.locale = Locale(identifier: "en_US") - // formatter.dateFormat = "EEEE, MMMM d" - formatter.dateFormat = "EEE, MMMM d" - - dateLabel.textColor = UIColor(red: 0.36, green: 0.36, blue: 0.36, alpha: 1.00) - dateLabel.text = formatter.string(from: now).uppercased() - dateLabel.font = UIFont.systemFont(ofSize: 15) - dateLabel.x = 15 - dateLabel.y = 15 - dateLabel.sizeToFit() - headerView.addSubview(dateLabel) - - let titleLabel = UILabel(text: "Favorite") - titleLabel.font = UIFont.systemFont(ofSize: 35, weight: UIFont.Weight.heavy) - titleLabel.x = 15 - titleLabel.y = 35 - titleLabel.sizeToFit() - headerView.addSubview(titleLabel) - - let xwImgView = UIImageView(frame: CGRect(x: SCREEN.width/2, y: 10, width: SCREEN.width * 0.4, height: 60)) - xwImgView.contentMode = .scaleAspectFit - xwImgView.image = UIImage(named: "feedback_banner") - headerView.addSubview(xwImgView) -// xwImgView.snp.makeConstraints { (make) in -// make.centerY.equalTo(headerView) -// make.width.equalTo(SCREEN.width * 0.4) -// make.right.equalTo(headerView.snp.right).offset(-20) -// } - - _ = NotificationCenter.default.addObserver(forName: NotificationName.NotificationCardWillRefresh.name, object: nil, queue: nil, using: { notification in - // 这个地方很丑陋 - if let info = notification.userInfo, - let nameString = info["name"] as? String, - let name = Module(rawValue: nameString), - let height = info["height"] as? CGFloat, - let card = self.cardDict[name], - let row = self.modules.firstIndex(where: { $0 == name }) { - let indexPath = IndexPath(row: row, section: 0) - let cell = self.cardTableView.cellForRow(at: indexPath) - - self.cellHeights[row] = height - - card.snp.updateConstraints { make in - make.height.equalTo(height) - } - - card.setNeedsUpdateConstraints() - cell?.setNeedsUpdateConstraints() - UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.2, options: .curveEaseInOut, animations: { - card.layoutIfNeeded() - // cell?.contentView.layoutIfNeeded() - cell?.layoutIfNeeded() - }, completion: { _ in + + // The below override will not be called if current viewcontroller is controlled by a UINavigationController + // We should do self.navigationController.navigationBar.barStyle = UIBarStyleBlack + // override var preferredStatusBarStyle: UIStatusBarStyle { + // return .lightContent + // } + var headerView: UIView! + var fooView: UIView! + var cardTableView: UITableView! + var cardDict: [Module: CardView] = [:] + var cellHeights: [CGFloat] = [] + + var modules: [Module] = [] + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + self.navigationController?.navigationBar.isTranslucent = true + navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) + navigationController?.setNavigationBarHidden(true, animated: animated) + navigationController?.navigationBar.shadowImage = UIImage() + // + // navigationController?.navigationBar.barStyle = .black + // navigationController?.navigationBar.barTintColor = Metadata.Color.WPYAccentColor + // //Changing NavigationBar Title color + // navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: Metadata.Color.naviTextColor] + // + // navigationItem.title = "常用" + refreshCards(info: Notification(name: NotificationName.NotificationCardWillRefresh.name)) + } + + override func viewDidLoad() { + super.viewDidLoad() + + navigationController?.navigationBar.barStyle = .black + // navigationController?.navigationBar.barTintColor = Metadata.Color.WPYAccentColor + // Changing NavigationBar Title color + navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: Metadata.Color.naviTextColor] + // This is for removing the dark shadows when transitioning + navigationController?.navigationBar.isTranslucent = false + navigationController?.isNavigationBarHidden = true + + navigationItem.title = "常用" + + // view.backgroundColor = Metadata.Color.GlobalViewBackgroundColor + view.backgroundColor = .white + + self.automaticallyAdjustsScrollViewInsets = false + let statusBarHeight: CGFloat = UIScreen.main.bounds.height == 812 ? 44 : 20 + let tabBarHeight = self.tabBarController?.tabBar.height ?? 0 + + let placeholderLabel = UILabel(text: "什么都不加你还想看什么😒", color: .lightGray) + placeholderLabel.font = UIFont.flexibleSystemFont(ofSize: 20, weight: .medium) + placeholderLabel.sizeToFit() + view.addSubview(placeholderLabel) + + cardTableView = UITableView(frame: CGRect(x: 0, y: statusBarHeight, width: deviceWidth, height: deviceHeight-statusBarHeight-tabBarHeight), style: .grouped) + + placeholderLabel.center = cardTableView.center + + view.addSubview(cardTableView) + + cardTableView.delegate = self + cardTableView.dataSource = self + cardTableView.estimatedRowHeight = 300 + cardTableView.rowHeight = UITableView.automaticDimension + cardTableView.separatorStyle = .none + cardTableView.allowsSelection = false + cardTableView.backgroundColor = .white + + // init headerView + headerView = UIView() + headerView.frame = CGRect(x: 0, y: 0, width: 400, height: 80) + let dateLabel = UILabel() + let now = Date() + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US") + // formatter.dateFormat = "EEEE, MMMM d" + formatter.dateFormat = "EEE, MMMM d" + + dateLabel.textColor = UIColor(red: 0.36, green: 0.36, blue: 0.36, alpha: 1.00) + dateLabel.text = formatter.string(from: now).uppercased() + dateLabel.font = UIFont.systemFont(ofSize: 15) + dateLabel.x = 15 + dateLabel.y = 15 + dateLabel.sizeToFit() + headerView.addSubview(dateLabel) + + let titleLabel = UILabel(text: "Favorite") + titleLabel.font = UIFont.systemFont(ofSize: 35, weight: UIFont.Weight.heavy) + titleLabel.x = 15 + titleLabel.y = 35 + titleLabel.sizeToFit() + headerView.addSubview(titleLabel) + + // let xwImgView = UIImageView(frame: CGRect(x: SCREEN.width/2, y: 10, width: SCREEN.width * 0.4, height: 60)) + // xwImgView.contentMode = .scaleAspectFit + // xwImgView.image = UIImage(named: "feedback_banner") + // headerView.addSubview(xwImgView) + // let xwBtn = UIButton(frame: CGRect(x: SCREEN.width/2, y: 10, width: SCREEN.width * 0.4, height: 60)) + // xwBtn.setBackgroundImage(UIImage(named: "feedback_banner"), for: .normal) + // xwBtn.imageView?.contentMode = .scaleAspectFill + // + // xwBtn.backgroundColor = .yellow + // xwBtn.addCornerRadius(15) + // xwBtn.add(for: .touchUpInside) { + // if TwTUser.shared.token == nil { + // showLoginView { + // let vc = FeedBackMainViewController() + // vc.hidesBottomBarWhenPushed = true + // self.navigationController?.pushViewController(vc, animated: true) + // } + // } else { + // let vc = FeedBackMainViewController() + // vc.hidesBottomBarWhenPushed = true + // self.navigationController?.pushViewController(vc, animated: true) + // } + // } + // headerView.addSubview(xwBtn) + + _ = NotificationCenter.default.addObserver(forName: NotificationName.NotificationCardWillRefresh.name, object: nil, queue: nil, using: { notification in + // 这个地方很丑陋 + if let info = notification.userInfo, + let nameString = info["name"] as? String, + let name = Module(rawValue: nameString), + let height = info["height"] as? CGFloat, + let card = self.cardDict[name], + let row = self.modules.firstIndex(where: { $0 == name }) { + let indexPath = IndexPath(row: row, section: 0) + let cell = self.cardTableView.cellForRow(at: indexPath) + + self.cellHeights[row] = height + + card.snp.updateConstraints { make in + make.height.equalTo(height) + } + + card.setNeedsUpdateConstraints() + cell?.setNeedsUpdateConstraints() + UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.2, options: .curveEaseInOut, animations: { + card.layoutIfNeeded() + // cell?.contentView.layoutIfNeeded() + cell?.layoutIfNeeded() + }, completion: { _ in + }) + + // self.cardTableView.endUpdates() + self.cardTableView.reloadData() + self.cardTableView.scrollToRow(at: indexPath, at: UITableView.ScrollPosition.middle, animated: true) + // self.cardTableView.reloadRows(at: [indexPath], with: .automatic) + } else { + self.refreshCards(info: notification) + } + }) + + reloadOrder() + + NotificationCenter.default.addObserver(self, selector: #selector(refreshCards), name: NotificationName.NotificationUserDidLogout.name, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(refreshCards), name: NotificationName.NotificationUserDidLogin.name, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(reloadOrder), name: NotificationName.NotificationCardOrderChanged.name, object: nil) + + SolaSessionManager.solaSession(type: .get, url: "/app/message", token: nil, parameters: nil, success: { dict in + if let data = dict["data"] as? [String: Any], + let version = data["version"] as? Int, + let title = data["title"] as? String, + let message = data["message"] as? String { + let prev = UserDefaults.standard.integer(forKey: MessageKey) + if version > prev { + // new message + SwiftMessages.showNotification(title: title, message: message, handler: { _ in + UserDefaults.standard.set(version, forKey: MessageKey) + SwiftMessages.hideAll() }) - - // self.cardTableView.endUpdates() - self.cardTableView.reloadData() - self.cardTableView.scrollToRow(at: indexPath, at: UITableView.ScrollPosition.middle, animated: true) - // self.cardTableView.reloadRows(at: [indexPath], with: .automatic) - } else { - self.refreshCards(info: notification) - } - }) - - reloadOrder() - - NotificationCenter.default.addObserver(self, selector: #selector(refreshCards), name: NotificationName.NotificationUserDidLogout.name, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(refreshCards), name: NotificationName.NotificationUserDidLogin.name, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(reloadOrder), name: NotificationName.NotificationCardOrderChanged.name, object: nil) - - SolaSessionManager.solaSession(type: .get, url: "/app/message", token: nil, parameters: nil, success: { dict in - if let data = dict["data"] as? [String: Any], - let version = data["version"] as? Int, - let title = data["title"] as? String, - let message = data["message"] as? String { - let prev = UserDefaults.standard.integer(forKey: MessageKey) - if version > prev { - // new message - SwiftMessages.showNotification(title: title, message: message, handler: { _ in - UserDefaults.standard.set(version, forKey: MessageKey) - SwiftMessages.hideAll() - }) - } - } - }) - } - - // 重新加载顺序 - @objc func reloadOrder() { - modules = ModuleStateManager.getModules() - initCards() - } - - // 重新加载数据 - @objc func refreshCards(info: Notification) { - if modules.isEmpty { - view.sendSubviewToBack(cardTableView) - } else { - view.bringSubviewToFront(cardTableView) - } - - for item in modules { - cardDict[item]?.refresh() - } - - switch info.name { - case NotificationName.NotificationUserDidLogin.name: - cardTableView.reloadData() - case NotificationName.NotificationUserDidLogout.name: - cardTableView.reloadData() - default: - return - } - } - - // 初始化卡片 - func initCards() { - for module in modules where cardDict[module] == nil { - switch module { - case .classtable: + } + } + }) + } + + // 重新加载顺序 + @objc func reloadOrder() { + modules = ModuleStateManager.getModules() + initCards() + } + + // 重新加载数据 + @objc func refreshCards(info: Notification) { + if modules.isEmpty { + view.sendSubviewToBack(cardTableView) + } else { + view.bringSubviewToFront(cardTableView) + } + + for item in modules { + cardDict[item]?.refresh() + } + + switch info.name { + case NotificationName.NotificationUserDidLogin.name: + cardTableView.reloadData() + case NotificationName.NotificationUserDidLogout.name: + cardTableView.reloadData() + default: + return + } + } + + // 初始化卡片 + func initCards() { + for module in modules where cardDict[module] == nil { + switch module { + case .classtable: initClassTableCard() - case .gpa: + case .gpa: initGPACard() - case .library: + case .library: initLibraryCard() - case .ecard: + case .ecard: initEcard() - case .exam: + case .exam: initExamCard() - case .code: + case .code: initQRCode() - - } - } - cardTableView.reloadData() - } - - deinit { - NotificationCenter.default.removeObserver(self) - } + case .feedback: + initFeedBack() + } + } + cardTableView.reloadData() + } + + deinit { + NotificationCenter.default.removeObserver(self) + } } extension FavViewController { - func initGPACard() { - let card = GPACard() - - // card.refresh() - - // let gpaVC = GPAViewController() - // let gpaNC = UINavigationController(rootViewController: gpaVC) - // card.shouldPresent(gpaNC, from: self) - card.shouldPresent(GPAViewController.self, from: self) - // card.shouldPush(gpaVC, from: self) - card.delegate = self - cardDict[Module.gpa] = card - } - - func initClassTableCard() { - let card = ClassTableCard() - - card.delegate = self - - do { - card.shouldPresent(ClassTableViewController.self, from: self) - cardDict[Module.classtable] = card - } - - // card.refresh() - } - - func initLibraryCard() { - let card = LibraryCard() - card.delegate = self - - card.refresh() - card.shouldPresent(LibraryMainViewController.self, from: self) - cardDict[Module.library] = card - } - - func initEcard() { - let card = ECardView() - card.delegate = self - card.refresh() - card.shouldPresent(CardTransactionViewController.self, from: self) - cardDict[Module.ecard] = card - } - - func initExamCard() { - let card = ExamCard() - card.delegate = self - card.refresh() - card.shouldPresent(ExamtableController.self, from: self) - cardDict[Module.exam] = card - } - // MARK: 后来加的 - func initQRCode() { - let card = ActivitiesView() - card.delegate = self - card.refresh() - // MARK: 一定要改下面这个 - card.shouldPresent(ActivitiesViewController.self, from: self) - cardDict[Module.code] = card - } + func initGPACard() { + let card = GPACard() + + // card.refresh() + + // let gpaVC = GPAViewController() + // let gpaNC = UINavigationController(rootViewController: gpaVC) + // card.shouldPresent(gpaNC, from: self) + card.shouldPresent(GPAViewController.self, from: self) + // card.shouldPush(gpaVC, from: self) + card.delegate = self + cardDict[Module.gpa] = card + } + + func initClassTableCard() { + let card = ClassTableCard() + + card.delegate = self + + do { + card.shouldPresent(ClassTableViewController.self, from: self) + cardDict[Module.classtable] = card + } + + // card.refresh() + } + + func initLibraryCard() { + let card = LibraryCard() + card.delegate = self + + card.refresh() + card.shouldPresent(LibraryMainViewController.self, from: self) + cardDict[Module.library] = card + } + + func initEcard() { + let card = ECardView() + card.delegate = self + card.refresh() + card.shouldPresent(CardTransactionViewController.self, from: self) + cardDict[Module.ecard] = card + } + + func initExamCard() { + let card = ExamCard() + card.delegate = self + card.refresh() + card.shouldPresent(ExamtableController.self, from: self) + cardDict[Module.exam] = card + } + // MARK: 后来加的 + func initQRCode() { + let card = ActivitiesView() + card.delegate = self + card.refresh() + // MARK: 一定要改下面这个 + card.shouldPresent(ActivitiesViewController.self, from: self) + cardDict[Module.code] = card + } + + func initFeedBack() { + let card = FeedBackCard() + card.delegate = self + card.refresh() +// card.shouldPresent(FeedBackMainViewController.self, from: self) + card.shouldPush(FeedBackMainViewController.self, from: self) + cardDict[Module.feedback] = card + } } extension FavViewController: UITableViewDataSource { - func numberOfSections(in tableView: UITableView) -> Int { - return 1 - } - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return modules.count - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let module = modules[indexPath.row] - - // let key = Array(cardDict.keys)[indexPath.row] - let card = cardDict[module]! - var cell = tableView.dequeueReusableCell(withIdentifier: "card\(module)") - - if cell == nil { - // no cell in reuse pool - cell = UITableViewCell(style: .default, reuseIdentifier: "card\(module)") - cell!.contentView.addSubview(card) - card.sizeToFit() - let cellHeight: CGFloat = 240 - card.snp.makeConstraints { make in - make.top.equalToSuperview().offset(10) - make.bottom.equalToSuperview().offset(-10) - make.height.equalTo(cellHeight) - if isiPad { - make.centerX.equalToSuperview() - make.width.equalToSuperview().multipliedBy(0.6) - } else { - make.left.equalToSuperview().offset(15) - make.right.equalToSuperview().offset(-15) - } - } - cellHeights.append(cellHeight) - cell?.setNeedsLayout() - cell?.layoutIfNeeded() - } - - return cell! - } + func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return modules.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let module = modules[indexPath.row] + + // let key = Array(cardDict.keys)[indexPath.row] + let card = cardDict[module]! + var cell = tableView.dequeueReusableCell(withIdentifier: "card\(module)") + + if cell == nil { + // no cell in reuse pool + cell = UITableViewCell(style: .default, reuseIdentifier: "card\(module)") + cell!.contentView.addSubview(card) + card.sizeToFit() + let cellHeight: CGFloat = 240 + card.snp.makeConstraints { make in + make.top.equalToSuperview().offset(10) + make.bottom.equalToSuperview().offset(-10) + make.height.equalTo(cellHeight) + if isiPad { + make.centerX.equalToSuperview() + make.width.equalToSuperview().multipliedBy(0.6) + } else { + make.left.equalToSuperview().offset(15) + make.right.equalToSuperview().offset(-15) + } + } + cellHeights.append(cellHeight) + cell?.setNeedsLayout() + cell?.layoutIfNeeded() + } + + return cell! + } } extension FavViewController: UITableViewDelegate { - func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - return cellHeights[indexPath.row] - } - - func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - if section == 0 { - return headerView - } - return nil - } - - func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - return headerView.systemLayoutSizeFitting(.init(width: CGFloat.infinity, height: CGFloat.infinity)).height - } + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return cellHeights[indexPath.row] + } + + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + if section == 0 { + return headerView + } + return nil + } + + func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + return headerView.systemLayoutSizeFitting(.init(width: CGFloat.infinity, height: CGFloat.infinity)).height + } } extension FavViewController: CardViewDelegate { - func cardIsTapped(card: CardView) { - if TwTUser.shared.token == nil { - card.superVC = nil - showLoginView(success: { - // card.superVC = self - }) - } else { - card.superVC = self - } - } + func cardIsTapped(card: CardView) { + if TwTUser.shared.token == nil { + card.superVC = nil + showLoginView(success: { + // card.superVC = self + }) + } else { + card.superVC = self + } + } } diff --git a/WePeiYang/Favorite/View/FeedBackCard.swift b/WePeiYang/Favorite/View/FeedBackCard.swift new file mode 100644 index 0000000..867b50f --- /dev/null +++ b/WePeiYang/Favorite/View/FeedBackCard.swift @@ -0,0 +1,59 @@ +// +// FeedBackCard.swift +// WePeiYang +// +// Created by Zrzz on 2020/11/30. +// Copyright © 2020 twtstudio. All rights reserved. +// + +import UIKit + +class FeedBackCard: CardView { + private let titleLabel = UILabel() + private let imageView = UIImageView() + + override func initialize() { + super.initialize() + + let padding: CGFloat = 20 + titleLabel.text = "校务专区" + titleLabel.font = UIFont.systemFont(ofSize: 25, weight: UIFont.Weight.semibold) + titleLabel.textColor = .black + titleLabel.sizeToFit() + + self.addSubview(titleLabel) + titleLabel.snp.makeConstraints { make in + make.left.top.equalToSuperview().offset(padding) + make.width.equalTo(200) + make.height.equalTo(30) + } + + + + imageView.image = UIImage(named: "feedback_banner") + imageView.contentMode = .scaleAspectFit + self.addSubview(imageView) + imageView.snp.makeConstraints { (make) in + make.left.equalToSuperview().offset(padding) + make.right.equalToSuperview().offset(-padding) + make.top.equalTo(titleLabel.snp.bottom).offset(padding) + make.width.equalToSuperview().offset(-2 * padding) + make.bottom.equalToSuperview().offset(-padding) + } + + self.backgroundColor = .white + layout(rect: self.frame) + } + + override func layout(rect: CGRect) { + let padding: CGFloat = 20 + + let layerWidth = rect.width - 2*padding + let layerHeight = rect.height - 2*padding - 40 + + blankView.frame = CGRect(x: padding, y: padding + 30 + 15, width: layerWidth, height: layerHeight) + + super.layout(rect: rect) + } + +} diff --git a/WePeiYang/FeedBack/Controller/FBReplyDetailTVController.swift b/WePeiYang/FeedBack/Controller/FBReplyDetailTVController.swift index d61e15c..3bfe76b 100644 --- a/WePeiYang/FeedBack/Controller/FBReplyDetailTVController.swift +++ b/WePeiYang/FeedBack/Controller/FBReplyDetailTVController.swift @@ -9,57 +9,57 @@ import UIKit class FBReplyDetailTVController: UITableViewController { - - var replies: [FBCommentModel] = [] - var isOwner: Bool = false - - let replyCellID = "feedBackRDVCCell" - - convenience init(reply: FBCommentModel, isOwner: Bool) { - self.init() - self.replies = [reply] - self.isOwner = isOwner - } - - convenience init(replies: [FBCommentModel], isOwner: Bool) { - self.init() - self.replies = replies - self.isOwner = isOwner - } - - override func viewDidLoad() { - super.viewDidLoad() - title = "回复详情" - view.backgroundColor = UIColor(hex6: 0xf6f6f6) - tableView.register(FBReplyDetailTableViewCell.self, forCellReuseIdentifier: replyCellID) - tableView.separatorStyle = .none - - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return replies.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: replyCellID, for: indexPath) as! FBReplyDetailTableViewCell - cell.update(comment: replies[indexPath.row]) - return cell - } - - override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - let str = (replies[indexPath.row].contain ?? "").htmlToAttributedString - return 60 + str!.getSuitableHeight(font: .systemFont(ofSize: 14), setWidth: SCREEN.width * 0.8, numbersOfLines: 0) - } - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - if isOwner { - let rateView = FBRateCommentView() - var config = SwiftMessages.defaultConfig - config.presentationStyle = .center - config.duration = .forever - config.dimMode = .blur(style: .dark, alpha: 1, interactive: true) - config.presentationContext = .window(windowLevel: .normal) - SwiftMessages.show(config: config, view: rateView) - } - } + + var replies: [FBCommentModel] = [] + var isOwner: Bool = false + + let replyCellID = "feedBackRDVCCell" + + convenience init(reply: FBCommentModel, isOwner: Bool) { + self.init() + self.replies = [reply] + self.isOwner = isOwner + } + + convenience init(replies: [FBCommentModel], isOwner: Bool) { + self.init() + self.replies = replies + self.isOwner = isOwner + } + + override func viewDidLoad() { + super.viewDidLoad() + title = "回复详情" + view.backgroundColor = UIColor(hex6: 0xf6f6f6) + tableView.register(FBReplyDetailTableViewCell.self, forCellReuseIdentifier: replyCellID) + tableView.separatorStyle = .none + + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return replies.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: replyCellID, for: indexPath) as! FBReplyDetailTableViewCell + cell.update(comment: replies[indexPath.row]) + return cell + } + + override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + let str = (replies[indexPath.row].contain ?? "").htmlToAttributedString + return 60 + str!.getSuitableHeight(font: .systemFont(ofSize: 14), setWidth: SCREEN.width * 0.8, numbersOfLines: 0) + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + if isOwner { + let rateView = FBRateCommentView() + var config = SwiftMessages.defaultConfig + config.presentationStyle = .center + config.duration = .forever + config.dimMode = .blur(style: .dark, alpha: 1, interactive: true) + config.presentationContext = .window(windowLevel: .normal) + SwiftMessages.show(config: config, view: rateView) + } + } } diff --git a/WePeiYang/FeedBack/Controller/FeedBackMainViewController.swift b/WePeiYang/FeedBack/Controller/FeedBackMainViewController.swift index 5e16ec5..a72320d 100644 --- a/WePeiYang/FeedBack/Controller/FeedBackMainViewController.swift +++ b/WePeiYang/FeedBack/Controller/FeedBackMainViewController.swift @@ -26,10 +26,10 @@ class FeedBackMainViewController: UIViewController { // MARK: - Data var availableTags = [ - FBTagModel(id: 0, name: "教务处", children: nil), - FBTagModel(id: 0, name: "后保部", children: nil), - FBTagModel(id: 0, name: "场馆中心", children: nil), - FBTagModel(id: 0, name: "其他", children: nil), + FBTagModel(id: 0, name: "教务处", children: nil), + FBTagModel(id: 0, name: "后保部", children: nil), + FBTagModel(id: 0, name: "场馆中心", children: nil), + FBTagModel(id: 0, name: "其他", children: nil), ] { didSet { tagCollectionView.reloadData() @@ -37,11 +37,11 @@ class FeedBackMainViewController: UIViewController { } } // means no tag is selected - var selectedTag: Int = -1 { - didSet { - self.tableView.mj_header.beginRefreshing() - } - } + var selectedTag: Int = -1 { + didSet { + self.tableView.mj_header.beginRefreshing() + } + } var questions = [FBQuestionModel]() { didSet { @@ -58,14 +58,14 @@ class FeedBackMainViewController: UIViewController { tableView.mj_footer.beginRefreshing() FBQuestionHelper.searchQuestions(tags: availableTags.map{ $0.id ?? 0 }.filter{ $0 != 0 }, string: "", limits: 10, page: curPage) { (result) in switch result { - case .success(let questions): - if questions.count != 0 { - self.questions += questions - } else { - self.tableView.mj_footer.endRefreshingWithNoMoreData() - } - case .failure(let error): - print(error) + case .success(let questions): + if questions.count != 0 { + self.questions += questions + } else { + self.tableView.mj_footer.endRefreshingWithNoMoreData() + } + case .failure(let error): + print(error) } } } @@ -97,8 +97,8 @@ class FeedBackMainViewController: UIViewController { extension FeedBackMainViewController: UISearchControllerDelegate { private func setUp() { - // navigationController?.isNavigationBarHidden = false - // navigationController?.navigationBar.isTranslucent = false +// self.navigationController?.navigationBar.isTranslucent = false + hidesBottomBarWhenPushed = true view.backgroundColor = .white navigationItem.title = "校务平台" @@ -192,9 +192,9 @@ 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) + let addVC = FBNewQuestionViewController() + addVC.availableTags = self.availableTags + self.present(addVC, animated: true, completion: nil) } view.addSubview(floaty) @@ -265,22 +265,22 @@ extension FeedBackMainViewController { private func loadData() { FBTagsHelper.tagGet { (results) in switch results { - case .success(let tags): - if tags.count == 1 { - self.availableTags = tags[0].children ?? [] - } - case .failure(let error): - print(error) + case .success(let tags): + if tags.count == 1 { + self.availableTags = tags[0].children ?? [] + } + case .failure(let error): + print(error) } } FBUserHelper.userIdGet { (result) in switch result { - case .success(let uid): - TwTUser.shared.feedbackID = uid - TwTUser.shared.save() - case .failure(let error): - print(error) + case .success(let uid): + TwTUser.shared.feedbackID = uid + TwTUser.shared.save() + case .failure(let error): + print(error) } } } @@ -301,14 +301,14 @@ extension FeedBackMainViewController { FBQuestionHelper.searchQuestions(tags: availableTags.map{ $0.id ?? 0 }.filter{ $0 != 0 }, string: "", limits: 10, page: 1) { (result) in switch result { - case .success(let questions): - self.questions = questions - self.curPage = 1 - if self.tableView.mj_header.isRefreshing { - self.tableView.mj_header.endRefreshing() - } - case .failure(let error): - print(error) + case .success(let questions): + self.questions = questions + self.curPage = 1 + if self.tableView.mj_header.isRefreshing { + self.tableView.mj_header.endRefreshing() + } + case .failure(let error): + print(error) } } } diff --git a/WePeiYang/FeedBack/Model/FBCommentHelper.swift b/WePeiYang/FeedBack/Model/FBCommentHelper.swift index 3ba7cde..6ba026d 100644 --- a/WePeiYang/FeedBack/Model/FBCommentHelper.swift +++ b/WePeiYang/FeedBack/Model/FBCommentHelper.swift @@ -90,7 +90,7 @@ class FBCommentHelper { } } - static func commentAnswer (answerId: Int, score: Float, commit: String, completion: @escaping (Result) -> Void) { + static func commentAnswer (answerId: Int, score: Int, commit: String, completion: @escaping (Result) -> Void) { let paras = ["user_id": FB_USER_ID, "answer_id": answerId, "score": score, "commit": commit] as [String: Any] Alamofire.request(FB_BASE_USER_URL + "answer/commit", method: .post, parameters: paras, encoding: JSONEncoding.default) .validate().responseJSON{(response) in diff --git a/WePeiYang/FeedBack/View/CellView/FBReplyDetailTableViewCell.swift b/WePeiYang/FeedBack/View/CellView/FBReplyDetailTableViewCell.swift index 557b0cf..ffe4b08 100644 --- a/WePeiYang/FeedBack/View/CellView/FBReplyDetailTableViewCell.swift +++ b/WePeiYang/FeedBack/View/CellView/FBReplyDetailTableViewCell.swift @@ -9,126 +9,126 @@ import UIKit class FBReplyDetailTableViewCell: UITableViewCell { - var bgView: UIView! - var userImgView: UIImageView! // user头像 - var userNameLabel: UILabel! // user名称 - var officialLabel: UILabel! // 官方的标签 - var contentLabel: UILabel! // 内容 - var timeLabel: UILabel! // 时间 - - var commentID: Int! - - var starRateView: FBStarRateView! - - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - - backgroundColor = UIColor(hex6: 0xf6f6f6) - selectionStyle = .none - - bgView = UIView() - contentView.addSubview(bgView) - bgView.backgroundColor = .white - bgView.addCornerRadius(15) - bgView.snp.makeConstraints { (make) in - make.top.equalTo(contentView).offset(5) - make.bottom.equalTo(contentView).offset(-5) - make.left.equalTo(contentView).offset(10) - make.right.equalTo(contentView).offset(-10) - } - - userImgView = UIImageView() - userImgView.image = UIImage(named: "feedback_user") - userImgView.backgroundColor = .white - bgView.addSubview(userImgView) - userImgView.snp.makeConstraints { (make) in - make.left.top.equalTo(bgView).offset(10) - make.width.height.equalTo(20) - } - - userNameLabel = UILabel() - userNameLabel.font = .boldSystemFont(ofSize: 14) - userNameLabel.backgroundColor = .white - bgView.addSubview(userNameLabel) - userNameLabel.snp.makeConstraints { (make) in - make.left.equalTo(userImgView.snp.right).offset(5) - make.centerY.equalTo(userImgView) - make.height.equalTo(20) - } - - officialLabel = UILabel() - officialLabel.font = .systemFont(ofSize: 12) - bgView.addSubview(officialLabel) - officialLabel.text = "官方" - officialLabel.backgroundColor = UIColor(hex6: 0x00a1e9) - officialLabel.layer.cornerRadius = 10 - officialLabel.layer.masksToBounds = true - officialLabel.textColor = .white - officialLabel.textAlignment = .center - officialLabel.snp.makeConstraints { (make) in - make.left.equalTo(userNameLabel.snp.right).offset(10) - make.centerY.equalTo(userImgView) - make.width.equalTo(30) - make.height.equalTo(20) - } - - starRateView = FBStarRateView(frame: CGRect(origin: .zero, size: CGSize(width: 120, height: 20)), progressImg: UIImage(named: "feedback_star_fill"), trackImg: UIImage(named: "feedback_star"))! - starRateView.show(type: .half, isInteractable: true, leastStar: 0, completion: { (score) in -// print(score) - }) - bgView.addSubview(starRateView) - - starRateView.snp.makeConstraints { (make) in - make.left.equalTo(officialLabel.snp.right).offset(5) - make.centerY.equalTo(officialLabel.snp.top) // strange - } - - contentLabel = UILabel() - contentLabel.font = .systemFont(ofSize: 14) - contentLabel.numberOfLines = 0 - contentLabel.backgroundColor = .white - bgView.addSubview(contentLabel) - contentLabel.snp.makeConstraints { (make) in - make.left.equalTo(userNameLabel.snp.left) - make.top.equalTo(userNameLabel.snp.bottom).offset(5) - make.width.equalTo(SCREEN.width * 0.8) - } - - timeLabel = UILabel() - timeLabel.font = .systemFont(ofSize: 12) - timeLabel.backgroundColor = .white - timeLabel.textColor = .gray - bgView.addSubview(timeLabel) - timeLabel.snp.makeConstraints { (make) in - make.left.equalTo(contentLabel.snp.left) - make.bottom.equalTo(self).offset(-10) - } - - } - - override func layoutIfNeeded() { - super.layoutIfNeeded() - bgView.addShadow(.black, sRadius: 3, sOpacity: 0.2, offset: (1, 1)) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - func update(comment: FBCommentModel) { - starRateView?.setScore(f: CGFloat(comment.score ?? 0)) - - userNameLabel.text = comment.adminName - userNameLabel.sizeToFit() - - contentLabel.attributedText = comment.contain?.htmlToAttributedString - contentLabel.font = .systemFont(ofSize: 14) - contentLabel.sizeToFit() - - timeLabel.text = (comment.createdAt?[0..<10] ?? "") + " " + (comment.createdAt?[11..<16] ?? "") - timeLabel.sizeToFit() - commentID = comment.id ?? 0 - - } - + var bgView: UIView! + var userImgView: UIImageView! // user头像 + var userNameLabel: UILabel! // user名称 + var officialLabel: UILabel! // 官方的标签 + var contentLabel: UILabel! // 内容 + var timeLabel: UILabel! // 时间 + + var commentID: Int! + + var starRateView: FBStarRateView! + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + backgroundColor = UIColor(hex6: 0xf6f6f6) + selectionStyle = .none + + bgView = UIView() + contentView.addSubview(bgView) + bgView.backgroundColor = .white + bgView.addCornerRadius(15) + bgView.snp.makeConstraints { (make) in + make.top.equalTo(contentView).offset(5) + make.bottom.equalTo(contentView).offset(-5) + make.left.equalTo(contentView).offset(10) + make.right.equalTo(contentView).offset(-10) + } + + userImgView = UIImageView() + userImgView.image = UIImage(named: "feedback_user") + userImgView.backgroundColor = .white + bgView.addSubview(userImgView) + userImgView.snp.makeConstraints { (make) in + make.left.top.equalTo(bgView).offset(10) + make.width.height.equalTo(20) + } + + userNameLabel = UILabel() + userNameLabel.font = .boldSystemFont(ofSize: 14) + userNameLabel.backgroundColor = .white + bgView.addSubview(userNameLabel) + userNameLabel.snp.makeConstraints { (make) in + make.left.equalTo(userImgView.snp.right).offset(5) + make.centerY.equalTo(userImgView) + make.height.equalTo(20) + } + + officialLabel = UILabel() + officialLabel.font = .systemFont(ofSize: 12) + bgView.addSubview(officialLabel) + officialLabel.text = "官方" + officialLabel.backgroundColor = UIColor(hex6: 0x00a1e9) + officialLabel.layer.cornerRadius = 10 + officialLabel.layer.masksToBounds = true + officialLabel.textColor = .white + officialLabel.textAlignment = .center + officialLabel.snp.makeConstraints { (make) in + make.left.equalTo(userNameLabel.snp.right).offset(10) + make.centerY.equalTo(userImgView) + make.width.equalTo(30) + make.height.equalTo(20) + } + + starRateView = FBStarRateView(frame: CGRect(origin: .zero, size: CGSize(width: 120, height: 20)), progressImg: UIImage(named: "feedback_star_fill"), trackImg: UIImage(named: "feedback_star"))! + starRateView.show(type: .half, isInteractable: true, leastStar: 0, completion: { (score) in + // print(score) + }) + bgView.addSubview(starRateView) + + starRateView.snp.makeConstraints { (make) in + make.left.equalTo(officialLabel.snp.right).offset(5) + make.centerY.equalTo(officialLabel.snp.top) // strange + } + + contentLabel = UILabel() + contentLabel.font = .systemFont(ofSize: 14) + contentLabel.numberOfLines = 0 + contentLabel.backgroundColor = .white + bgView.addSubview(contentLabel) + contentLabel.snp.makeConstraints { (make) in + make.left.equalTo(userNameLabel.snp.left) + make.top.equalTo(userNameLabel.snp.bottom).offset(5) + make.width.equalTo(SCREEN.width * 0.8) + } + + timeLabel = UILabel() + timeLabel.font = .systemFont(ofSize: 12) + timeLabel.backgroundColor = .white + timeLabel.textColor = .gray + bgView.addSubview(timeLabel) + timeLabel.snp.makeConstraints { (make) in + make.left.equalTo(contentLabel.snp.left) + make.bottom.equalTo(self).offset(-10) + } + + } + + override func layoutIfNeeded() { + super.layoutIfNeeded() + bgView.addShadow(.black, sRadius: 3, sOpacity: 0.2, offset: (1, 1)) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func update(comment: FBCommentModel) { + starRateView?.setScore(f: CGFloat(comment.score ?? 0)) + + userNameLabel.text = comment.adminName + userNameLabel.sizeToFit() + + contentLabel.attributedText = comment.contain?.htmlToAttributedString + contentLabel.font = .systemFont(ofSize: 14) + contentLabel.sizeToFit() + + timeLabel.text = (comment.createdAt?[0..<10] ?? "") + " " + (comment.createdAt?[11..<16] ?? "") + timeLabel.sizeToFit() + commentID = comment.id ?? 0 + + } + } diff --git a/WePeiYang/FeedBack/View/CellView/FBReplyTableViewCell.swift b/WePeiYang/FeedBack/View/CellView/FBReplyTableViewCell.swift index 2d454ca..8216584 100644 --- a/WePeiYang/FeedBack/View/CellView/FBReplyTableViewCell.swift +++ b/WePeiYang/FeedBack/View/CellView/FBReplyTableViewCell.swift @@ -10,191 +10,191 @@ import UIKit import WebKit class FBReplyTableViewCell: UITableViewCell { - - var bgView: UIView! - var userImgView: UIImageView! // user头像 - var userNameLabel: UILabel! // user名称 - var officialLabel: UILabel! // 官方的标签 - var contentLabel: UILabel! // 内容 - var timeLabel: UILabel! // 时间 - var likesBtn: UIButton! // 点赞图标 - - var likes: Int! { - didSet { - likesLabel.text = likes.description - } - } - var likesLabel: UILabel! // 点赞Label - var isLiked: Bool! { - didSet { - likesBtn.setImage(UIImage(named: isLiked ? "feedback_thumb_up_fill" : "feedback_thumb_up"), for: .normal) - } - } - var commentID: Int! - - var starRateView: FBStarRateView! - - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - - backgroundColor = UIColor(hex6: 0xf6f6f6) - selectionStyle = .none - - bgView = UIView() - contentView.addSubview(bgView) - bgView.backgroundColor = .white - bgView.addCornerRadius(15) - bgView.snp.makeConstraints { (make) in - make.top.equalTo(contentView).offset(5) - make.bottom.equalTo(contentView).offset(-5) - make.left.equalTo(contentView).offset(10) - make.right.equalTo(contentView).offset(-10) - } - - userImgView = UIImageView() - userImgView.image = UIImage(named: "feedback_user") - userImgView.backgroundColor = .white - bgView.addSubview(userImgView) - userImgView.snp.makeConstraints { (make) in - make.left.top.equalTo(bgView).offset(10) - make.width.height.equalTo(20) - } - - userNameLabel = UILabel() - userNameLabel.font = .boldSystemFont(ofSize: 14) - userNameLabel.backgroundColor = .white - bgView.addSubview(userNameLabel) - userNameLabel.snp.makeConstraints { (make) in - make.left.equalTo(userImgView.snp.right).offset(5) - make.centerY.equalTo(userImgView) - make.height.equalTo(20) - } - - officialLabel = UILabel() - officialLabel.font = .systemFont(ofSize: 12) - bgView.addSubview(officialLabel) - officialLabel.text = "官方" - officialLabel.backgroundColor = UIColor(hex6: 0x00a1e9) - officialLabel.layer.cornerRadius = 10 - officialLabel.layer.masksToBounds = true - officialLabel.textColor = .white - officialLabel.textAlignment = .center - officialLabel.snp.makeConstraints { (make) in - make.left.equalTo(userNameLabel.snp.right).offset(10) - make.centerY.equalTo(userImgView) - make.width.equalTo(30) - make.height.equalTo(20) - } - - starRateView = FBStarRateView(frame: CGRect(origin: .zero, size: CGSize(width: 120, height: 20)), progressImg: UIImage(named: "feedback_star_fill"), trackImg: UIImage(named: "feedback_star"))! - starRateView.show(type: .half, isInteractable: true, leastStar: 0, completion: { (score) in -// print(score) - }) - bgView.addSubview(starRateView) - - starRateView.snp.makeConstraints { (make) in - make.left.equalTo(officialLabel.snp.right).offset(5) - make.centerY.equalTo(officialLabel.snp.top) // strange - } - - contentLabel = UILabel() - contentLabel.font = .systemFont(ofSize: 14) - contentLabel.backgroundColor = .white - bgView.addSubview(contentLabel) - contentLabel.snp.makeConstraints { (make) in - make.left.equalTo(userNameLabel.snp.left) - make.top.equalTo(userNameLabel.snp.bottom).offset(5) - make.width.equalTo(SCREEN.width * 0.8) - } - - timeLabel = UILabel() - timeLabel.font = .systemFont(ofSize: 12) - timeLabel.backgroundColor = .white - timeLabel.textColor = .gray - bgView.addSubview(timeLabel) - timeLabel.snp.makeConstraints { (make) in - make.left.equalTo(contentLabel.snp.left) - make.bottom.equalTo(self).offset(-10) - } - - likesBtn = UIButton() - likesBtn.tag = 0 - bgView.addSubview(likesBtn) - likesBtn.snp.makeConstraints { (make) in - make.centerY.equalTo(timeLabel) - make.left.equalTo(timeLabel.snp.right).offset(5) - make.width.height.equalTo(15) - } - - likesLabel = UILabel() - likesLabel.font = .systemFont(ofSize: 12) - likesLabel.backgroundColor = .white - bgView.addSubview(likesLabel) - likesLabel.snp.makeConstraints { (make) in - make.centerY.equalTo(timeLabel) - make.left.equalTo(likesBtn.snp.right).offset(5) - } - } - - override func layoutIfNeeded() { - super.layoutIfNeeded() - bgView.addShadow(.black, sRadius: 3, sOpacity: 0.2, offset: (1, 1)) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - func update(comment: FBCommentModel) { - starRateView?.setScore(f: CGFloat(comment.score ?? 0)) - - userNameLabel.text = comment.adminName - userNameLabel.sizeToFit() - - contentLabel.attributedText = comment.contain?.htmlToAttributedString - contentLabel.font = .systemFont(ofSize: 14) - contentLabel.numberOfLines = 4 - contentLabel.sizeToFit() - - timeLabel.text = (comment.createdAt?[0..<10] ?? "") + " " + (comment.createdAt?[11..<16] ?? "") - timeLabel.sizeToFit() - commentID = comment.id ?? 0 - likesBtn.removeTarget(nil, action: nil, for: .allEvents) - likesBtn.addTarget(self, action: #selector(likeOrDislike), for: .touchUpInside) - isLiked = comment.isLiked - likes = comment.likes ?? 0 - likesLabel.sizeToFit() - } - - @objc func likeOrDislike() { - if isLiked == false { - likesBtn.setImage(UIImage(named: "feedback_thumb_up_fill"), for: .normal) - FBCommentHelper.likeComment(type: .answer, commentId: commentID) { (result) in - switch result { + + var bgView: UIView! + var userImgView: UIImageView! // user头像 + var userNameLabel: UILabel! // user名称 + var officialLabel: UILabel! // 官方的标签 + var contentLabel: UILabel! // 内容 + var timeLabel: UILabel! // 时间 + var likesBtn: UIButton! // 点赞图标 + + var likes: Int! { + didSet { + likesLabel.text = likes.description + } + } + var likesLabel: UILabel! // 点赞Label + var isLiked: Bool! { + didSet { + likesBtn.setImage(UIImage(named: isLiked ? "feedback_thumb_up_fill" : "feedback_thumb_up"), for: .normal) + } + } + var commentID: Int! + + var starRateView: FBStarRateView! + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + backgroundColor = UIColor(hex6: 0xf6f6f6) + selectionStyle = .none + + bgView = UIView() + contentView.addSubview(bgView) + bgView.backgroundColor = .white + bgView.addCornerRadius(15) + bgView.snp.makeConstraints { (make) in + make.top.equalTo(contentView).offset(5) + make.bottom.equalTo(contentView).offset(-5) + make.left.equalTo(contentView).offset(10) + make.right.equalTo(contentView).offset(-10) + } + + userImgView = UIImageView() + userImgView.image = UIImage(named: "feedback_user") + userImgView.backgroundColor = .white + bgView.addSubview(userImgView) + userImgView.snp.makeConstraints { (make) in + make.left.top.equalTo(bgView).offset(10) + make.width.height.equalTo(20) + } + + userNameLabel = UILabel() + userNameLabel.font = .boldSystemFont(ofSize: 14) + userNameLabel.backgroundColor = .white + bgView.addSubview(userNameLabel) + userNameLabel.snp.makeConstraints { (make) in + make.left.equalTo(userImgView.snp.right).offset(5) + make.centerY.equalTo(userImgView) + make.height.equalTo(20) + } + + officialLabel = UILabel() + officialLabel.font = .systemFont(ofSize: 12) + bgView.addSubview(officialLabel) + officialLabel.text = "官方" + officialLabel.backgroundColor = UIColor(hex6: 0x00a1e9) + officialLabel.layer.cornerRadius = 10 + officialLabel.layer.masksToBounds = true + officialLabel.textColor = .white + officialLabel.textAlignment = .center + officialLabel.snp.makeConstraints { (make) in + make.left.equalTo(userNameLabel.snp.right).offset(10) + make.centerY.equalTo(userImgView) + make.width.equalTo(30) + make.height.equalTo(20) + } + + starRateView = FBStarRateView(frame: CGRect(origin: .zero, size: CGSize(width: 120, height: 20)), progressImg: UIImage(named: "feedback_star_fill"), trackImg: UIImage(named: "feedback_star"))! + starRateView.show(type: .half, isInteractable: true, leastStar: 0, completion: { (score) in + // print(score) + }) + bgView.addSubview(starRateView) + + starRateView.snp.makeConstraints { (make) in + make.left.equalTo(officialLabel.snp.right).offset(5) + make.centerY.equalTo(officialLabel.snp.top) // strange + } + + contentLabel = UILabel() + contentLabel.font = .systemFont(ofSize: 14) + contentLabel.backgroundColor = .white + bgView.addSubview(contentLabel) + contentLabel.snp.makeConstraints { (make) in + make.left.equalTo(userNameLabel.snp.left) + make.top.equalTo(userNameLabel.snp.bottom).offset(5) + make.width.equalTo(SCREEN.width * 0.8) + } + + timeLabel = UILabel() + timeLabel.font = .systemFont(ofSize: 12) + timeLabel.backgroundColor = .white + timeLabel.textColor = .gray + bgView.addSubview(timeLabel) + timeLabel.snp.makeConstraints { (make) in + make.left.equalTo(contentLabel.snp.left) + make.bottom.equalTo(self).offset(-10) + } + + likesBtn = UIButton() + likesBtn.tag = 0 + bgView.addSubview(likesBtn) + likesBtn.snp.makeConstraints { (make) in + make.centerY.equalTo(timeLabel) + make.left.equalTo(timeLabel.snp.right).offset(5) + make.width.height.equalTo(15) + } + + likesLabel = UILabel() + likesLabel.font = .systemFont(ofSize: 12) + likesLabel.backgroundColor = .white + bgView.addSubview(likesLabel) + likesLabel.snp.makeConstraints { (make) in + make.centerY.equalTo(timeLabel) + make.left.equalTo(likesBtn.snp.right).offset(5) + } + } + + override func layoutIfNeeded() { + super.layoutIfNeeded() + bgView.addShadow(.black, sRadius: 3, sOpacity: 0.2, offset: (1, 1)) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func update(comment: FBCommentModel) { + starRateView?.setScore(f: CGFloat(comment.score ?? 0)) + + userNameLabel.text = comment.adminName + userNameLabel.sizeToFit() + + contentLabel.attributedText = comment.contain?.htmlToAttributedString + contentLabel.font = .systemFont(ofSize: 14) + contentLabel.numberOfLines = 4 + contentLabel.sizeToFit() + + timeLabel.text = (comment.createdAt?[0..<10] ?? "") + " " + (comment.createdAt?[11..<16] ?? "") + timeLabel.sizeToFit() + commentID = comment.id ?? 0 + likesBtn.removeTarget(nil, action: nil, for: .allEvents) + likesBtn.addTarget(self, action: #selector(likeOrDislike), for: .touchUpInside) + isLiked = comment.isLiked + likes = comment.likes ?? 0 + likesLabel.sizeToFit() + } + + @objc func likeOrDislike() { + if isLiked == false { + likesBtn.setImage(UIImage(named: "feedback_thumb_up_fill"), for: .normal) + FBCommentHelper.likeComment(type: .answer, commentId: commentID) { (result) in + switch result { case .success(let str): - SwiftMessages.showSuccessMessage(body: str) + SwiftMessages.showSuccessMessage(body: str) case .failure(let error): - print(error) - } - } - isLiked = true - likes += 1 - - } else { - likesBtn.setImage(UIImage(named: "feedback_thumb_up"), for: .normal) - FBCommentHelper.dislikeComment(type: .answer, commentId: commentID) { (result) in - switch result { + print(error) + } + } + isLiked = true + likes += 1 + + } else { + likesBtn.setImage(UIImage(named: "feedback_thumb_up"), for: .normal) + FBCommentHelper.dislikeComment(type: .answer, commentId: commentID) { (result) in + switch result { case .success(let str): - SwiftMessages.showSuccessMessage(body: str) + SwiftMessages.showSuccessMessage(body: str) case .failure(let error): - print(error) - } - } - isLiked = false - likes -= 1 - } - } - - - + print(error) + } + } + isLiked = false + likes -= 1 + } + } + + + } diff --git a/WePeiYang/FeedBack/View/FBRateCommentView.swift b/WePeiYang/FeedBack/View/FBRateCommentView.swift index d9718ff..7c67ce8 100644 --- a/WePeiYang/FeedBack/View/FBRateCommentView.swift +++ b/WePeiYang/FeedBack/View/FBRateCommentView.swift @@ -9,131 +9,131 @@ import UIKit class FBRateCommentView: MessageView { - private var starRateView: FBStarRateView! - private var commentTextView: UITextView! - - private var score: Float = 0 - - var successHandler: (() -> Void)? - var failureHandler: (() -> Void)? - - init() { - super.init(frame: CGRect(x: 30, y: UIScreen.main.bounds.height*0.2, width: UIScreen.main.bounds.width-60, height: 300)) - setup() - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - func setup() { - let contentView = UIView() - contentView.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 0.97, alpha: 1.00) - self.backgroundColor = .clear - installBackgroundView(contentView) - configureBackgroundView(width: 250) - contentView.snp.makeConstraints { make in - if isiPad { - make.top.equalToSuperview().offset(30) - make.bottom.equalToSuperview().offset(-30) - make.width.equalToSuperview().multipliedBy(0.6) - make.left.equalTo(deviceWidth*0.2) - make.right.equalTo(-deviceWidth*0.2) - } else { - make.top.left.equalToSuperview().offset(30) - make.bottom.right.equalToSuperview().offset(-30) - make.width.equalTo(250) - } - make.height.equalTo(300) - } - - titleLabel = UILabel() - titleLabel?.text = "评价回复" - titleLabel?.font = .boldSystemFont(ofSize: 16) - titleLabel?.sizeToFit() - contentView.addSubview(titleLabel!) - titleLabel?.snp.makeConstraints({ (make) in - make.top.centerX.equalToSuperview() - }) - - starRateView = FBStarRateView(frame: CGRect(origin: .zero, size: CGSize(width: 170, height: 30)), progressImg: UIImage(named: "feedback_star_fill"), trackImg: UIImage(named: "feedback_star")) - starRateView.show(type: .half, isInteractable: true, leastStar: 0) { (score) in - self.score = Float(score) - print(score) - } - contentView.addSubview(starRateView) - starRateView.snp.makeConstraints { (make) in - make.top.equalTo(titleLabel!.snp.bottom).offset(10) - make.centerX.equalToSuperview() - make.width.equalTo(170) - make.height.equalTo(30) - } - - commentTextView = UITextView() - commentTextView.layer.borderWidth = 1 - commentTextView.layer.borderColor = UIColor(hex6: 0xf4f4f4).cgColor - commentTextView.layer.cornerRadius = 5 - commentTextView.layer.masksToBounds = true - commentTextView.textContainerInset = UIEdgeInsets(top: 5, left: 7, bottom: 5, right: 5) - commentTextView.font = .systemFont(ofSize: 14) - contentView.addSubview(commentTextView) - commentTextView.snp.makeConstraints { (make) in - make.top.equalTo(starRateView.snp.bottom).offset(15) - make.centerX.equalToSuperview() - make.width.equalToSuperview().multipliedBy(0.8) - make.height.equalToSuperview().multipliedBy(0.5) - } - - button = UIButton() - button?.backgroundColor = UIColor(hex6: 0x00a1e9) - button?.addTarget(self, action: #selector(rateComment), for: .touchUpInside) - button?.setTitle("确认提交", for: .normal) - button?.layer.cornerRadius = 15 - button?.layer.masksToBounds = true - contentView.addSubview(button!) - button?.snp.makeConstraints { (make) in - make.centerX.equalToSuperview() - make.top.equalTo(commentTextView.snp.bottom).offset(15) - make.height.equalTo(35) - make.width.equalTo(100) - } - - NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil) - - backgroundView.backgroundColor = UIColor.init(white: 0.97, alpha: 1) - backgroundView.layer.cornerRadius = 10 - } - - @objc private func rateComment() { - if score == 0 || commentTextView.text.isEmpty { - let alert = UIAlertController(title: "提示", message: "信息未补充完整", preferredStyle: .alert) - let action1 = UIAlertAction(title: "好的", style: .default, handler: nil) - alert.addAction(action1) - - var topVC = UIApplication.shared.keyWindow?.rootViewController - while((topVC!.presentedViewController) != nil) { - topVC = topVC!.presentedViewController - } - topVC?.present(alert, animated: true) - } else { - SwiftMessages.showLoading() - FBCommentHelper.commentAnswer(answerId: TwTUser.shared.feedbackID ?? 0, score: score, commit: commentTextView.text) { (result) in - switch result { + private var starRateView: FBStarRateView! + private var commentTextView: UITextView! + + private var score: Float = 0 + + var successHandler: (() -> Void)? + var failureHandler: (() -> Void)? + + init() { + super.init(frame: CGRect(x: 30, y: UIScreen.main.bounds.height*0.2, width: UIScreen.main.bounds.width-60, height: 300)) + setup() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func setup() { + let contentView = UIView() + contentView.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 0.97, alpha: 1.00) + self.backgroundColor = .clear + installBackgroundView(contentView) + configureBackgroundView(width: 250) + contentView.snp.makeConstraints { make in + if isiPad { + make.top.equalToSuperview().offset(30) + make.bottom.equalToSuperview().offset(-30) + make.width.equalToSuperview().multipliedBy(0.6) + make.left.equalTo(deviceWidth*0.2) + make.right.equalTo(-deviceWidth*0.2) + } else { + make.top.left.equalToSuperview().offset(30) + make.bottom.right.equalToSuperview().offset(-30) + make.width.equalTo(250) + } + make.height.equalTo(300) + } + + titleLabel = UILabel() + titleLabel?.text = "评价回复" + titleLabel?.font = .boldSystemFont(ofSize: 16) + titleLabel?.sizeToFit() + contentView.addSubview(titleLabel!) + titleLabel?.snp.makeConstraints({ (make) in + make.top.centerX.equalToSuperview() + }) + + starRateView = FBStarRateView(frame: CGRect(origin: .zero, size: CGSize(width: 170, height: 30)), progressImg: UIImage(named: "feedback_star_fill"), trackImg: UIImage(named: "feedback_star")) + starRateView.show(type: .half, isInteractable: true, leastStar: 0) { (score) in + self.score = Float(score) + print(score) + } + contentView.addSubview(starRateView) + starRateView.snp.makeConstraints { (make) in + make.top.equalTo(titleLabel!.snp.bottom).offset(10) + make.centerX.equalToSuperview() + make.width.equalTo(170) + make.height.equalTo(30) + } + + commentTextView = UITextView() + commentTextView.layer.borderWidth = 1 + commentTextView.layer.borderColor = UIColor(hex6: 0xf4f4f4).cgColor + commentTextView.layer.cornerRadius = 5 + commentTextView.layer.masksToBounds = true + commentTextView.textContainerInset = UIEdgeInsets(top: 5, left: 7, bottom: 5, right: 5) + commentTextView.font = .systemFont(ofSize: 14) + contentView.addSubview(commentTextView) + commentTextView.snp.makeConstraints { (make) in + make.top.equalTo(starRateView.snp.bottom).offset(15) + make.centerX.equalToSuperview() + make.width.equalToSuperview().multipliedBy(0.8) + make.height.equalToSuperview().multipliedBy(0.5) + } + + button = UIButton() + button?.backgroundColor = UIColor(hex6: 0x00a1e9) + button?.addTarget(self, action: #selector(rateComment), for: .touchUpInside) + button?.setTitle("确认提交", for: .normal) + button?.layer.cornerRadius = 15 + button?.layer.masksToBounds = true + contentView.addSubview(button!) + button?.snp.makeConstraints { (make) in + make.centerX.equalToSuperview() + make.top.equalTo(commentTextView.snp.bottom).offset(15) + make.height.equalTo(35) + make.width.equalTo(100) + } + + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil) + + backgroundView.backgroundColor = UIColor.init(white: 0.97, alpha: 1) + backgroundView.layer.cornerRadius = 10 + } + + @objc private func rateComment() { + if score == 0 || commentTextView.text.isEmpty { + let alert = UIAlertController(title: "提示", message: "信息未补充完整", preferredStyle: .alert) + let action1 = UIAlertAction(title: "好的", style: .default, handler: nil) + alert.addAction(action1) + + var topVC = UIApplication.shared.keyWindow?.rootViewController + while((topVC!.presentedViewController) != nil) { + topVC = topVC!.presentedViewController + } + topVC?.present(alert, animated: true) + } else { + SwiftMessages.showLoading() + FBCommentHelper.commentAnswer(answerId: TwTUser.shared.feedbackID ?? 0, score: Int(score * 2), commit: commentTextView.text) { (result) in + switch result { case .success(_): - SwiftMessages.showSuccessMessage(body: "评价成功!") + SwiftMessages.showSuccessMessage(body: "评价成功!") case .failure(let err): - print("CommentAnswer ERROR!\n" + err.localizedDescription) - } - SwiftMessages.hideLoading() - SwiftMessages.hideAll() - } - } - } - - deinit { - NotificationCenter.default.removeObserver(self) - } + print("CommentAnswer ERROR!\n" + err.localizedDescription) + } + SwiftMessages.hideLoading() + SwiftMessages.hideAll() + } + } + } + + deinit { + NotificationCenter.default.removeObserver(self) + } } extension FBRateCommentView { @@ -143,7 +143,7 @@ extension FBRateCommentView { } self.frame.origin.y = 20 } - + @objc func keyboardWillHide(notification: Notification) { self.frame.origin.y = (UIScreen.main.bounds.height - self.frame.height)/2 } diff --git a/WePeiYang/FeedBack/View/FBStarRateView.swift b/WePeiYang/FeedBack/View/FBStarRateView.swift index a62bbda..2088619 100644 --- a/WePeiYang/FeedBack/View/FBStarRateView.swift +++ b/WePeiYang/FeedBack/View/FBStarRateView.swift @@ -71,8 +71,18 @@ public class FBStarRateView: UIView { // MARK: - 对象实例化 public convenience init?(frame: CGRect, progressImg: UIImage?, trackImg: UIImage?) { + let width = frame.size.width + let height = frame.size.height + var computedSpace: CGFloat = 0 + if height * 5 <= width { + computedSpace = (width - height * 5) / 4 + } else { + // TODO: 这里还得等读完这个轮子才能写 + computedSpace = 0 + } + - self.init(frame:frame, totalStarCount:5.0, currentStarCount:0.0, starSpace:5.0, progressImg: progressImg, trackImg: trackImg) + self.init(frame:frame, totalStarCount:5.0, currentStarCount:0.0, starSpace: computedSpace, progressImg: progressImg, trackImg: trackImg) } public init?(frame:CGRect, totalStarCount:CGFloat, currentStarCount:CGFloat, starSpace:CGFloat, progressImg: UIImage?, trackImg: UIImage?) { @@ -86,7 +96,7 @@ public class FBStarRateView: UIView { self.currentStarCount = currentStarCount - + self.starSpace = starSpace unStarView = setupStarView(trackImg!) diff --git a/WePeiYang/Shared/UI_Fundamentals/CardView.swift b/WePeiYang/Shared/UI_Fundamentals/CardView.swift index 4c50a50..6094b34 100644 --- a/WePeiYang/Shared/UI_Fundamentals/CardView.swift +++ b/WePeiYang/Shared/UI_Fundamentals/CardView.swift @@ -191,7 +191,7 @@ extension CardView { detailVC.modalPresentationStyle = .fullScreen superVC.present(detailVC, animated: true, completion: nil) } else if shouldPushDetail { - let detailVC = detailVC.init() + let detailVC = UINavigationController(rootViewController: detailVC.init()) detailVC.hidesBottomBarWhenPushed = true superVC.navigationController?.delegate = self superVC.navigationController?.pushViewController(detailVC, animated: true) diff --git a/WePeiYang/Shared/Utilities/ModuleStateManager.swift b/WePeiYang/Shared/Utilities/ModuleStateManager.swift index cc1f2e7..5f05fb1 100644 --- a/WePeiYang/Shared/Utilities/ModuleStateManager.swift +++ b/WePeiYang/Shared/Utilities/ModuleStateManager.swift @@ -9,12 +9,14 @@ import Foundation enum Module: String, CaseIterable { + case feedback = "校务专区" case classtable = "课程表" case gpa = "GPA" case library = "图书馆" case ecard = "校园卡" case exam = "考表" case code = "活动" + } let ModuleArrangementKey = "ModuleArrangementKey" @@ -26,7 +28,7 @@ struct ModuleStateManager { index += 1 modules[module] = index } - + if let dict = UserDefaults.standard.dictionary(forKey: ModuleArrangementKey) as? [String: Int] { for item in dict { let module = Module(rawValue: item.key)! @@ -41,33 +43,33 @@ struct ModuleStateManager { } } } - + return modules } - + static func getModules() -> [Module] { let modules = getAllModule() return Array(modules).filter { item in return item.value > 0 - }.sorted { a, b in - return a.value < b.value - }.map { item in - return item.key + }.sorted { a, b in + return a.value < b.value + }.map { item in + return item.key } } - + static func setModules(dict: [String: Int]) { -// var dict: [Module: Int] = [:] -// var index = 0 -// Module.allCases.forEach { module in -// index -= 1 -// dict[module] = index -// } -// -// for (idx, module) in modules.enumerated() { -// dict[module] = idx -// } - + // var dict: [Module: Int] = [:] + // var index = 0 + // Module.allCases.forEach { module in + // index -= 1 + // dict[module] = index + // } + // + // for (idx, module) in modules.enumerated() { + // dict[module] = idx + // } + UserDefaults.standard.set(dict, forKey: ModuleArrangementKey) print(UserDefaults.standard.dictionary(forKey: ModuleArrangementKey)) }