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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/460479.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

NAT——网络地址转换、NAPT

网络地址转换 NAT (Network Address Translation) 1994 年提出。 需要在专用网连接到互联网的路由器上安装 NAT 软件。 装有 NAT 软件的路由器叫做 NAT路由器&#xff0c;它至少有一个有效的外部全球 IP 地址。 所有使用本地地址的主机在和外界通信时&#xff0c;都要在 NA…

MPLS VPN功能组件

VPN实例 VPN实例即为VPN路由转发表VRF&#xff0c;不同VPN之间的路由隔离通过VPN实例实现&#xff0c;PE上存在多个路由转发表&#xff0c;包括一个公网路由转发表&#xff0c;以及一个或多个VPN路由转发表。 PE为每个直接相连的Site建立并维护专门的VPN实例&#xff0c;VPN实…

构造 蓝桥OJ小蓝的无限集

样例输入 4 1 4 7 2 5 8 3 6 8 12 11 81 样例输出 No Yes No No #include<bits/stdc.h> using namespace std;using ll long long;bool rnk(ll a, ll b, ll n) {if((n-1) % b 0) return true;else if (a 1) return false;ll res 1;while(res < n){res * a;if (r…

FRP内网穿透如何避免SSH暴力破解(二)——指定地区允许访问

背景 上篇文章说到&#xff0c;出现了试图反复通过FRP的隧道&#xff0c;建立外网端口到内网服务器TCP链路的机器人&#xff0c;同时试图暴力破解ssh。这些连接造成了流量的浪费和不必要的通信开销。考虑到服务器使用者主要分布在A、B、C地区和国家&#xff0c;我打算对上一篇…

LC 993. 二叉树的堂兄弟节点

993. 二叉树的堂兄弟节点 难度&#xff1a; 简单 题目&#xff1a; 在二叉树中&#xff0c;根节点位于深度 0 处&#xff0c;每个深度为 k 的节点的子节点位于深度 k1 处。 如果二叉树的两个节点深度相同&#xff0c;但 父节点不同 &#xff0c;则它们是一对堂兄弟节点。 我…

【调试】pstore原理和使用方法总结

什么是pstore pstore最初是用于系统发生oops或panic时&#xff0c;自动保存内核log buffer中的日志。不过在当前内核版本中&#xff0c;其已经支持了更多的功能&#xff0c;如保存console日志、ftrace消息和用户空间日志。同时&#xff0c;它还支持将这些消息保存在不同的存储…

C#用Array类的FindAll方法和List<T>类的Add方法按关键词在数组中检索元素并输出

目录 一、使用的方法 1. Array.FindAll(T[], Predicate) 方法 &#xff08;1&#xff09;定义 &#xff08;2&#xff09;示例 2.List类的常用方法 &#xff08;1&#xff09;List.Add(T) 方法 &#xff08;2&#xff09;List.RemoveAt(Int32) 方法 &#xff08;3&…

stable_diffusion提示词编写笔记(1)

stable_diffusion提示词编写笔记(1) start 总结一下AI绘画学到的知识。 一.提示词分两种&#xff1a; 1.正向提示词&#xff1b; 2.反向提示词&#xff1b; 一个对应你希望图形包含的内容提示词&#xff0c;一个对应你不希望图形出现的内容提示词。 二.如何书写提示词 1.内…

gh0st远程控制——客户端界面编写(三)

◉ 主控端界面添加右键弹出菜单的功能 为Onlie_List区域添加右键弹出菜单项的功能&#xff1a; 3个视图&#xff1a;类视图、解决方案视图、资源视图 在资源视图下添加一个Menu&#xff1a; 更改Menu的ID为IDR_MENU_ONLINE&#xff1a; 为各控件添加便于区分的ID&#xff1a…

C语言函数栈帧的创建和销毁(逐步分析)

什么是函数栈帧 我们在写C语言代码的时候&#xff0c;经常会把一个独立的功能抽象为函数&#xff0c;所以C程序是以函数为基本单位的。 那函数是如何调用的&#xff1f;函数的返回值又是如何返回的&#xff1f;函数参数是如何传递的&#xff1f;这些问题都和函数栈帧有关系。 …

数据结构(C语言)代码实现(八)——顺序栈实现数值转换行编辑程序汉诺塔

目录 参考资料 顺序栈的实现 头文件SqStack.h&#xff08;顺序栈函数声明&#xff09; 源文件SqStack.cpp&#xff08;顺序栈函数实现&#xff09; 顺序栈的三个应用 数值转换 行编辑程序 顺序栈的实现测试 栈与递归的实现&#xff08;以汉诺塔为例&#xff09; 参考资…

Stable Diffusion 模型下载:Samaritan 3d Cartoon(撒玛利亚人 3d 卡通)

文章目录 模型介绍生成案例案例一案例二案例三案例四案例五案例六案例七案例八案例九案例十 下载地址 模型介绍 由“PromptSharingSamaritan”创作的撒玛利亚人 3d 卡通类型的大模型&#xff0c;该模型的基础模型为 SD 1.5。 条目内容类型大模型基础模型SD 1.5来源CIVITAI作者…