BBSSubjectAttachmentViewController.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // BBSSubjectAttachmentViewController.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2020/6/28.
  6. // Copyright © 2020 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import QuickLook
  10. import CocoaLumberjack
  11. class BBSSubjectAttachmentViewController: UITableViewController {
  12. var attachmentList:[O2BBSSubjectAttachmentInfo] = []
  13. //预览文件
  14. private lazy var previewVC: CloudFilePreviewController = {
  15. return CloudFilePreviewController()
  16. }()
  17. private lazy var viewModel: BBSViewModel = {
  18. return BBSViewModel()
  19. }()
  20. @IBAction func closeAction(_ sender: UIBarButtonItem) {
  21. self.dismiss(animated: true, completion: nil)
  22. }
  23. override func viewDidLoad() {
  24. super.viewDidLoad()
  25. self.tableView.tableFooterView = UIView()
  26. }
  27. // MARK: - Table view data source
  28. override func numberOfSections(in tableView: UITableView) -> Int {
  29. return 1
  30. }
  31. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  32. return self.attachmentList.count
  33. }
  34. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  35. if let cell = tableView.dequeueReusableCell(withIdentifier: "subjectAttachmentCell", for: indexPath) as? BBSSubjectAttachmentViewCell {
  36. cell.setAttachment(file: self.attachmentList[indexPath.row])
  37. return cell
  38. }
  39. return UITableViewCell()
  40. }
  41. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  42. tableView.deselectRow(at: indexPath, animated: false)
  43. self.showLoading()
  44. self.viewModel
  45. .downloadAttachment(att: self.attachmentList[indexPath.row])
  46. .always {
  47. self.hideLoading()
  48. }.then({ (url) in
  49. let currentURL = NSURL(fileURLWithPath: url.path)
  50. if QLPreviewController.canPreview(currentURL) {
  51. self.previewVC.currentFileURLS.removeAll()
  52. self.previewVC.currentFileURLS.append(currentURL)
  53. self.previewVC.reloadData()
  54. self.pushVC(self.previewVC)
  55. }else {
  56. self.showError(title: "当前文件类型不支持预览!")
  57. }
  58. }).catch { (err) in
  59. DDLogError(err.localizedDescription)
  60. self.showError(title: "下载文件失败!")
  61. }
  62. }
  63. }