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
})
}
0 个回复