Browse Source

根据角色切换tabBar

master
CODE 1 year ago
parent
commit
af9e128c8a
  1. 44
      weapp/app.js
  2. 19
      weapp/app.json
  3. 32
      weapp/custom-tab-bar/index.js
  4. 3
      weapp/custom-tab-bar/index.json
  5. 8
      weapp/custom-tab-bar/index.wxml
  6. 38
      weapp/custom-tab-bar/index.wxss
  7. 13
      weapp/pages/home/home.js
  8. 5
      weapp/pages/index/index.js
  9. 2
      weapp/pages/index/index.wxss
  10. 13
      weapp/pages/login/login.js
  11. 6
      weapp/pages/myInfo/myInfo.js
  12. 3
      weapp/pages/myInfo/myInfo.wxss
  13. 6
      weapp/pages/overview/overview.js
  14. 3
      weapp/project.private.config.json

44
weapp/app.js

@ -14,7 +14,49 @@ App({
// baseUrl: 'http://127.0.0.1:6015', //api 测试环境
// webUrl: "http://127.0.0.1:6014/", //web 测试环境
// imgUrl: 'http://127.0.0.1:6014/_file-server/', //文件 本测试环境
key: 'ODQBZ-3FZAU-6VIVL-2XXNM-F7CP7-WVFCY' //获取位置信息
key: 'ODQBZ-3FZAU-6VIVL-2XXNM-F7CP7-WVFCY', //获取位置信息
inspecterList: [ // 巡检人员tabBar / app.json 也要写
{
"pagePath": "/pages/index/index",
"iconPath": "/images/tabBar/icon_polling.png",
"selectedIconPath": "/images/tabBar/icon_polling_active.png",
"text": "巡检总览"
},
{
"pagePath": "/pages/overview/overview",
"iconPath": "/images/tabBar/icon_menu.png",
"selectedIconPath": "/images/tabBar/icon_menu_active.png",
"text": "工作台"
},
{
"pagePath": "/pages/myInfo/myInfo",
"iconPath": "/images/tabBar/icon_person.png",
"selectedIconPath": "/images/tabBar/icon_person_active.png",
"text": "我的"
}
],
managerList: [ // 管理人员tabBar / app.json 也要写
{
"pagePath": "/pages/home/home",
"iconPath": "/images/tabBar/icon_polling.png",
"selectedIconPath": "/images/tabBar/icon_polling_active.png",
"text": "首页"
},
{
"pagePath": "/pages/overview/overview",
"iconPath": "/images/tabBar/icon_menu.png",
"selectedIconPath": "/images/tabBar/icon_menu_active.png",
"text": "工作台"
},
{
"pagePath": "/pages/myInfo/myInfo",
"iconPath": "/images/tabBar/icon_person.png",
"selectedIconPath": "/images/tabBar/icon_person_active.png",
"text": "我的"
}
],
},
onShow (e) {
// 检查是否有更新

19
weapp/app.json

@ -4,7 +4,8 @@
"pages/login/login",
"pages/myInfo/myInfo",
"pages/overview/overview",
"pages/home/home"
"pages/home/home",
"custom-tab-bar/index"
],
"subPackages": [
{
@ -29,6 +30,7 @@
"navigationBarTextStyle": "white"
},
"tabBar": {
"custom": true,
"color": "#000000",
"selectedColor": "#2F54FF",
"borderStyle": "black",
@ -40,12 +42,6 @@
"selectedIconPath": "images/tabBar/icon_polling_active.png",
"text": "巡检总览"
},
{
"pagePath": "pages/home/home",
"iconPath": "images/tabBar/icon_polling.png",
"selectedIconPath": "images/tabBar/icon_polling_active.png",
"text": "首页"
},
{
"pagePath": "pages/overview/overview",
"iconPath": "images/tabBar/icon_menu.png",
@ -57,6 +53,12 @@
"iconPath": "images/tabBar/icon_person.png",
"selectedIconPath": "images/tabBar/icon_person_active.png",
"text": "我的"
},
{
"pagePath": "pages/home/home",
"iconPath": "images/tabBar/icon_polling.png",
"selectedIconPath": "images/tabBar/icon_polling_active.png",
"text": "首页"
}
]
},
@ -69,5 +71,6 @@
"getLocation"
],
"sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents"
"lazyCodeLoading": "requiredComponents",
"usingComponents": {}
}

32
weapp/custom-tab-bar/index.js

@ -0,0 +1,32 @@
Component({
data: {
selected: 0,
color: "#7A7E83",
selectedColor: "#1070E8",
list: []
},
attached () {
let userRole = wx.getStorageSync('userRole');
// 0 表示普通用户 1表示管理员
console.log('userRole', userRole);
if (userRole && userRole.includes('管理')) {
this.setData({
list: getApp().globalData.managerList
})
} else {
this.setData({
list: getApp().globalData.inspecterList
})
}
},
methods: {
switchTab (e) {
const data = e.currentTarget.dataset
const url = data.path
// this.setData({
// selected: data.index
// })
wx.switchTab({ url })
}
}
})

3
weapp/custom-tab-bar/index.json

@ -0,0 +1,3 @@
{
"component": true
}

8
weapp/custom-tab-bar/index.wxml

@ -0,0 +1,8 @@
<!-- miniprogram/custom-tab-bar/index.wxml -->
<view class="tab-bar">
<view class="tab-bar-border"></view>
<view wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="switchTab">
<image src="{{selected === index ? item.selectedIconPath : item.iconPath}}"></image>
<view style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</view>
</view>
</view>

38
weapp/custom-tab-bar/index.wxss

@ -0,0 +1,38 @@
.tab-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 48px;
background: white;
display: flex;
padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar-border {
background-color: rgba(0, 0, 0, 0.33);
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 1px;
transform: scaleY(0.5);
}
.tab-bar-item {
flex: 1;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.tab-bar-item image {
width: 27px;
height: 27px;
}
.tab-bar-item view {
font-size: 10px;
}

13
weapp/pages/home/home.js

@ -26,7 +26,18 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow () {
const userInfo = wx.getStorageSync('userInfo');
if (!userInfo || !userInfo.id) {
wx.reLaunch({
url: '/pages/login/login'
});
} else {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: 0
})
}
}
},
/**

5
weapp/pages/index/index.js

@ -110,6 +110,11 @@ Page({
});
} else {
this.getData();
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: 0
})
}
}
},

2
weapp/pages/index/index.wxss

@ -1,7 +1,7 @@
/* pages/index/index.wxss */
.map {
width: 100vw;
height: 100vh;
height: calc(100vh - 82px);
}
.action-box {

13
weapp/pages/login/login.js

@ -32,16 +32,29 @@ Page({
wx.setStorageSync('token', res.token);
wx.setStorageSync("userInfo", res);
getApp().globalData.userInfo = res
wx.setStorageSync('userRole', res.role)
wx.hideLoading()
if (this.data.scene) {
wx.redirectTo({
url: `/package/inspectionInput/inspectionInput?scene=${this.data.scene}`,
})
return;
}
console.log(res.role);
setTimeout(() => {
console.log(`跳转`);
if (res.role.includes('管理')) {
wx.switchTab({
url: '/pages/home/home',
})
} else {
wx.switchTab({
url: '/pages/index/index',
})
}
}, 1000)
})
},

6
weapp/pages/myInfo/myInfo.js

@ -62,7 +62,11 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow () {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: 2
})
}
},
/**

3
weapp/pages/myInfo/myInfo.wxss

@ -25,6 +25,7 @@ page {
/* 容器 */
.box {
padding-top: 42rpx;
padding: 30rpx;
font-family: 'PingFang SC-Medium';
}
@ -151,7 +152,7 @@ page {
.foot-container {
position: absolute;
bottom: 50px;
bottom: 140px;
width: 90%;
height: 42px;
border: 1px solid #006BE3;

6
weapp/pages/overview/overview.js

@ -45,7 +45,11 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow () {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: 1
})
}
},
/**

3
weapp/project.private.config.json

@ -31,5 +31,6 @@
}
]
}
}
},
"libVersion": "2.29.2"
}
Loading…
Cancel
Save