Skip to content

Commit e6d2636

Browse files
committed
添加导航栏带城市选择示例
添加导航栏带红点和角标示例
1 parent b638671 commit e6d2636

5 files changed

Lines changed: 233 additions & 18 deletions

File tree

‎pages.json‎

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@
481481
}
482482
},
483483
{
484-
"path" : "platforms/h5/about/about",
484+
"path" : "pages/about/about",
485485
"style" : {
486486
"navigationBarTitleText" : "关于"
487487
}
@@ -592,25 +592,68 @@
592592
}
593593
}
594594
}
595+
},
596+
// #endif
597+
// #ifdef APP-PLUS
598+
{
599+
"path" : "nav-image/nav-image",
600+
"style" : {
601+
"app-plus" : {
602+
"titleNView" : {
603+
"titleText" : "",
604+
"tags" : [
605+
{
606+
"tag" : "img",
607+
"src" : "/static/nav.png",
608+
"position" : {
609+
"left" : "auto",
610+
"top" : "auto",
611+
"width" : "110px",
612+
"height" : "26px"
613+
}
614+
}
615+
]
616+
}
617+
}
618+
}
619+
},
620+
{
621+
"path" : "nav-city-dropdown/nav-city-dropdown",
622+
"style" : {
623+
"navigationBarTitleText" : "导航栏带城市选择",
624+
"app-plus" : {
625+
"titleNView" : {
626+
"buttons" : [
627+
{
628+
"text" : "北京市",
629+
"fontSize" : "14",
630+
"select" : true,
631+
"width" : "auto"
632+
}
633+
]
634+
}
635+
}
636+
}
595637
},
596638
{
597-
"path" : "nav-image/nav-image",
639+
"path" : "nav-dot/nav-dot",
598640
"style" : {
599-
"navigationBarTitleText" : " ",
600-
"app-plus" : {
601-
"titleNView" : {
602-
"tags":[{
603-
"tag":"img",
604-
"src":"/static/nav.png",
605-
"position":{
606-
"left":"auto",
607-
"top":"auto",
608-
"width":"110px",
609-
"height":"26px"
610-
}
611-
}]
612-
}
613-
641+
"navigationBarTitleText" : "导航栏带红点和角标",
642+
"app-plus": {
643+
"titleNView": {
644+
"buttons": [
645+
{
646+
"text": "消息",
647+
"fontSize": "14",
648+
"redDot": true
649+
},
650+
{
651+
"text": "关注",
652+
"fontSize": "14",
653+
"badgeText": "12"
654+
}
655+
]
656+
}
614657
}
615658
}
616659
},

‎pages/tabBar/template/template.vue‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
name: '导航栏带图片',
6666
url: 'nav-image'
6767
},
68+
{
69+
name: '导航栏带红点和角标',
70+
url:'nav-dot'
71+
},
72+
{
73+
name: '导航栏带城市选择',
74+
url:'nav-city-dropdown'
75+
},
6876
// #endif
6977
{
7078
name: '自定义导航栏组件(非原生)',
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<template>
2+
<view class="mpvue-picker">
3+
<page-head :title="title"></page-head>
4+
<view class="uni-padding-wrap uni-common-mt">
5+
<view class="uni-title"> <uni-icon size="16" type="info"></uni-icon>说明 : </view>
6+
<view class="uni-helllo-text">
7+
<view
8+
>在App端可在pages.json里配置buttons,暂不支持动态改变buttons的样式,使用onNavigationBarButtonTap可监听buttons的点击事件。</view
9+
>
10+
<view>在小程序和h5端,不支持配置buttons,故按钮不见了。</view>
11+
</view>
12+
</view>
13+
<mpvue-picker
14+
:themeColor="themeColor"
15+
ref="mpvuePicker"
16+
:mode="mode"
17+
:deepLength="deepLength"
18+
:pickerValueDefault="pickerValueDefault"
19+
@onConfirm="onConfirm"
20+
@onCancel="onCancel"
21+
:pickerValueArray="pickerValueArray"
22+
></mpvue-picker>
23+
</view>
24+
</template>
25+
26+
<script>
27+
// https://github.com/zhetengbiji/mpvue-picker
28+
import mpvuePicker from '../../../components/mpvue-picker/mpvuePicker.vue';
29+
// https://github.com/zhetengbiji/mpvue-citypicker
30+
import cityData from '../../../common/city.data.js';
31+
32+
export default {
33+
components: {
34+
mpvuePicker
35+
},
36+
data() {
37+
return {
38+
title: 'nav-city-dropdown',
39+
pickerSingleArray: [
40+
{
41+
label: '中国',
42+
value: 1
43+
},
44+
{
45+
label: '俄罗斯',
46+
value: 2
47+
},
48+
{
49+
label: '美国',
50+
value: 3
51+
},
52+
{
53+
label: '日本',
54+
value: 4
55+
}
56+
],
57+
themeColor: '#007AFF',
58+
mode: '',
59+
deepLength: 1,
60+
pickerValueDefault: [0],
61+
pickerValueArray: []
62+
63+
};
64+
},
65+
onLoad() {
66+
this.setStyle(0,'北京市');
67+
},
68+
methods: {
69+
onCancel(e) {
70+
console.log(e);
71+
},
72+
// 单列
73+
showSinglePicker() {
74+
this.pickerValueArray = cityData;
75+
this.mode = 'selector';
76+
this.deepLength = 1;
77+
this.pickerValueDefault = [0];
78+
this.$refs.mpvuePicker.show();
79+
},
80+
onConfirm(e) {
81+
this.setStyle(0,e.label)
82+
},
83+
/**
84+
* 修改导航栏buttons
85+
* index[number] 修改的buttons 下标索引,最右边索引为0
86+
* text[string] 需要修改的text 内容
87+
*/
88+
setStyle(index,text) {
89+
let pages = getCurrentPages();
90+
let page = pages[pages.length - 1];
91+
// #ifdef APP-PLUS
92+
let currentWebview = page.$getAppWebview();
93+
let titleNView = currentWebview.getStyle().titleNView;
94+
if(text.length > 3){
95+
text = text.substr(0,3)+"..."
96+
}
97+
titleNView.buttons[index].text = text;
98+
currentWebview.setStyle({
99+
titleNView:titleNView
100+
});
101+
// #endif
102+
}
103+
},
104+
onBackPress() {
105+
if (this.$refs.mpvuePicker.showPicker) {
106+
this.$refs.mpvuePicker.pickerCancel();
107+
return true;
108+
}
109+
},
110+
onUnload() {
111+
if (this.$refs.mpvuePicker.showPicker) {
112+
this.$refs.mpvuePicker.pickerCancel();
113+
}
114+
},
115+
onNavigationBarButtonTap(e) {
116+
if (e.index === 0) {
117+
this.showSinglePicker();
118+
}
119+
}
120+
};
121+
</script>
122+
123+
<style></style>

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<template>
2+
<view>
3+
<page-head :title="title"></page-head>
4+
<view class="uni-padding-wrap uni-common-mt">
5+
<view class="uni-title">
6+
<uni-icon size="16" type="info"></uni-icon>说明 : </view>
7+
<view class="uni-helllo-text">
8+
<view>在App端可在pages.json里配置buttons,暂不支持动态改变buttons的样式,使用onNavigationBarButtonTap可监听buttons的点击事件。</view>
9+
<view>在小程序和h5端,不支持配置buttons,故按钮不见了。</view>
10+
</view>
11+
</view>
12+
</view>
13+
</template>
14+
<script>
15+
import uniIcon from '../../../components/uni-icon.vue'
16+
export default {
17+
data() {
18+
return {
19+
title: 'nav-button'
20+
}
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+
31+
}
32+
},
33+
components:{
34+
uniIcon
35+
}
36+
}
37+
</script>
38+
39+
<style>
40+
41+
</style>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<uni-icon size="16" type="info"></uni-icon>说明 : </view>
77
<view class="uni-helllo-text">
88
<view>在App端可在pages.json里配置tags,暂不支持动态改变tags的样式。</view>
9-
<view>在小程序\H5端,不支持配置tags,故按钮不见了。</view>
9+
<view>在小程序和h5端,不支持配置tags,故按钮不见了。</view>
1010
</view>
1111
</view>
1212
</view>

0 commit comments

Comments
 (0)