Skip to content

Commit f72cb45

Browse files
committed
feat: using custom tabbar
1 parent 8934d33 commit f72cb45

File tree

13 files changed

+108
-76
lines changed

13 files changed

+108
-76
lines changed

miniprogram/app.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
"pages/learn/detail",
1111
"pages/search/index"
1212
],
13+
"tabBar": {
14+
"custom": true,
15+
"color": "#000",
16+
"selectedColor": "#000",
17+
"backgroundColor": "#fff",
18+
"list": [{
19+
"pagePath": "pages/index/index",
20+
"text": "首页"
21+
}, {
22+
"pagePath": "pages/learn/index",
23+
"text": "技巧"
24+
}, {
25+
"pagePath": "pages/my/index",
26+
"text": "我的"
27+
}]
28+
},
1329
"window": {
1430
"backgroundColor": "#f6f6f6",
1531
"backgroundTextStyle": "light",
@@ -38,6 +54,8 @@
3854
"t-navbar": "tdesign-miniprogram/navbar/navbar",
3955
"t-search": "tdesign-miniprogram/search/search",
4056
"t-switch": "tdesign-miniprogram/switch/switch",
57+
"t-popup": "tdesign-miniprogram/popup/popup",
58+
"t-image": "tdesign-miniprogram/image/image",
4159
"t-steps": "tdesign-miniprogram/steps/steps",
4260
"t-step": "tdesign-miniprogram/steps/step-item"
4361
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
Component({
3+
data: {
4+
value: 'index',
5+
list: [{
6+
icon: 'home',
7+
value: 'index',
8+
label: '首页',
9+
},{
10+
icon: 'tips',
11+
value: 'learn',
12+
label: '发现',
13+
}, {
14+
icon: 'user',
15+
value: 'my',
16+
label: '我的'
17+
}]
18+
},
19+
lifetimes: {
20+
ready() {
21+
const pages = getCurrentPages();
22+
const curPage = pages[pages.length - 1];
23+
24+
if (curPage) {
25+
const nameRe = /pages\/(\w+)\/index/.exec(curPage.route);
26+
27+
if (nameRe[1]) {
28+
this.setData({
29+
value: nameRe[1]
30+
})
31+
}
32+
}
33+
}
34+
},
35+
methods: {
36+
handleChange(e) {
37+
const { value } = e.detail;
38+
39+
// this.setData({ value });
40+
wx.switchTab({
41+
url: `/pages/${value}/index`,
42+
})
43+
}
44+
}
45+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"component": true,
3+
"usingComponents": {
4+
"t-tab-bar": "tdesign-miniprogram/tab-bar/tab-bar",
5+
"t-tab-bar-item": "tdesign-miniprogram/tab-bar/tab-bar-item"
6+
}
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* custom-tab-bar/index.wxss */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<t-tab-bar value="{{value}}" bind:change="handleChange">
2+
<t-tab-bar-item wx:for="{{list}}" wx:key="index" icon="{{item.icon}}" value="{{item.value}}">
3+
{{item.label}}
4+
</t-tab-bar-item>
5+
</t-tab-bar>

miniprogram/pages/index/index.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,9 @@ let isSubscribeShow = false;
88
Page({
99
data: {
1010
list: [],
11-
value: 'index',
1211
searchKeyword: '',
12+
chineseMap,
1313
subscribeModalVisible: false,
14-
tabbars: [{
15-
text: '首页',
16-
value: 'index',
17-
icon: 'home'
18-
}, {
19-
text: '技巧',
20-
value: 'learn',
21-
icon: 'tips'
22-
}, {
23-
text: '个人中心',
24-
value: 'my',
25-
icon: 'user'
26-
}]
2714
},
2815

2916
onLoad() {
@@ -54,18 +41,10 @@ Page({
5441
},
5542

5643
handleTap(e) {
57-
const { item } = e.detail;
44+
const { id } = e.currentTarget.dataset;
5845

5946
wx.navigateTo({
60-
url: '../detail/index?id=' + item.id
61-
})
62-
},
63-
64-
handleTabbarChange({ detail }) {
65-
const { value } = detail;
66-
67-
wx.redirectTo({
68-
url: `../${value}/index`
47+
url: '../detail/index?id=' + id
6948
})
7049
},
7150

miniprogram/pages/index/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"navigationBarTitleText": "程序员做饭",
3-
"navigationStyle": "custom",
3+
"backgroundColor": "#fff",
44
"usingComponents": {
55
}
66
}

miniprogram/pages/index/index.less

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
page {
2-
padding: 0 0 200rpx;
3-
}
1+
42

53
.brand {
64
display: flex;
@@ -30,4 +28,31 @@ page {
3028
.container {
3129
margin-top: 32rpx;
3230
padding: 0 32rpx;
31+
}
32+
33+
.tabs {
34+
height: 100%;
35+
}
36+
37+
.t-tabs__scroll {
38+
min-height: 100vh;
39+
background-color: #f3f3f3;
40+
}
41+
42+
.card {
43+
margin: 24rpx;
44+
padding: 24rpx;
45+
border-radius: 8rpx;
46+
box-shadow: 2rpx 2rpx 10rpx rgba(0, 0, 0, .3);
47+
}
48+
49+
.wrapper {
50+
box-sizing: border-box;
51+
height: 100vh;
52+
border-bottom: env(safe-area-inset-bottom, 28rpx) solid #fff;
53+
padding-bottom: 50px ;
54+
}
55+
56+
scroll-view {
57+
height: 100%;
3358
}

miniprogram/pages/index/index.wxml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@
2828
bind:confirm="handleSubscribe"
2929
/>
3030

31-
<include src="/templates/tabbar.wxml" />
3231
<include src="/templates/base.wxml" />

miniprogram/pages/learn/index.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,12 @@ Page({
44

55
data: {
66
info,
7-
value: 'learn',
8-
tabbars: [{
9-
text: '首页',
10-
value: 'index',
11-
icon: 'home'
12-
}, {
13-
text: '技巧',
14-
value: 'learn',
15-
icon: 'tips'
16-
}, {
17-
text: '个人中心',
18-
value: 'my',
19-
icon: 'user'
20-
}]
217
},
228

239
onLoad: function (options) {
2410

2511
},
2612

27-
handleTabbarChange({ detail }) {
28-
const { value } = detail;
29-
30-
wx.redirectTo({
31-
url: `../${value}/index`
32-
})
33-
},
34-
3513
onShareAppMessage: function () {
3614

3715
}

0 commit comments

Comments
 (0)