当前位置:   article > 正文

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

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.

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

 

  1. //cc-myTabbar.vue 底部导航组件
  2. <template>
  3. <view class="page-total">
  4. <view class="tab-list">
  5. <view class="list" v-for="(item,index) in TabBarList" @click="onTabBar(item,index)" :style="{marginTop: (item.name == '') ? '-88rpx' : '0px'}" :key="item.index">
  6. <image :src="item.acImg" mode="widthFix" v-show="tabBarShow ===index" :style="{width: (item.name == '') ? '100rpx' : '54rpx',borderRadius: (item.name == '') ? '24rpx' : '0rpx'}"></image>
  7. <image :src="item.img" mode="widthFix" v-show="tabBarShow != index" :style="{width: (item.name == '') ? '100rpx' : '54rpx',borderRadius: (item.name == '') ? '24rpx' : '0rpx'}"></image>
  8. <text :class="{'action':tabBarShow===index}">{{item.name}}</text>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. import tabBar from "@/utils/tabBar.js"
  15. // 判断当前登陆用户角色
  16. // 0 为管理员
  17. // 1 为财务
  18. // 2 为司机
  19. // 三元表达式判断当前登陆的用户角色
  20. // var user_type = uni.getStorageSync("userType")
  21. var user_type = 0
  22. let type = user_type === 0 ? 'admin' : user_type === 1 ? "finance" : "driver"
  23. const state = {
  24. list: tabBar[type]
  25. }
  26. // console.log(user_type, 'user_type');
  27. // console.log(type, 'type');
  28. // console.log(state, 'state');
  29. export default {
  30. data () {
  31. return {
  32. TabBarList: state.list,
  33. codeheight: 0,
  34. isOverall: 0,
  35. phoneModel: '',
  36. };
  37. },
  38. props: {
  39. tabBarShow: {
  40. type: Number,
  41. default: 0,
  42. }
  43. },
  44. mounted () {
  45. try {
  46. const res = uni.getSystemInfoSync();
  47. let that = this;
  48. // 获取系统信息
  49. uni.getSystemInfo({
  50. success (res) {
  51. console.log(res.brand) //手机牌子
  52. console.log(res.model) //手机型号
  53. console.log(res.screenWidth) //屏幕宽度
  54. console.log(res.screenHeight) //屏幕高度
  55. that.codeheight = Math.round(res.screenHeight);
  56. that.phoneModel = res.model
  57. if (res.model.search('iPhone')) {
  58. that.isOverall = 0;
  59. } else if (Math.round(res.screenHeight) > 740) {
  60. that.isOverall = 1;
  61. }
  62. console.log(that.isOverall);
  63. }
  64. });
  65. } catch (e) {
  66. // error
  67. }
  68. },
  69. methods: {
  70. // 底部导航 跳转
  71. onTabBar (item, index) {
  72. // this.tabBarShow = index;
  73. // console.log(item, 'item');
  74. // console.log(index, 'index');
  75. if (user_type == 2) { // 司机
  76. switch (item.name) {
  77. case '首页':
  78. uni.switchTab({
  79. url: '/pages/homePage/homePage'
  80. })
  81. break;
  82. case '':
  83. // uni.switchTab({
  84. // url: '/pages/scan/scan'
  85. // })
  86. // 允许从相机和相册扫码
  87. uni.scanCode({
  88. success: function (res) {
  89. console.log('条码类型:' + res.scanType);
  90. console.log('条码内容:' + res.result);
  91. }
  92. });
  93. break;
  94. case '我的':
  95. uni.switchTab({
  96. url: '/pages/mineDriver/mineDriver'
  97. })
  98. break;
  99. }
  100. } else if (user_type == 0) { //管理员
  101. switch (item.name) {
  102. case '首页':
  103. uni.switchTab({
  104. url: '/pages/homePage/homePage'
  105. })
  106. break;
  107. case '':
  108. // uni.switchTab({
  109. // url: '/pages/scan/scan'
  110. // })
  111. // 允许从相机和相册扫码
  112. uni.scanCode({
  113. success: function (res) {
  114. console.log('条码类型:' + res.scanType);
  115. console.log('条码内容:' + res.result);
  116. }
  117. });
  118. break;
  119. case '我的':
  120. uni.switchTab({
  121. url: '/pages/mine/mine'
  122. })
  123. break;
  124. }
  125. } else { // 财务
  126. switch (item.name) {
  127. case '首页':
  128. uni.switchTab({
  129. url: '/pages/homePage/homePage'
  130. })
  131. break;
  132. case '':
  133. // uni.switchTab({
  134. // url: '/pages/scan/scan'
  135. // })
  136. // 允许从相机和相册扫码
  137. uni.scanCode({
  138. success: function (res) {
  139. console.log('条码类型:' + res.scanType);
  140. console.log('条码内容:' + res.result);
  141. }
  142. });
  143. break;
  144. case '我的':
  145. uni.switchTab({
  146. url: '/pages/mineFinance/mineFinance'
  147. })
  148. break;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. @import 'cc-myTabbar.scss';
  157. </style>
  158. //在components文件夹里创建cc-myTabbar.scss
  159. //cc-myTabbar.scss
  160. /* 主要颜色 */
  161. $base: #508AF1; // 基础颜色
  162. .page-total {
  163. position: fixed;
  164. left: 0;
  165. bottom: 0;
  166. width: 100%;
  167. // height: 100rpx;
  168. }
  169. .tab-list {
  170. display: flex;
  171. justify-content: space-between;
  172. align-items: center;
  173. width: 100%;
  174. height: 140rpx;
  175. padding-bottom: 20rpx;
  176. background-color: #FFFFFF;
  177. // border-top: 1px solid #e8e8e8;
  178. .list {
  179. display: flex;
  180. flex-direction: column;
  181. align-items: center;
  182. justify-content: center;
  183. width: 38%;
  184. height: 120rpx;
  185. image {
  186. width: 48rpx;
  187. height: 48rpx;
  188. background-color: white;
  189. }
  190. text {
  191. color: #707070;
  192. font-weight: 900;
  193. font-size: 24rpx;
  194. margin-top: 10rpx;
  195. }
  196. .action {
  197. color: $base;
  198. }
  199. }
  200. }
  1. //tabBar.js
  2. // 小程序管理者
  3. const admin = [
  4. {
  5. pagePath: "/pages/homePage/homePage",
  6. index: 0,
  7. name: '首页',
  8. img: '/static/images/tabBar/tab_01.png',
  9. acImg: '/static/images/tabBar/tab_02.png'
  10. },
  11. // {
  12. // index: 2,
  13. // name: '',
  14. // img: '/static/images/tabBar/tab_03.png',
  15. // acImg: '/static/images/tabBar/tab_04.png'
  16. // },
  17. {
  18. pagePath: "/pages/mine/mine",
  19. index: 1,
  20. name: '我的',
  21. img: '/static/images/tabBar/tab_05.png',
  22. acImg: '/static/images/tabBar/tab_06.png'
  23. },
  24. ]
  25. // 财务
  26. const finance = [
  27. {
  28. pagePath: "/pages/homePage/homePage",
  29. index: 0,
  30. name: '首页',
  31. img: '/static/images/tabBar/tab_01.png',
  32. acImg: '/static/images/tabBar/tab_02.png'
  33. },
  34. // {
  35. // index: 1,
  36. // name: '',
  37. // img: '/static/images/tabBar/tab_03.png',
  38. // acImg: '/static/images/tabBar/tab_04.png'
  39. // },
  40. {
  41. pagePath: "/pages/mineFinance/mineFinance",
  42. index: 1,
  43. name: '我的',
  44. img: '/static/images/tabBar/tab_05.png',
  45. acImg: '/static/images/tabBar/tab_06.png'
  46. },
  47. ]
  48. // 司机
  49. const driver = [
  50. {
  51. pagePath: "/pages/homePage/homePage",
  52. index: 0,
  53. name: '首页',
  54. img: '/static/images/tabBar/tab_01.png',
  55. acImg: '/static/images/tabBar/tab_02.png'
  56. },
  57. // {
  58. // pagePath: "/pages/scan/scan",
  59. // index: 1,
  60. // name: '',
  61. // img: '/static/images/tabBar/tab_03.png',
  62. // acImg: '/static/images/tabBar/tab_04.png'
  63. // },
  64. {
  65. pagePath: "/pages/mineDriver/mineDriver",
  66. index: 1,
  67. name: '我的',
  68. img: '/static/images/tabBar/tab_05.png',
  69. acImg: '/static/images/tabBar/tab_06.png'
  70. },
  71. ]
  72. export default {
  73. admin,
  74. finance,
  75. driver
  76. }
  1. // pages.json
  2. {
  3. "pages": [
  4. {
  5. "path": "pages/homePage/homePage",
  6. "style": {
  7. "navigationBarTitleText": "首页"
  8. // "navigationStyle": "custom"
  9. }
  10. },
  11. {
  12. "path": "pages/login",
  13. "style": {
  14. "navigationBarTitleText": "登录"
  15. }
  16. },
  17. {
  18. "path": "pages/register",
  19. "style": {
  20. "navigationBarTitleText": "注册"
  21. }
  22. },
  23. {
  24. "path": "pages/work/work",
  25. "style": {
  26. "navigationBarTitleText": "工作台"
  27. }
  28. },
  29. {
  30. "path": "pages/mine/mine", //管理员
  31. "style": {
  32. "navigationBarTitleText": "我的"
  33. }
  34. },
  35. {
  36. "path": "pages/mineDriver/mineDriver", // 司机
  37. "style": {
  38. "navigationBarTitleText": "我的"
  39. }
  40. },
  41. {
  42. "path": "pages/mineFinance/mineFinance", // 财务
  43. "style": {
  44. "navigationBarTitleText": "我的"
  45. }
  46. },
  47. {
  48. "path": "pages/mine/avatar/index",
  49. "style": {
  50. "navigationBarTitleText": "修改头像"
  51. }
  52. },
  53. {
  54. "path": "pages/mine/info/index",
  55. "style": {
  56. "navigationBarTitleText": "个人信息"
  57. }
  58. },
  59. {
  60. "path": "pages/mine/info/edit",
  61. "style": {
  62. "navigationBarTitleText": "编辑资料"
  63. }
  64. },
  65. {
  66. "path": "pages/mine/pwd/index",
  67. "style": {
  68. "navigationBarTitleText": "修改密码"
  69. }
  70. },
  71. {
  72. "path": "pages/mine/setting/index",
  73. "style": {
  74. "navigationBarTitleText": "应用设置"
  75. }
  76. },
  77. {
  78. "path": "pages/mine/help/index",
  79. "style": {
  80. "navigationBarTitleText": "常见问题"
  81. }
  82. },
  83. {
  84. "path": "pages/mine/about/index",
  85. "style": {
  86. "navigationBarTitleText": "关于我们"
  87. }
  88. },
  89. ],
  90. "tabBar": {
  91. "custom": true, // 隐藏tabBar
  92. "color": "#000000",
  93. "selectedColor": "#508af1", // 选中颜色
  94. "borderStyle": "white",
  95. "backgroundColor": "#ffffff",
  96. "list": [
  97. {
  98. "pagePath": "pages/homePage/homePage"
  99. // "iconPath": "static/images/tabbar/tab_01.png",
  100. // "selectedIconPath": "static/images/tabbar/tab_02.png",
  101. // "text": "首页"
  102. },
  103. // {
  104. // "pagePath": "pages/work/work",
  105. // "iconPath": "static/images/tabbar/work.png",
  106. // "selectedIconPath": "static/images/tabbar/work_.png",
  107. // "text": "工作台"
  108. // },
  109. {
  110. "pagePath": "pages/mine/mine"
  111. // "iconPath": "static/images/tabbar/tab_09.png",
  112. // "selectedIconPath": "static/images/tabbar/tab_10.png",
  113. // "text": "我的"
  114. },
  115. {
  116. "pagePath": "pages/mineDriver/mineDriver"
  117. // "iconPath": "static/images/tabbar/tab_09.png",
  118. // "selectedIconPath": "static/images/tabbar/tab_10.png",
  119. // "text": "我的"
  120. },
  121. {
  122. "pagePath": "pages/mineFinance/mineFinance"
  123. // "iconPath": "static/images/tabbar/tab_09.png",
  124. // "selectedIconPath": "static/images/tabbar/tab_10.png",
  125. // "text": "我的"
  126. }
  127. ]
  128. },
  129. "globalStyle": {
  130. "navigationBarTextStyle": "black",
  131. "navigationBarTitleText": "RuoYi",
  132. "navigationBarBackgroundColor": "#FFFFFF"
  133. }
  134. }
  1. // 单页面
  2. // mine.vue管理员版"我的"页面 / mineDriver.vue司机版"我的"页面 / mineFinance.vue财务版"我的"页面
  3. <template>
  4. <view class="page">
  5. <!-- tabBarShow:显示第几个tabbar 0是管理员 1是财务 2是司机-->
  6. <cc-myTabbar :tabBarShow="0"></cc-myTabbar>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. data() {
  12. return {
  13. };
  14. },
  15. onReady() {
  16. uni.hideTabBar()
  17. },
  18. methods: {
  19. }
  20. }
  21. </script>
  22. <style scoped lang="scss">
  23. page {
  24. padding-bottom: 140rpx;
  25. }
  26. </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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/63722
推荐阅读
相关标签
  

闽ICP备14008679号