Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Zrzzzz committed Nov 30, 2020
1 parent e733007 commit 2836f4a
Show file tree
Hide file tree
Showing 15 changed files with 1,041 additions and 1,035 deletions.
38 changes: 19 additions & 19 deletions WePeiYang/Favorite/View/FeedBackCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@
import UIKit

class FeedBackCard: CardView {
private let titleLabel = UILabel()
// 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)
}



let padding: CGFloat = 0
// 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.top.equalTo(titleLabel.snp.bottom).offset(padding)
make.width.equalToSuperview().offset(-2 * padding)
make.bottom.equalToSuperview().offset(-padding)
make.height.equalToSuperview().offset(-2 * padding)
make.center.equalToSuperview()
// make.bottom.equalToSuperview().offset(-padding)
}

self.backgroundColor = UIColor(hex6: 0x3f54af)
Expand All @@ -51,7 +51,7 @@ class FeedBackCard: CardView {
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)
blankView.frame = CGRect(x: padding, y: padding, width: layerWidth, height: layerHeight)

super.layout(rect: rect)
}
Expand Down
208 changes: 104 additions & 104 deletions WePeiYang/FeedBack/Controller/FBQuestionTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,116 +9,116 @@
import UIKit

class FBQuestionTableViewController: UITableViewController {
enum QTType {
case posted, thumbed
}
var type: QTType = .thumbed {
didSet {
FBQuestionHelper.getQuestions(type: (type == .thumbed ? .liked : .my)) { (result) in
switch result {

enum QTType {
case posted, thumbed
}

var type: QTType = .thumbed {
didSet {
FBQuestionHelper.getQuestions(type: (type == .thumbed ? .liked : .my)) { (result) in
switch result {
case .success(let questions):
self.questions = questions
self.questions = questions
case .failure(let err):
print(err)
}
}
}
}

var questions = [FBQuestionModel]() {
didSet {
tableView.reloadData()
}
}
let tableViewCellId = "feedBackQuestionTableViewCellID"
override func viewDidLoad() {
super.viewDidLoad()
tableView.backgroundColor = UIColor(hex6: 0xf6f6f6)
tableView.register(FBQuestionTableViewCell.self, forCellReuseIdentifier: tableViewCellId)
tableView.keyboardDismissMode = .onDrag
tableView.separatorStyle = .none
}
print(err)
}
}
}
}
var questions = [FBQuestionModel]() {
didSet {
tableView.reloadData()
}
}

let tableViewCellId = "feedBackQuestionTableViewCellID"

override func viewDidLoad() {
super.viewDidLoad()
tableView.backgroundColor = UIColor(hex6: 0xf6f6f6)
tableView.register(FBQuestionTableViewCell.self, forCellReuseIdentifier: tableViewCellId)
tableView.keyboardDismissMode = .onDrag
tableView.separatorStyle = .none
}
}

//MARK: - Delegate
extension FBQuestionTableViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return questions.isEmpty ? 1 : questions.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if questions.isEmpty {
let cell = UITableViewCell()
cell.textLabel?.text = type == .thumbed ? "你还没有点赞过问题哦" : "你还没有发布过问题哦"
cell.textLabel?.textAlignment = .center
cell.backgroundColor = UIColor(hex6: 0xf6f6f6)
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: tableViewCellId) as! FBQuestionTableViewCell
cell.update(by: questions[indexPath.row])
return cell
}
}


override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if questions.isEmpty {
return 60
} else {
let lineCnt = ceilf(Float(questions[indexPath.row].tags!.reduce(0, { $0 + 3 + $1.name!.count })) / 18)
return 150
+ 20 * CGFloat(lineCnt)
+ (questions[indexPath.row].datumDescription ?? "").getSuitableHeight(font: .systemFont(ofSize: 14), setWidth: SCREEN.width * 0.8, numbersOfLines: 2)
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard !questions.isEmpty else { return }

if type == .posted {
let alert = UIAlertController()
let action1 = UIAlertAction(title: "取消", style: .cancel, handler: nil)
let action2 = UIAlertAction(title: "查看", style: .default) { (_) in
let VC = FeedBackDetailViewController()
VC.questionOfthisPage = self.questions[indexPath.row]
self.navigationController?.pushViewController(VC, animated: true)
}
let action3 = UIAlertAction(title: "删除", style: .destructive) { (_) in
let alert = UIAlertController(title: "提示", message: "你正在删除这个提问\n是否真的删除?", preferredStyle: .alert)
let action1 = UIAlertAction(title: "取消", style: .cancel, handler: nil)
let action2 = UIAlertAction(title: "确定", style: .destructive) { (_) in
FBQuestionHelper.deleteMyQuestion(questionId: self.questions[indexPath.row].id ?? 0) { (result) in
switch result {
case .success(let str):
SwiftMessages.showSuccessMessage(body: str)
case .failure(let err):
print(err)
}
}
self.questions.remove(at: indexPath.row)
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return questions.isEmpty ? 1 : questions.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if questions.isEmpty {
let cell = UITableViewCell()
cell.textLabel?.text = type == .thumbed ? "你还没有点赞过问题哦" : "你还没有发布过问题哦"
cell.textLabel?.textAlignment = .center
cell.backgroundColor = UIColor(hex6: 0xf6f6f6)
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: tableViewCellId) as! FBQuestionTableViewCell
cell.update(by: questions[indexPath.row])
return cell
}
}


override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if questions.isEmpty {
return 60
} else {
let lineCnt = ceilf(Float(questions[indexPath.row].tags!.reduce(0, { $0 + 3 + $1.name!.count })) / 18)
return 150
+ 20 * CGFloat(lineCnt)
+ (questions[indexPath.row].datumDescription ?? "").getSuitableHeight(font: .systemFont(ofSize: 14), setWidth: SCREEN.width * 0.8, numbersOfLines: 2)
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard !questions.isEmpty else { return }

if type == .posted {
let alert = UIAlertController()
let action1 = UIAlertAction(title: "取消", style: .cancel, handler: nil)
let action2 = UIAlertAction(title: "查看", style: .default) { (_) in
let VC = FeedBackDetailViewController()
VC.questionOfthisPage = self.questions[indexPath.row]
self.navigationController?.pushViewController(VC, animated: true)
}
let action3 = UIAlertAction(title: "删除", style: .destructive) { (_) in
let alert = UIAlertController(title: "提示", message: "你正在删除这个提问\n是否真的删除?", preferredStyle: .alert)
let action1 = UIAlertAction(title: "取消", style: .cancel, handler: nil)
let action2 = UIAlertAction(title: "确定", style: .destructive) { (_) in
FBQuestionHelper.deleteMyQuestion(questionId: self.questions[indexPath.row].id ?? 0) { (result) in
switch result {
case .success(let str):
SwiftMessages.showSuccessMessage(body: str)
case .failure(let err):
print(err)
}
}
alert.addAction(action1)
alert.addAction(action2)

self.present(alert, animated: true)
}
alert.addAction(action1)
alert.addAction(action2)
alert.addAction(action3)

self.present(alert, animated: true)
} else {
let VC = FeedBackDetailViewController()
var question = questions[indexPath.row]
question.isLiked = true // 这里接口没有处理
VC.questionOfthisPage = question
navigationController?.pushViewController(VC, animated: true)
}
}
self.questions.remove(at: indexPath.row)
}
alert.addAction(action1)
alert.addAction(action2)

self.present(alert, animated: true)
}
alert.addAction(action1)
alert.addAction(action2)
alert.addAction(action3)

self.present(alert, animated: true)
} else {
let VC = FeedBackDetailViewController()
var question = questions[indexPath.row]
question.isLiked = true // 这里接口没有处理
VC.questionOfthisPage = question
navigationController?.pushViewController(VC, animated: true)
}
}
}

6 changes: 6 additions & 0 deletions WePeiYang/FeedBack/Controller/FBReplyDetailTVController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class FBReplyDetailTVController: UITableViewController {
config.dimMode = .blur(style: .dark, alpha: 1, interactive: true)
config.presentationContext = .window(windowLevel: .normal)
SwiftMessages.show(config: config, view: rateView)
} else {
let alert = UIAlertController(title: "提示", message: "你不是该问题的提出者,\n无法进行评分", preferredStyle: .alert)
let action1 = UIAlertAction(title: "好的", style: .default, handler: nil)
alert.addAction(action1)

self.present(alert, animated: true)
}
}
}
Loading

0 comments on commit 2836f4a

Please sign in to comment.