1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import router from '@ohos.router'; 17import Logger from '../util/Logger'; 18import webview from '@ohos.web.webview'; 19 20@Component 21export struct WebInitialized { 22 build() { 23 Row() { 24 Column({ space: 20 }) { 25 // 点击按钮跳转优化后的Web组件页 26 Button($r('app.string.web_entry_button')) 27 .onClick(() => { 28 AppStorage.setOrCreate('webPage', 'InitializedWeb'); 29 Logger.info("WebPerformance initializedWeb"); 30 router.pushUrl({ url: 'pages/webPerformance/WebBrowserPage', params: 'InitializedWeb' }); 31 }) 32 .width($r('app.string.web_button_width')) 33 .height($r('app.string.web_button_height')) 34 Button($r('app.string.web_page_back')) 35 .onClick(() => { 36 router.back(); 37 }) 38 .width($r('app.string.web_button_width')) 39 .height($r('app.string.web_button_height')) 40 .margin({ top: $r('app.string.web_button_margin') }) 41 } 42 .width('100%') 43 } 44 .height('100%') 45 } 46 47 aboutToAppear() { 48 // 预加载Web内核、开启预连接 49 webview.WebviewController.initializeWebEngine(); 50 webview.WebviewController.prepareForPageLoad("https://www.openharmony.cn", true, 2); 51 } 52}