zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//
//  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