Commit eeb298aa authored by pete谢兆麟's avatar pete谢兆麟

文件预览预研

parent 2d579f64
...@@ -137,6 +137,45 @@ class YHMyViewController: YHBaseViewController, ConstraintRelatableTarget { ...@@ -137,6 +137,45 @@ class YHMyViewController: YHBaseViewController, ConstraintRelatableTarget {
NotificationCenter.default.addObserver(self, selector: #selector(logoutSuccess), name: YhConstant.YhNotification.didLogoutSuccessNotifiction, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(logoutSuccess), name: YhConstant.YhNotification.didLogoutSuccessNotifiction, object: nil)
} }
func openXLSXRemoteFile(urlString: String) {
guard let url = URL(string: urlString) else { return }
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration)
let task = session.downloadTask(with: url) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil {
// 下载完成,尝试打开文件
let fileManager = FileManager.default
let destination = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(response?.suggestedFilename ?? UUID().uuidString)
try? fileManager.moveItem(at: tempLocalUrl, to: destination)
// 打开文件
self.openXLSXFile(at: destination)
} else {
print("Error downloading the file: \(error?.localizedDescription ?? "Unknown error")")
}
}
task.resume()
}
func openXLSXFile(at fileURL: URL) {
let controller = UIDocumentInteractionController(url: fileURL)
controller.delegate = self
DispatchQueue.main.async {
controller.presentPreview(animated: true)
}
}
}
extension YHMyViewController: UIDocumentInteractionControllerDelegate {
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
} }
extension YHMyViewController : UITableViewDelegate, UITableViewDataSource { extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
...@@ -164,65 +203,58 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource { ...@@ -164,65 +203,58 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
let vc = UINavigationController(rootVC: YHPhoneLoginViewController()) let vc = UINavigationController(rootVC: YHPhoneLoginViewController())
vc.modalPresentationStyle = .custom vc.modalPresentationStyle = .custom
self.navigationController?.present(vc, animated: true) self.navigationController?.present(vc, animated: true)
return
} else { } else {
YHHUD.flash(message: "已登录: 功能完善中...") YHHUD.flash(message: "已登录: 功能完善中...")
} }
let vc = YHWebViewViewController()
navigationController?.pushViewController(vc, animated: true) //for test hjl
return
// let url = URL(string: "https://docs.qq.com/openapi/drive/v2/files/embed/temporary?timestamp=1710298232&id=6bcaa379b0e5488abbaff85d51ee2fab&clientID=2aebc2da4f0b4883bf33ef20836f2e2d")!
//
// let tmpVC = SFSafariViewController(url: url)
// navigationController?.pushViewController(tmpVC)
//
//
// return
// if indexPath.row == 0 {
//
//
// let vc = YHWebViewViewController()
// navigationController?.pushViewController(vc, animated: true)
// } else {
// let vc = YHWebViewViewController()
// navigationController?.pushViewController(vc, animated: true)
// }
//
// return
let item: PersonalModuleItem = items[indexPath.row]; let item: PersonalModuleItem = items[indexPath.row];
// 预览文件预研 杜宇todo
if item.title == "关于我们" { if item.title == "我的消息" {
let vc = YHAboutUsViewController() YHHUD.flash(message: "预览image")
self.navigationController?.pushViewController(vc) self.openXLSXRemoteFile(urlString: "https://upload-cdn.galaxy-immi.com/crm/production/1620280305822.jpg")
} else if item.title == "我的进度" {
} else if item.title == "我的设置" { YHHUD.flash(message: "预览pdf")
self.openXLSXRemoteFile(urlString: "https://upload-cdn.galaxy-immi.com/crm/production/1620271660487.pdf")
} else if item.title == "积分中心" {
YHHUD.flash(message: "预览xlsx")
self.openXLSXRemoteFile(urlString: "https://test-cdn.galaxy-immi.com/4001001/8979989729091623170120240321152216.xlsx?Expires=1711007546&OSSAccessKeyId=LTAI5tNFvK2xGRrBeJ2z8R2j&Signature=UfM6tRcws5ObN4rp/3ZESEWbM2E%3D&v=1711005746")
} else if item.title == "推荐有理" {
let account = "duyu" } else if item.title == "我的海报" {
let token = "123456"
let vc = ConversationController()
self.navigationController?.pushViewController(vc)
IMKitClient.instance.loginIM(account, token) { error in
if let err = error {
print("login error in app : ", err.localizedDescription)
}else {
let _ = NEAtMessageManager.instance
}
}
} else if item.title == "我的测评码" {
}
} else {
// if item.title == "关于我们" {
// let vc = YHAboutUsViewController()
// self.navigationController?.pushViewController(vc)
//
// } else if item.title == "我的设置" {
//
// let account = "duyu"
// let token = "123456"
// let vc = ConversationController()
// self.navigationController?.pushViewController(vc)
//
// IMKitClient.instance.loginIM(account, token) { error in
// if let err = error {
// print("login error in app : ", err.localizedDescription)
// }else {
// let _ = NEAtMessageManager.instance
//
// }
// }
//
//
//
// } else {
// let vc = YHLoginViewController() // let vc = YHLoginViewController()
// self.navigationController?.pushViewController(vc) // self.navigationController?.pushViewController(vc)
} // }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment