Skip to content

Commit 4a9a034

Browse files
committed
feat: finish custom tabbar
1 parent c2593c6 commit 4a9a034

File tree

15 files changed

+162
-23
lines changed

15 files changed

+162
-23
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# tdesign-miniprogram-starter
1+
# Miniprogram Starter
22
基于 TDesign 小程序组件库的基础模板
33

44
## 初始化
@@ -7,4 +7,11 @@
77
npm install
88
```
99

10-
然后打开微信开发者工具,点击菜单栏 ”工具“ - “构建npm”,即可开启预览。
10+
然后打开微信开发者工具,点击菜单栏 ”工具“ - “构建npm”,即可开启预览。
11+
12+
## 特性
13+
14+
- [x] 支持 LESS (v0.0.1)
15+
- [x] 使用自定义 tabbar (v0.0.1)
16+
- [ ] 支持版本检测,并弹窗更新
17+
- [ ] 通过 GitHub Action 自动发布小程序

app.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// app.js
22
App({
33
onLaunch() {
4-
// 展示本地存储能力
5-
const logs = wx.getStorageSync('logs') || []
6-
logs.unshift(Date.now())
7-
wx.setStorageSync('logs', logs)
8-
94
// 登录
105
wx.login({
116
success: res => {

app.json

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
{
2-
"pages":[
2+
"pages": [
33
"pages/index/index",
4-
"pages/logs/logs"
4+
"pages/explore/index",
5+
"pages/my/index"
56
],
6-
"window":{
7-
"backgroundTextStyle":"light",
7+
"window": {
8+
"backgroundTextStyle": "light",
89
"navigationBarBackgroundColor": "#fff",
910
"navigationBarTitleText": "Weixin",
10-
"navigationBarTextStyle":"black"
11+
"navigationBarTextStyle": "black"
1112
},
1213
"tabBar": {
1314
"custom": true,
1415
"color": "#000000",
1516
"selectedColor": "#000000",
1617
"backgroundColor": "#000000",
17-
"list": [{
18-
"pagePath": "pages/index/index",
19-
"text": "组件"
20-
}, {
21-
"pagePath": "pages/logs/logs",
22-
"text": "接口"
23-
}]
18+
"list": [
19+
{
20+
"pagePath": "pages/index/index",
21+
"text": "首页"
22+
},
23+
{
24+
"pagePath": "pages/explore/index",
25+
"text": "发现"
26+
},
27+
{
28+
"pagePath": "pages/my/index",
29+
"text": "我的"
30+
}
31+
]
2432
},
2533
"style": "v2",
2634
"sitemapLocation": "sitemap.json"
27-
}
35+
}

custom-tab-bar/index.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11

22
Component({
33
data: {
4+
value: 'index',
45
list: [{
56
icon: 'home',
6-
value: 'home',
7+
value: 'index',
78
label: '首页',
89
},{
910
icon: 'control-platform',
1011
value: 'explore',
1112
label: '发现',
1213
}, {
1314
icon: 'user',
14-
value: 'user',
15+
value: 'my',
1516
label: '我的'
1617
}]
1718
},
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+
}
1845
})

custom-tab-bar/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<t-tab-bar defaultValue="home">
1+
<t-tab-bar value="{{value}}" bind:change="handleChange">
22
<t-tab-bar-item wx:for="{{list}}" wx:key="index" icon="{{item.icon}}" value="{{item.value}}">
33
{{item.label}}
44
</t-tab-bar-item>

pages/explore/index.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// pages/explore/index.js
2+
Page({
3+
4+
/**
5+
* 页面的初始数据
6+
*/
7+
data: {
8+
9+
},
10+
11+
/**
12+
* 生命周期函数--监听页面加载
13+
*/
14+
onLoad(options) {
15+
16+
},
17+
18+
/**
19+
* 生命周期函数--监听页面初次渲染完成
20+
*/
21+
onReady() {
22+
23+
},
24+
25+
/**
26+
* 生命周期函数--监听页面显示
27+
*/
28+
onShow() {
29+
30+
},
31+
32+
/**
33+
* 生命周期函数--监听页面隐藏
34+
*/
35+
onHide() {
36+
37+
},
38+
39+
/**
40+
* 生命周期函数--监听页面卸载
41+
*/
42+
onUnload() {
43+
44+
},
45+
46+
/**
47+
* 页面相关事件处理函数--监听用户下拉动作
48+
*/
49+
onPullDownRefresh() {
50+
51+
},
52+
53+
/**
54+
* 页面上拉触底事件的处理函数
55+
*/
56+
onReachBottom() {
57+
58+
},
59+
60+
/**
61+
* 用户点击右上角分享
62+
*/
63+
onShareAppMessage() {
64+
65+
}
66+
})

pages/explore/index.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"navigationBarTitleText": "发现",
3+
"usingComponents": {}
4+
}

pages/explore/index.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* pages/explore/index.wxss */

pages/explore/index.wxml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<view class="container">
2+
Explore Page
3+
</view>

pages/index/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"navigationBarTitleText": "首页",
23
"usingComponents": {}
34
}

0 commit comments

Comments
 (0)