CloudFileBaseVC.swift 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // CloudFileBaseVC.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/11/8.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import QuickLook
  10. import CocoaLumberjack
  11. class CloudFileBaseVC: UIViewController {
  12. //预览文件
  13. private lazy var previewVC: CloudFilePreviewController = {
  14. return CloudFilePreviewController()
  15. }()
  16. lazy var cFileVM: CloudFileViewModel = {
  17. return CloudFileViewModel()
  18. }()
  19. //选中的文件夹列表
  20. var checkedFolderList: [OOFolder] = []
  21. //选中的文件列表
  22. var checkedFileList: [OOAttachment] = []
  23. //重新加载数据 子类各自实现
  24. func loadListData() {
  25. }
  26. func renameOp() {
  27. DDLogDebug("重命名")
  28. let rename = Languager.standardLanguager().string(key: "Rename")
  29. if self.checkedFolderList.count > 0 {
  30. let folder = self.checkedFolderList.first!
  31. let name = folder.name ?? ""
  32. self.showPromptAlert(title: rename, message: "\(rename) \(name)", inputText: name) { (action, result) in
  33. if result.isBlank {
  34. let msg = Languager.standardLanguager().string(key: "Empty name Error Message")
  35. self.showError(title: msg)
  36. }else {
  37. folder.name = result
  38. self.cFileVM.updateFolder(folder: folder).then({ (result) in
  39. self.loadListData()
  40. }).catch({ (error) in
  41. DDLogError(error.localizedDescription)
  42. self.showError(title: error.localizedDescription)
  43. })
  44. }
  45. }
  46. }else if self.checkedFileList.count > 0 {
  47. let file = self.checkedFileList.first!
  48. let name = file.name ?? ""
  49. self.showPromptAlert(title: rename, message: "\(rename) \(name)", inputText: name) { (action, result) in
  50. if result.isBlank {
  51. let msg = Languager.standardLanguager().string(key: "Empty name Error Message")
  52. self.showError(title: msg)
  53. }else {
  54. file.name = result
  55. self.cFileVM.updateFile(file: file).then({ (result) in
  56. self.loadListData()
  57. }).catch({ (error) in
  58. DDLogError(error.localizedDescription)
  59. self.showError(title: error.localizedDescription)
  60. })
  61. }
  62. }
  63. }
  64. }
  65. func deleteOp() {
  66. DDLogDebug("删除")
  67. let totalCount = self.checkedFileList.count + self.checkedFolderList.count
  68. if totalCount > 0 {
  69. let alert = Languager.standardLanguager().string(key: "Alert")
  70. let msg = Languager.standardLanguager().string(key: "Delete Items Confirm Message")
  71. self.showDefaultConfirm(title: alert, message: msg) { (action) in
  72. self.cFileVM.deleteCheckedList(folderList: self.checkedFolderList, fileList: self.checkedFileList)
  73. .then({ (result) in
  74. if result {
  75. self.loadListData()
  76. }
  77. }).catch({ (error) in
  78. DDLogError(error.localizedDescription)
  79. self.showError(title: error.localizedDescription)
  80. })
  81. }
  82. }
  83. }
  84. func moveOp() {
  85. DDLogDebug("移动")
  86. let totalCount = self.checkedFileList.count + self.checkedFolderList.count
  87. if totalCount > 0 {
  88. if let vc = CloudFileMoveFolderController.chooseFolderVC({ (folder) in
  89. self.showLoading()
  90. self.cFileVM.moveToFolder(folderList: self.checkedFolderList, fileList: self.checkedFileList, destFolder: folder)
  91. .then({ (result) in
  92. DDLogInfo("移动成功,\(result)")
  93. self.hideLoading()
  94. if result {
  95. self.loadListData()
  96. }
  97. }).catch { (error) in
  98. DDLogError(error.localizedDescription)
  99. self.hideLoading()
  100. }
  101. }){
  102. self.pushVC(vc)
  103. }
  104. }
  105. }
  106. func shareOp() {
  107. DDLogDebug("分享")
  108. let totalCount = self.checkedFileList.count + self.checkedFolderList.count
  109. if totalCount > 0 {
  110. self.showContactPicker(modes: [ContactPickerType.person, ContactPickerType.unit], callback: { result in
  111. var u: [O2PersonPickerItem] = []
  112. var d: [O2UnitPickerItem] = []
  113. if let users = result.users, users.count > 0 {
  114. u = users
  115. }
  116. if let units = result.departments, units.count > 0 {
  117. d = units
  118. }
  119. if u.count > 0 || d.count > 0 {
  120. self.showLoading()
  121. self.cFileVM.share(folderList: self.checkedFolderList, fileList: self.checkedFileList, users: u, orgs: d)
  122. .then { result in
  123. DDLogInfo("分享成功,\(result)")
  124. self.hideLoading()
  125. if result {
  126. self.loadListData()
  127. }
  128. }.catch { (error) in
  129. DDLogError(error.localizedDescription)
  130. self.hideLoading()
  131. }
  132. }
  133. })
  134. }
  135. }
  136. //点击查看文件
  137. func clickFile(file: OOAttachment) {
  138. if let type = file.type {
  139. switch type {
  140. case "image":
  141. self.previewFile(fileId: file.id!)
  142. break
  143. case "office":
  144. self.previewFile(fileId: file.id!)
  145. break
  146. case "music":
  147. self.showMessage(msg: "音频类型还未支持!")
  148. break
  149. case "movie":
  150. self.showMessage(msg: "视频类型还未支持!")
  151. break
  152. case "other":
  153. self.previewFile(fileId: file.id!)
  154. break
  155. default:
  156. self.previewFile(fileId: file.id!)
  157. break
  158. }
  159. }else {
  160. self.previewFile(fileId: file.id!)
  161. }
  162. }
  163. func previewFile(fileId: String) {
  164. self.showLoading()
  165. O2CloudFileManager.shared
  166. .getFileUrl(fileId: fileId)
  167. .always {
  168. self.hideLoading()
  169. }
  170. .then { (path) in
  171. let currentURL = NSURL(fileURLWithPath: path.path)
  172. DDLogDebug(currentURL.description)
  173. DDLogDebug(path.path)
  174. if QLPreviewController.canPreview(currentURL) {
  175. self.previewVC.currentFileURLS.removeAll()
  176. self.previewVC.currentFileURLS.append(currentURL)
  177. self.previewVC.reloadData()
  178. self.pushVC(self.previewVC)
  179. }else {
  180. self.showError(title: "当前文件类型不支持预览!")
  181. }
  182. }
  183. .catch { (error) in
  184. DDLogError(error.localizedDescription)
  185. self.showError(title: "获取文件异常!")
  186. }
  187. }
  188. }