我想弄的是在用户点击进入的时候判断他是不是指定用户的openid,如果不是的话,tabbar显示首页和返回首页,如果是指定用户的openid,tabbar显示首页和发布。(在app.js已成功调用获取openid的云函数)
我在app.json的tabbar配置了"custom": true之后,tabbar不显示,把它去掉后又会显示了,不知道问题出在哪里,求指教!
app.json:
"tabBar": {
"custom": true,
"list": [
{
"pagePath": "pages/home/home",
"text": "首页"
},
{
"pagePath": "pages/publish/publish",
"text": "发布"
},
{
"pagePath": "pages/notice/notice",
"text": "返回"
}
]
},
"usingComponents": {},
custom-tab-bar.js:
const app = getApp()
Component({
data: {
selected: 0,
color: "#000000",
roleId: '',
selectedColor: "#1396DB",
openid: '',
list: [],
allList: [{
list1: [{
pagePath: "../pages/home/home",
text: "首页"
}, {
pagePath: "../pages/notice/notice",
text: "返回首页"
}],
list2: [{
pagePath: "../pages/home/home",
text: "首页"
}, {
pagePath: "../pages/publish/publish",
text: "发布"
}]
}],
},
attached() {
let openid = app.globalData.openid
if (openid !== 'orUNJ4x0onCasKAVhRD5jD2pql1A') {
this.setData({
list: this.data.allList[0].list1
})
}
else if (openid == 'orUNJ4x0onCasKAVhRD5jD2pql1A') {
this.setData({
list: this.data.allList[0].list2
})
}
},
methods: {
switchTab(e) {
const data = e.currentTarget.dataset
const url = data.path
wx.switchTab({url})
this.setData({
selected: data.index
})
}
}
custom-tab-bar.wxml:
<cover-view class="tab-bar">
<cover-view class="tab-bar-border"></cover-view>
<cover-view wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="switchTab">
<cover-view style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</cover-view>
</cover-view>
</cover-view>
home.js:
onShow: function () {
if (typeof this.getTabBar === 'function' &&
this.getTabBar()) {
this.getTabBar().setData({
selected: 0
})
}
},