LoginProtocolWebview.ets
4.93 KB
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
import router from '@ohos.router';
import webview from '@ohos.web.webview';
import { SpConstants } from 'wdConstant/Index';
import { Logger, NetworkUtil, SPHelper } from 'wdKit';
import { Params } from '../../../../../../../commons/wdRouter/oh_modules/wdBean/src/main/ets/bean/content/Params';
import { WebArticleEventHandler, WebPoolManager } from 'wdWebComponent';
import { EmptyComponent } from './EmptyComponent';
import {getNWeb} from "wdWebComponent/Index"
const TAG = 'LoginProtocolWebview';
@Entry
@Component
struct LoginProtocolWebview {
@State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0
@State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
@State webUrl: string = ''
webviewController: webview.WebviewController = new webview.WebviewController()
userProtocol = "https://cdnpeoplefrontuat.aikan.pdnews.cn/rmrb/rmrb-protocol-zh-web/0.0.1/app/protocol-1005.html"
privateProtocol = 'https://cdnpeoplefrontuat.aikan.pdnews.cn/rmrb/rmrb-protocol-zh-web/0.0.1/app/protocol-1001.html'
logoutProtocol = 'https://cdnpeoplefrontuat.aikan.pdnews.cn/rmrb/rmrb-protocol-zh-web/0.0.1/app/protocol-1003.html'
huaweiAuthProtocol = 'https://privacy.consumer.huawei.com/legal/id/authentication-terms.htm?code=CN&language=zh-CN'
collectionProtocol = 'https://cdnpeoplefront.aikan.pdnews.cn/rmrb/rmrb-protocol-zh-web/0.0.1/app/protocol-1002.html'//收集个人信息明示清单
thirdVendorProtocol = 'https://cdnpeoplefront.aikan.pdnews.cn/rmrb/rmrb-protocol-zh-web/0.0.1/app/protocol-1004.html'//第三方信息共享清单
@State contentID:string = "0"
@State isConnectNetwork : boolean = NetworkUtil.isNetConnected()
async aboutToAppear() {
if (router.getParams()) {
let params = router.getParams() as Params
Logger.info(TAG, 'params.contentID:' + params.contentID);
if(params.contentID != undefined){
this.contentID = params.contentID
}
if (params.contentID == "1") { //"人民日报客户端网络服务使用协议"
this.webUrl = SPHelper.default.getSync(SpConstants.NET_SERVICE_PROTOCOL, this.userProtocol) as string
} else if(params.contentID == "2"){ //"人民日报客户端用户隐私协议"
this.webUrl = SPHelper.default.getSync(SpConstants.PRIVATE_PROTOCOL, this.privateProtocol) as string
}else if(params.contentID == "3"){ //注销协议
this.webUrl = SPHelper.default.getSync(SpConstants.LOGOUT_PROTOCOL, this.logoutProtocol) as string
} else if(params.contentID == "4"){ //华为用户认证协议
this.webUrl = this.huaweiAuthProtocol
} else if(params.contentID == "5"){ //收集个人信息明示清单
this.webUrl = this.collectionProtocol
} else if(params.contentID == "6"){ //第三方信息共享清单
this.webUrl = this.thirdVendorProtocol
}
}
}
build() {
Column(){
Column() {
Row() {
Image($r("app.media.login_back_icon"))
.width(24)
.aspectRatio(1)
.onClick(() => {
if (this.isConnectNetwork){
///无网络状态下 执行webviewController.accessBackward方法 会crash
if(this.webviewController.accessBackward()){
this.webviewController.backward()
return
}
}
router.back();
}).margin({ left: 16 })
Text()
}
.alignItems(VerticalAlign.Center)
.width('100%')
.height(43)
Text().backgroundColor("#EDEDED")
.width('100%')
.height(1)
if(this.isConnectNetwork){
if(this.contentID == "4"){ //华为用户认证协议
NodeContainer(getNWeb(this.webUrl)).backgroundColor(Color.White)
}else {
Web({ src: this.webUrl, controller: this.webviewController })
.backgroundColor(Color.White)
.domStorageAccess(true)
.databaseAccess(true)
.javaScriptAccess(true)
.zoomAccess(false)
.horizontalScrollBarAccess(false)
.verticalScrollBarAccess(false)
.onHttpErrorReceive((event) => {
//TODO 页面加载不成功的时候处理
Logger.info(TAG, 'onHttpErrorReceive event.request.getRequestUrl:' + event?.request.getRequestUrl());
Logger.info(TAG, 'onHttpErrorReceive event.response.getResponseCode:' + event?.response.getResponseCode());
})
.padding({bottom:this.contentID === "2" ? "40lpx" : 0 })
}
}else{
EmptyComponent({ emptyType: 1,emptyHeight:"100%" ,retry: () => {
this.isConnectNetwork = NetworkUtil.isNetConnected()
}})
.layoutWeight(1)
.width('100%')
}
}
}.width("100%")
.height("100%")
.backgroundColor(Color.White)
.padding({top:px2vp(this.topSafeHeight),bottom:px2vp(this.bottomSafeHeight)})
}
}