1***@qq.com
1***@qq.com
  • 发布:2024-09-18 16:37
  • 更新:2024-09-18 16:37
  • 阅读:104

【报Bug】onNavigationBarButtonTap 以及使用currentWeb.getStyle().titleNView 设置button问题

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: MAC

HBuilderX类型: 正式

HBuilderX版本号: 3.99

手机系统: Android

手机系统版本号: Android 14

手机厂商: 小米

手机机型: 小米 11

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
export function setNavBarRight({text, fontSrc = '', style = false, idx = 0}) {  
    let tStyle = style || {color: '#333333', fontSize: '14px'};  
    _setNavBarBtnStyle({text,fontSrc, tStyle, idx});  
}  

function _setNavBarBtnStyle({text,fontSrc, tStyle = {}, idx = 0}) {  
    console.error('setNavBarRight',text,fontSrc, tStyle, idx);  
    _initWebviewBtn().then(flag => {  
        console.error('==========',flag);  
        if (!flag) return;  
        console.log(tn);  
        console.log(tn.buttons);  
        console.log(!tn.buttons);  
        let titleBtn = ''  
        if(!tn.buttons) tn.buttons = [];  
        console.log(tn.buttons[idx]);  
        console.log(!tn.buttons[idx]);  
        if(!tn.buttons[idx]) {  
            tn.buttons.splice(idx,  
                0,  
                {  
                "text": text,  
                "fontSrc": fontSrc,  
                "color": tStyle.color,  
                "fontSize": tStyle.fontSize  
            }  
            )  
            titleBtn = tn.buttons[idx];  
        }else {  
            titleBtn = tn.buttons[idx];  
            if (text) titleBtn.text = text;  
            if (fontSrc) titleBtn.fontSrc = fontSrc;  
            if (tStyle.color) titleBtn.color = tStyle.color;  
            if (tStyle.fontSize) titleBtn.fontSize = tStyle.fontSize;  
        }  
        console.log(titleBtn);  
        tn.buttons[idx] = titleBtn;  
        currentWebview.setStyle({titleNView: tn});  
    });  
}  
function _initWebviewBtn() {  
    return new Promise(resolve => {  
        if (!currentWebview) {  
            let pages = getCurrentPages();  
            let page = pages[pages.length - 1];  
            if (page) {  
                let currentWeb= page.$getAppWebview();  
                tn = currentWeb.getStyle().titleNView;  
                currentWebview = currentWeb;  
                resolve(true);  
            } else {  
                resolve(false);  
            }  
        } else {  
            resolve(true);  
        }  
    });  
}  

vue页面使用

onready(){  
setNavBarRight({  
                    text: '\uE610',  
                    fontSrc: "/static/icon_navbar.ttf",  
                    style: {color: '#333333', fontSize: '20px'},  
                    idx: 0  
                })  
                setNavBarRight({  
                    text: '\uE60D',  
                    fontSrc: "/static/icon_navbar.ttf",  
                    style: {color: '#333333', fontSize: '20px'},  
                    idx: 1  
                })  
}

操作步骤:

使用上述代码按钮文字只有刚刚加载完成出来一次,之后再进这个页面就不显示了,并且button的点击事件一直不生效

预期结果:

进入页面显示对应的文字按钮,onNavigationBarButtonTap点击事件可以使用

实际结果:

只有刚刚加载完之后才会生效,之后进入页面不生效,并且onNavigationBarButtonTap点击事件一直没发使用

bug描述:

let currentWeb= page.$getAppWebview();  
tn = currentWeb.getStyle().titleNView;  
if(!tn.buttons[idx]) {  
            tn.buttons.splice(idx,  
                0,  
                {  
                "text": text,  
                "fontSrc": fontSrc,  
                "color": tStyle.color,  
                "fontSize": tStyle.fontSize  
            }  
            )  
            titleBtn = tn.buttons[idx];  
        }else {  
            titleBtn = tn.buttons[idx];  
            if (text) titleBtn.text = text;  
            if (fontSrc) titleBtn.fontSrc = fontSrc;  
            if (tStyle.color) titleBtn.color = tStyle.color;  
            if (tStyle.fontSize) titleBtn.fontSize = tStyle.fontSize;  
        }  
        console.log(titleBtn);  
        tn.buttons[idx] = titleBtn;  
        currentWebview.setStyle({titleNView: tn});  

使用上述方法添加button方法,在页面onready执行出来一次,并且onNavigationBarButtonTap()点击事件不生效

2024-09-18 16:37 负责人:无 分享
已邀请:

要回复问题请先登录注册