首页设置壁纸及修改部分WebView

This commit is contained in:
2024-04-11 14:04:42 +08:00
parent aba6717228
commit fe18fa1ca6
5 changed files with 30 additions and 12 deletions

View File

@@ -85,8 +85,8 @@ export struct TitleBar {
align: this.leftMenuType != TitleBarMenuType.None ? HorizontalAlign.End : HorizontalAlign.Start
},
right: {
anchor: this.leftMenuType != TitleBarMenuType.None ? "right_menu" : ComponentConst.ContainerId,
align: this.leftMenuType != TitleBarMenuType.None ? HorizontalAlign.Start : HorizontalAlign.End
anchor: this.rightMenuType != TitleBarMenuType.None ? "right_menu" : ComponentConst.ContainerId,
align: this.rightMenuType != TitleBarMenuType.None ? HorizontalAlign.Start : HorizontalAlign.End
},
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
})

View File

@@ -1,24 +1,34 @@
import web_webview from '@ohos.web.webview';
import { WebScriptCallback, WebScriptFunction } from './WebScript';
export class WebViewParam {
webUrl: string = "";
}
@Component
export struct WebView {
private webviewController: web_webview.WebviewController = new web_webview.WebviewController();
controller: WebViewController = new WebViewController();
@Prop webUrl: string = "";
@Prop @Watch("onParamChanged")param: WebViewParam = new WebViewParam();
onParamChanged() {
if (this.param.webUrl != this.webviewController.getUrl()) {
this.controller.loadUrl(this.param.webUrl);
}
}
aboutToAppear(): void {
this.controller.setWebviewController(this.webviewController);
}
build() {
Web({ src: this.webUrl, controller: this.webviewController })
Web({ src: this.param.webUrl, controller: this.webviewController })
.javaScriptAccess(true)// 允许使用 js
.javaScriptProxy({
object: null,
name: "",
methodList: [],
object: this.controller,
name: WebViewController.JsBridgeName,
methodList: WebViewController.JsMethodName,
controller: this.webviewController
})
.onPageEnd(() => { this.controller.onPageEnd(this.webviewController.getTitle()) })
@@ -34,6 +44,9 @@ interface WebViewCallback {
export class WebViewController implements WebScriptCallback, WebScriptFunction, WebViewCallback {
static readonly JsBridgeName = "devwiki";
static readonly JsMethodName = [""];
private webviewController?: web_webview.WebviewController
constructor() {