当前位置: 首页 > news >正文

uniapp踩坑之项目:简易版不同角色显示不一样的tabbar和页面

1.

pages下创建三个不同用户身份的“我的”页面。

显示第几个tabbar,0是管理员 1是财务 2是司机

2.

在uni_modules文件夹创建底部导航cc-myTabbar文件夹,在cc-myTabbar文件夹创建components文件夹,在components文件夹创建cc-myTabbar.vue组件

3.

在utils文件夹创建tabBar.js

4.

pages.json里指定路径

5.

在单页面引入底部导航组件

 

//cc-myTabbar.vue 底部导航组件
<template><view class="page-total"><view class="tab-list"><view class="list" v-for="(item,index) in TabBarList" @click="onTabBar(item,index)" :style="{marginTop: (item.name == '') ?  '-88rpx' : '0px'}" :key="item.index"><image :src="item.acImg" mode="widthFix" v-show="tabBarShow ===index" :style="{width: (item.name == '') ?  '100rpx' : '54rpx',borderRadius: (item.name == '') ?  '24rpx' : '0rpx'}"></image><image :src="item.img" mode="widthFix" v-show="tabBarShow != index" :style="{width: (item.name == '') ?  '100rpx' : '54rpx',borderRadius: (item.name == '') ?  '24rpx' : '0rpx'}"></image><text :class="{'action':tabBarShow===index}">{{item.name}}</text></view></view></view>
</template><script>
import tabBar from "@/utils/tabBar.js"
// 判断当前登陆用户角色
// 0 为管理员
// 1 为财务
// 2 为司机// 三元表达式判断当前登陆的用户角色
// var user_type = uni.getStorageSync("userType")
var user_type = 0
let type = user_type === 0 ? 'admin' : user_type === 1 ? "finance" : "driver"const state = {list: tabBar[type]
}
// console.log(user_type, 'user_type');
// console.log(type, 'type');
// console.log(state, 'state');
export default {data () {return {TabBarList: state.list,codeheight: 0,isOverall: 0,phoneModel: '',};},props: {tabBarShow: {type: Number,default: 0,}},mounted () {try {const res = uni.getSystemInfoSync();let that = this;// 获取系统信息uni.getSystemInfo({success (res) {console.log(res.brand) //手机牌子console.log(res.model) //手机型号console.log(res.screenWidth) //屏幕宽度console.log(res.screenHeight) //屏幕高度that.codeheight = Math.round(res.screenHeight);that.phoneModel = res.modelif (res.model.search('iPhone')) {that.isOverall = 0;} else if (Math.round(res.screenHeight) > 740) {that.isOverall = 1;}console.log(that.isOverall);}});} catch (e) {// error}},methods: {// 底部导航 跳转onTabBar (item, index) {// this.tabBarShow = index;// console.log(item, 'item');// console.log(index, 'index');if (user_type == 2) { // 司机switch (item.name) {case '首页':uni.switchTab({url: '/pages/homePage/homePage'})break;case ''://   uni.switchTab({//     url: '/pages/scan/scan'//   })// 允许从相机和相册扫码uni.scanCode({success: function (res) {console.log('条码类型:' + res.scanType);console.log('条码内容:' + res.result);}});break;case '我的':uni.switchTab({url: '/pages/mineDriver/mineDriver'})break;}} else if (user_type == 0) { //管理员switch (item.name) {case '首页':uni.switchTab({url: '/pages/homePage/homePage'})break;case ''://   uni.switchTab({//     url: '/pages/scan/scan'//   })// 允许从相机和相册扫码uni.scanCode({success: function (res) {console.log('条码类型:' + res.scanType);console.log('条码内容:' + res.result);}});break;case '我的':uni.switchTab({url: '/pages/mine/mine'})break;}} else { // 财务switch (item.name) {case '首页':uni.switchTab({url: '/pages/homePage/homePage'})break;case ''://   uni.switchTab({//     url: '/pages/scan/scan'//   })// 允许从相机和相册扫码uni.scanCode({success: function (res) {console.log('条码类型:' + res.scanType);console.log('条码内容:' + res.result);}});break;case '我的':uni.switchTab({url: '/pages/mineFinance/mineFinance'})break;}}}}
}
</script><style scoped lang="scss">
@import 'cc-myTabbar.scss';
</style>//在components文件夹里创建cc-myTabbar.scss
//cc-myTabbar.scss
/* 主要颜色 */
$base: #508AF1; // 基础颜色.page-total {position: fixed;left: 0;bottom: 0;width: 100%;// height: 100rpx;
}.tab-list {display: flex;justify-content: space-between;align-items: center;width: 100%;height: 140rpx;padding-bottom: 20rpx;background-color: #FFFFFF;// border-top: 1px solid #e8e8e8;.list {display: flex;flex-direction: column;align-items: center;justify-content: center;width: 38%;height: 120rpx;image {width: 48rpx;height: 48rpx;background-color: white;}text {color: #707070;font-weight: 900;font-size: 24rpx;margin-top: 10rpx;}.action {color: $base;}}
}
//tabBar.js
// 小程序管理者
const admin = [{pagePath: "/pages/homePage/homePage",index: 0,name: '首页',img: '/static/images/tabBar/tab_01.png',acImg: '/static/images/tabBar/tab_02.png'},// {//   index: 2,//   name: '',//   img: '/static/images/tabBar/tab_03.png',//   acImg: '/static/images/tabBar/tab_04.png'// },{pagePath: "/pages/mine/mine",index: 1,name: '我的',img: '/static/images/tabBar/tab_05.png',acImg: '/static/images/tabBar/tab_06.png'},
]
// 财务
const finance = [{pagePath: "/pages/homePage/homePage",index: 0,name: '首页',img: '/static/images/tabBar/tab_01.png',acImg: '/static/images/tabBar/tab_02.png'},// {//   index: 1,//   name: '',//   img: '/static/images/tabBar/tab_03.png',//   acImg: '/static/images/tabBar/tab_04.png'// },{pagePath: "/pages/mineFinance/mineFinance",index: 1,name: '我的',img: '/static/images/tabBar/tab_05.png',acImg: '/static/images/tabBar/tab_06.png'},
]// 司机
const driver = [{pagePath: "/pages/homePage/homePage",index: 0,name: '首页',img: '/static/images/tabBar/tab_01.png',acImg: '/static/images/tabBar/tab_02.png'},// {//   pagePath: "/pages/scan/scan",//   index: 1,//   name: '',//   img: '/static/images/tabBar/tab_03.png',//   acImg: '/static/images/tabBar/tab_04.png'// },{pagePath: "/pages/mineDriver/mineDriver",index: 1,name: '我的',img: '/static/images/tabBar/tab_05.png',acImg: '/static/images/tabBar/tab_06.png'},
]export default {admin,finance,driver
}
// pages.json
{"pages": [{"path": "pages/homePage/homePage","style": {"navigationBarTitleText": "首页"// "navigationStyle": "custom"}},{"path": "pages/login","style": {"navigationBarTitleText": "登录"}},{"path": "pages/register","style": {"navigationBarTitleText": "注册"}},{"path": "pages/work/work","style": {"navigationBarTitleText": "工作台"}},{"path": "pages/mine/mine", //管理员"style": {"navigationBarTitleText": "我的"}},{"path": "pages/mineDriver/mineDriver", // 司机"style": {"navigationBarTitleText": "我的"}},{"path": "pages/mineFinance/mineFinance", // 财务"style": {"navigationBarTitleText": "我的"}},{"path": "pages/mine/avatar/index","style": {"navigationBarTitleText": "修改头像"}},{"path": "pages/mine/info/index","style": {"navigationBarTitleText": "个人信息"}},{"path": "pages/mine/info/edit","style": {"navigationBarTitleText": "编辑资料"}},{"path": "pages/mine/pwd/index","style": {"navigationBarTitleText": "修改密码"}},{"path": "pages/mine/setting/index","style": {"navigationBarTitleText": "应用设置"}},{"path": "pages/mine/help/index","style": {"navigationBarTitleText": "常见问题"}},{"path": "pages/mine/about/index","style": {"navigationBarTitleText": "关于我们"}},],"tabBar": {"custom": true, // 隐藏tabBar"color": "#000000","selectedColor": "#508af1", // 选中颜色"borderStyle": "white","backgroundColor": "#ffffff","list": [{"pagePath": "pages/homePage/homePage"// "iconPath": "static/images/tabbar/tab_01.png",// "selectedIconPath": "static/images/tabbar/tab_02.png",// "text": "首页"},// {//   "pagePath": "pages/work/work",//   "iconPath": "static/images/tabbar/work.png",//   "selectedIconPath": "static/images/tabbar/work_.png",//   "text": "工作台"// },{"pagePath": "pages/mine/mine"// "iconPath": "static/images/tabbar/tab_09.png",// "selectedIconPath": "static/images/tabbar/tab_10.png",// "text": "我的"},{"pagePath": "pages/mineDriver/mineDriver"// "iconPath": "static/images/tabbar/tab_09.png",// "selectedIconPath": "static/images/tabbar/tab_10.png",// "text": "我的"},{"pagePath": "pages/mineFinance/mineFinance"// "iconPath": "static/images/tabbar/tab_09.png",// "selectedIconPath": "static/images/tabbar/tab_10.png",// "text": "我的"}]},"globalStyle": {"navigationBarTextStyle": "black","navigationBarTitleText": "RuoYi","navigationBarBackgroundColor": "#FFFFFF"}
}
// 单页面 
// mine.vue管理员版"我的"页面 / mineDriver.vue司机版"我的"页面 / mineFinance.vue财务版"我的"页面<template><view class="page"><!-- tabBarShow:显示第几个tabbar 0是管理员 1是财务 2是司机--><cc-myTabbar :tabBarShow="0"></cc-myTabbar> </view>
</template><script>export default {data() {return {};},onReady() {uni.hideTabBar()},methods: {}}
</script><style scoped lang="scss">page {padding-bottom: 140rpx;}
</style>

上一篇文章,

vue2踩坑之项目:vue2+element实现前端导出_vue2导出 type为text/plain 找不到状态code值-CSDN博客文章浏览阅读392次,点赞8次,收藏9次。vue2踩坑之项目:vue2+element实现前端导出。安装插件依赖 npm i --save xlsx@0.17.0 file-saver@2.0.5,单页面引入 前端导出插件_vue2导出 type为text/plain 找不到状态code值https://blog.csdn.net/weixin_43928112/article/details/135685385

相关文章:

  • 【JS逆向一】逆向某站的 加密参数算法--仅供学习参考
  • STM32内部Flash
  • 跟着cherno手搓游戏引擎【23】项目维护、2D引擎之前的一些准备
  • 西工大计算机学院复试问题整理
  • 第6章 智能租房——前期准备
  • 第59讲订单数据下拉实现
  • 《剑指 Offer》专项突破版 - 面试题 36 : 详解后缀表达式(C++ 实现)
  • Android 11 webview webrtc无法使用问题
  • 《Django+React前后端分离项目开发实战:爱计划》 03 理解项目结构
  • 【More Effective C++】条款2:使用C++转型操作符
  • 微服务OAuth 2.1扩展额外信息到JWT并解析(Spring Security 6)
  • 力扣231. 2 的幂(数学,二分查找,位运算)
  • 亚马逊认证考试系列 - 知识点 - LightSail介绍
  • 网络选择流程分析(首选网络类型切换流程)
  • Git中为常用指令配置别名
  • [ JavaScript ] 数据结构与算法 —— 链表
  • 07.Android之多媒体问题
  • 2017年终总结、随想
  • Django 博客开发教程 16 - 统计文章阅读量
  • iBatis和MyBatis在使用ResultMap对应关系时的区别
  • PHP 7 修改了什么呢 -- 2
  • TCP拥塞控制
  • Tornado学习笔记(1)
  • vue的全局变量和全局拦截请求器
  • 计算机常识 - 收藏集 - 掘金
  • 区块链分支循环
  • 微服务核心架构梳理
  • 云大使推广中的常见热门问题
  • ionic入门之数据绑定显示-1
  • python最赚钱的4个方向,你最心动的是哪个?
  • 策略 : 一文教你成为人工智能(AI)领域专家
  • 微龛半导体获数千万Pre-A轮融资,投资方为国中创投 ...
  • ​ubuntu下安装kvm虚拟机
  • ​人工智能书单(数学基础篇)
  • ​如何防止网络攻击?
  • # C++之functional库用法整理
  • #NOIP 2014#Day.2 T3 解方程
  • #QT(TCP网络编程-服务端)
  • #stm32整理(一)flash读写
  • ()、[]、{}、(())、[[]]命令替换
  • (附源码)spring boot儿童教育管理系统 毕业设计 281442
  • (力扣)1314.矩阵区域和
  • (转) RFS+AutoItLibrary测试web对话框
  • (转)3D模板阴影原理
  • (转)总结使用Unity 3D优化游戏运行性能的经验
  • .NET 4 并行(多核)“.NET研究”编程系列之二 从Task开始
  • .NET CF命令行调试器MDbg入门(四) Attaching to Processes
  • .NET Framework与.NET Framework SDK有什么不同?
  • .NET MVC 验证码
  • .NET3.5下用Lambda简化跨线程访问窗体控件,避免繁复的delegate,Invoke(转)
  • .NET开发不可不知、不可不用的辅助类(三)(报表导出---终结版)
  • @private @protected @public
  • [20170713] 无法访问SQL Server
  • [C++从入门到精通] 14.虚函数、纯虚函数和虚析构(virtual)
  • [CDOJ 1343] 卿学姐失恋了