feat(miniapp): 添加网页右上角菜单功能

- 在 WebMenuView 中添加了刷新、复制、浏览器打开和微信分享等功能- 在 MiniAppManager 中增加了 webController 和相关方法
- 在 Index 页面中添加了 WebMenuView组件
- 修改了 XWebview 和 XWebHelper 以支持新的菜单功能
这个提交包含在:
徐勤民 2025-05-22 15:19:01 +08:00
父节点 3752229689
当前提交 e756dd4319
共有 3 个文件被更改,包括 39 次插入12 次删除

查看文件

@ -48,17 +48,16 @@ export struct XWebview {
XWebManager.onClose(() => { XWebManager.onClose(() => {
router.back() router.back()
}) })
if (this.xController) { XWebManager.onGetUrl = () => {
this.xController.getUrl = () => { return this.controller.getUrl()
return this.controller.getUrl()
}
this.xController.getTitle = () => {
return this.controller.getTitle()
}
this.xController.refresh = () => {
this.controller.refresh()
}
} }
XWebManager.onGetTitle = () => {
return this.controller.getTitle()
}
XWebManager.onRefresh = () => {
this.controller.refresh()
}
SZYXLocalStorageHelper.storage.setOrCreate('refresh_web_base', -1) SZYXLocalStorageHelper.storage.setOrCreate('refresh_web_base', -1)
SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.XWebViewCLose, undefined) SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.XWebViewCLose, undefined)
@ -135,7 +134,7 @@ export struct XWebview {
Button({ buttonStyle: ButtonStyleMode.TEXTUAL }) { Button({ buttonStyle: ButtonStyleMode.TEXTUAL }) {
if (this.clickMenu?.img) { if (this.clickMenu?.img) {
Image(this.clickMenu?.img) Image(this.clickMenu?.img)
.width(15).height(15) .width(15).height(15).objectFit(ImageFit.Contain)
} else if (this.clickMenu?.text) { } else if (this.clickMenu?.text) {
Text(this.clickMenu.text) Text(this.clickMenu.text)
.fontColor(this.clickMenu?.color ?? '#17171A') .fontColor(this.clickMenu?.color ?? '#17171A')
@ -152,7 +151,7 @@ export struct XWebview {
}.width(65) }.width(65)
.onClick(() => { .onClick(() => {
if (this.clickMenu) { if (this.clickMenu) {
this.clickMenu?.onClick && this.clickMenu?.onClick() XWebManager.menuClick()
return return
} }
if (this.dialogController != null) { if (this.dialogController != null) {

查看文件

@ -64,6 +64,18 @@ export class XWebHelper {
params.controller.sendMessage = (msg) => { params.controller.sendMessage = (msg) => {
XWebManager.sendMessageToHtml(msg) XWebManager.sendMessageToHtml(msg)
} }
params.controller.getUrl = (): string => {
return XWebManager.getUrl();
}
params.controller.getTitle = (): string => {
return XWebManager.getTitle();
}
params.controller.refresh = () => {
XWebManager.refresh()
}
}
if (params.clickMenu){
XWebManager.menuClick = params.clickMenu.onClick
} }
if (params.jsParams && params.jsParams.obj) { if (params.jsParams && params.jsParams.obj) {

查看文件

@ -2,6 +2,9 @@ import { ToolsHelper } from './ToolsHelper';
export class XWebManager { export class XWebManager {
private static closeCall?: () => void; private static closeCall?: () => void;
static onGetUrl: () => string;
static onGetTitle: () => string;
static onRefresh: () => void;
static onClose(call: () => void) { static onClose(call: () => void) {
XWebManager.closeCall = call XWebManager.closeCall = call
@ -11,6 +14,18 @@ export class XWebManager {
XWebManager.closeCall && XWebManager.closeCall() XWebManager.closeCall && XWebManager.closeCall()
} }
static getUrl() {
return XWebManager.onGetUrl()
}
static getTitle() {
return XWebManager.onGetTitle()
}
static refresh() {
XWebManager.onRefresh()
}
private static MapEventListener = new Map<string, (msg: string) => void>(); private static MapEventListener = new Map<string, (msg: string) => void>();
static objs: Map<string, object> = new Map() static objs: Map<string, object> = new Map()
@ -32,6 +47,7 @@ export class XWebManager {
} }
} }
static menuClick: () => void
private static MapEventListenerToHtml = new Map<string, (msg: string) => void>(); private static MapEventListenerToHtml = new Map<string, (msg: string) => void>();
static addOnMessageToHtml(id: string, listener: (msg: string) => void) { static addOnMessageToHtml(id: string, listener: (msg: string) => void) {