//
|
// PBPreviewDocViewController.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2018/8/1.
|
// Copyright © 2018年 ProBIM. All rights reserved.
|
//
|
|
#import "PBPreviewDocViewController.h"
|
#import "PBDocPrivilegeModel.h"
|
#import <WebKit/WebKit.h>
|
#import "PBProjectModel.h"
|
#import "PBPromptView.h"
|
|
@interface PBPreviewDocViewController ()<WKNavigationDelegate, WKUIDelegate>
|
@property (nonatomic, strong) WKWebView *webView;
|
@property (nonatomic, weak) UILabel *fileNameL;
|
@end
|
|
@implementation PBPreviewDocViewController
|
- (void)viewWillAppear:(BOOL)animated {
|
[super viewWillAppear:animated];
|
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
|
|
}
|
- (void)viewWillDisappear:(BOOL)animated {
|
[super viewWillDisappear:animated];
|
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
|
}
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[self setupNav];
|
[self setWebView];
|
}
|
|
- (void)setupNav {
|
self.view.backgroundColor = [UIColor whiteColor];
|
UIView *navBgView = [[UIView alloc] init];
|
navBgView.backgroundColor = [UIColor z_colorWithR:18 G:18 B:18];
|
[self.view addSubview:navBgView];
|
CGFloat height;
|
if (IS_IPHONE_X) {
|
height = 88.0f;
|
}else {
|
height = 64.0f;
|
}
|
[navBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.left.right.equalTo(self.view);
|
make.height.equalTo(@(height));
|
}];
|
UIButton *backBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"Doc_preview_back"]];
|
[backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
[navBgView addSubview:backBtn];
|
[backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.bottom.equalTo(navBgView).offset(-12);
|
make.left.equalTo(navBgView).offset(16);
|
make.size.mas_equalTo(CGSizeMake(24, 24));
|
}];
|
UILabel *fileNameL = [UILabel z_labelWithText:@"文档" Color:[UIColor whiteColor] isBold:YES Font:18];
|
fileNameL.textAlignment = NSTextAlignmentCenter;
|
[navBgView addSubview:fileNameL];
|
[fileNameL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(backBtn);
|
make.left.equalTo(backBtn.mas_right).offset(10);
|
make.right.equalTo(navBgView).offset(-(16 + backBtn.width + 10));
|
}];
|
self.fileNameL = fileNameL;
|
}
|
- (void)backBtnAction {
|
[self dismissViewControllerAnimated:NO completion:nil];
|
}
|
- (void)setWebView {
|
self.webView = [[WKWebView alloc] init];
|
self.webView.backgroundColor = [UIColor whiteColor];
|
self.webView.navigationDelegate = self;
|
self.webView.UIDelegate = self;
|
[self.view addSubview:self.webView];
|
CGFloat height;
|
if (IS_IPHONE_X) {
|
height = 88.0f;
|
}else {
|
height = 64.0f;
|
}
|
[self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.view).offset(height);
|
make.bottom.left.right.equalTo(self.view);
|
}];
|
[self updaWebView];
|
}
|
- (void)updaWebView {
|
if (self.docUrl) {
|
//文档文件下载地址
|
// NSString *url = [NSString stringWithFormat:@"%@/api/Doc/GetFile?ProjectID=%@&FileKind=File&keyValue=%@&FileInfoVersionId=",BimUrl,self.projectModel.bimcomposerid,self.docModel.FileId];
|
// [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
|
|
|
// NSString *downUrl = [NSString stringWithFormat:@"%@/api/Doc/GetHideFile?ProjectID=%@&FileId=%@&FileType=Issue",BimUrl,self.projectModel.bimcomposerid,self.docModel.FileId];
|
// NSString *downUrlUtF8 = [downUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@":/?=&"].invertedSet];
|
// NSString *firstUrl = [NSString stringWithFormat:@"%@/api/DocViewer/Viewer/Show?downloadUrl=%@&tempNameAfterDownload=%@", BaseUrl,downUrlUtF8 ,self.docModel.FileName];
|
// NSString *docUrl = [NSString stringWithFormat:@"%@/Content/PDFJS/web/Viewer.html?file=%@", BaseUrl, [firstUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@".:/?=&%"].invertedSet]];
|
self.fileNameL.text = self.name;
|
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.docUrl]]];
|
}else {
|
self.fileNameL.text = self.name;
|
NSURL *url = [NSURL fileURLWithPath:self.path];
|
[self.webView loadFileURL:url allowingReadAccessToURL:url];
|
}
|
}
|
- (void)setProjectModel:(PBProjectModel *)projectModel {
|
_projectModel = projectModel;
|
}
|
-(void)setDocUrl:(NSString *)docUrl {
|
_docUrl = docUrl;
|
}
|
|
//页面开始加载时调用 11111
|
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{
|
[YJProgressHUD showProgress:@"" inView:self.view];
|
}
|
//主机地址被重定向时调用
|
- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation{
|
}
|
// 页面加载失败时调用 111
|
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{
|
[YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
NSLog(@"页面加载失败");
|
[self.webView reload];
|
}
|
// 当内容开始返回时调用 1111
|
- (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation{
|
NSLog(@"开始返回内容 %@",navigation);
|
|
}
|
//加载完成时调用 11111
|
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
[YJProgressHUD hide];
|
NSLog(@"页面加载完成");
|
}
|
//网页加载内容进程终止
|
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView API_AVAILABLE(macosx(10.11), ios(9.0)){
|
NSLog(@"网页加载内容进程终止");
|
[YJProgressHUD hide];
|
}
|
|
- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{
|
[YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
}
|
- (void)setPath:(NSString *)path {
|
_path = path;
|
}
|
- (void)setName:(NSString *)name {
|
_name = name;
|
}
|
- (void)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
// Dispose of any resources that can be recreated.
|
}
|
|
/*
|
#pragma mark - Navigation
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
// Get the new view controller using [segue destinationViewController].
|
// Pass the selected object to the new view controller.
|
}
|
*/
|
|
@end
|