Skip to content

Commit c3a31e0

Browse files
committed
完善导航栏红点和角标示例
1 parent e6d2636 commit c3a31e0

2 files changed

Lines changed: 53 additions & 24 deletions

File tree

‎pages/template/nav-city-dropdown/nav-city-dropdown.vue‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default {
9191
// #ifdef APP-PLUS
9292
let currentWebview = page.$getAppWebview();
9393
let titleNView = currentWebview.getStyle().titleNView;
94+
// 添加文字过长截取为3个字符,请根据自己业务需求更改
9495
if(text.length > 3){
9596
text = text.substr(0,3)+"..."
9697
}

‎pages/template/nav-dot/nav-dot.vue‎

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,68 @@
22
<view>
33
<page-head :title="title"></page-head>
44
<view class="uni-padding-wrap uni-common-mt">
5-
<view class="uni-title">
6-
<uni-icon size="16" type="info"></uni-icon>说明 : </view>
5+
<view class="uni-title"> <uni-icon size="16" type="info"></uni-icon>说明 : </view>
76
<view class="uni-helllo-text">
8-
<view>在App端可在pages.json里配置buttons,暂不支持动态改变buttons的样式,使用onNavigationBarButtonTap可监听buttons的点击事件。</view>
7+
<view
8+
>在App端可在pages.json里配置buttons,暂不支持动态改变buttons的样式,使用onNavigationBarButtonTap可监听buttons的点击事件。</view
9+
>
910
<view>在小程序和h5端,不支持配置buttons,故按钮不见了。</view>
1011
</view>
1112
</view>
1213
</view>
1314
</template>
1415
<script>
15-
import uniIcon from '../../../components/uni-icon.vue'
16-
export default {
17-
data() {
18-
return {
19-
title: 'nav-button'
16+
import uniIcon from '../../../components/uni-icon.vue';
17+
export default {
18+
data() {
19+
return {
20+
title: 'nav-dot'
21+
};
22+
},
23+
onLoad() {
24+
this.setStyle(0,true);
25+
this.setStyle(1,'20');
26+
27+
},
28+
methods: {
29+
/**
30+
* 修改导航栏buttons
31+
* index[number] 修改的buttons 下标索引,最右边索引为0
32+
* text[boolean|string] 需要修改的text 内容 ,如果定义redDot请设置 true||false ,如果定义badgeText请设置具体数字,如果没有输入''
33+
*/
34+
setStyle(index, text) {
35+
let pages = getCurrentPages();
36+
let page = pages[pages.length - 1];
37+
// #ifdef APP-PLUS
38+
let currentWebview = page.$getAppWebview();
39+
let titleNView = currentWebview.getStyle().titleNView;
40+
41+
let dot = titleNView.buttons[index].redDot;
42+
let badgeText = titleNView.buttons[index].badgeText;
43+
if (dot) {
44+
titleNView.buttons[index].redDot = text;
2045
}
21-
},
22-
onNavigationBarButtonTap(e) {
23-
uni.showToast({
24-
title: e.index === 0 ? "你点了分享按钮" : "你点了收藏按钮",
25-
icon: "none"
26-
})
27-
if(e.index === 0){
28-
29-
}else{
30-
46+
if (badgeText) {
47+
titleNView.buttons[index].badgeText = text;
3148
}
32-
},
33-
components:{
34-
uniIcon
49+
currentWebview.setStyle({
50+
titleNView: titleNView
51+
});
52+
// #endif
3553
}
54+
},
55+
onNavigationBarButtonTap(e) {
56+
uni.showToast({
57+
title: e.index === 0 ? '你点了消息按钮' : '你点了关注按钮',
58+
icon: 'none'
59+
});
60+
// 取消红点或者角标
61+
this.setStyle(e.index, e.index === 0 ? false : '');
62+
},
63+
components: {
64+
uniIcon
3665
}
66+
};
3767
</script>
3868

39-
<style>
40-
41-
</style>
69+
<style></style>

0 commit comments

Comments
 (0)