tabbar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view id="tabbar">
  3. <uv-tabbar v-if="menuList.length>0" :value="index" @change="pageTo" activeColor="var(--color)">
  4. <uv-tabbar-item :text="v.name" :badge="v.badge?v.badge:''" v-for="(v,k) in menuList" :key="k">
  5. <span class="text">{{v.name}}</span>
  6. <template v-slot:inactive-icon>
  7. <uv-image class="icon" :src="'/static/icons/'+v.icon+'.png'" width="20" height="20"></uv-image>
  8. </template>
  9. <template v-slot:active-icon>
  10. <uv-image class="icon" :src="'/static/icons/'+v.icon+'-active.png'" width="20"
  11. height="20"></uv-image>
  12. </template>
  13. </uv-tabbar-item>
  14. </uv-tabbar>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: "tabbar",
  20. props: {
  21. index: {
  22. type: [Boolean, Number],
  23. default: 0
  24. },
  25. menuType: {
  26. type: [Boolean, Number],
  27. default: 1
  28. },
  29. },
  30. data() {
  31. return {
  32. tab: this.index,
  33. menuList: []
  34. };
  35. },
  36. created() {
  37. let userInfo = uni.getStorageSync('yd.userInfo');
  38. userInfo = typeof(userInfo) != 'undefined' && userInfo ? JSON.parse(userInfo) : {};
  39. let userType = typeof(userInfo.user_type) != 'undefined' && userInfo.user_type ? userInfo.user_type : 3;
  40. if (userType == 5 || this.menuType == 2) {
  41. this.menuList = this.$store.state.adminMenuList
  42. } else {
  43. this.menuList = this.$store.state.stockMenuList
  44. }
  45. },
  46. watch: {
  47. index(val) {
  48. this.tab = val
  49. }
  50. },
  51. methods: {
  52. onFeedTap() {
  53. let platform = uni.getSystemInfoSync().platform
  54. // #ifdef APP-PLUS
  55. if (platform == "ios") {
  56. let UIImpactFeedbackGenerator = plus.ios.importClass('UIImpactFeedbackGenerator');
  57. let impact = new UIImpactFeedbackGenerator();
  58. impact.prepare();
  59. impact.init(1);
  60. impact.impactOccurred();
  61. }
  62. if (platform == "android") {
  63. uni.vibrateShort();
  64. }
  65. // #endif
  66. },
  67. pageTo(index) {
  68. let item = this.menuList[index]
  69. this.onFeedTap();
  70. console.log(item.page)
  71. // #ifdef H5
  72. if (item.page == '/pages/index/index' || item.page == '/pages/group/create' || item.page ==
  73. '/pages/group/index' || item.page ==
  74. '/pages/mine/index') {
  75. uni.switchTab({
  76. url: item.page
  77. });
  78. } else {
  79. uni.navigateTo({
  80. url: item.page
  81. });
  82. }
  83. // #endif
  84. // #ifdef APP||APP-NVUE||APP-PLUS||APP-VUE||MP-WEIXIN||MP
  85. uni.switchTab({
  86. url: item.page
  87. });
  88. // #endif
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. #tabbar {
  95. position: relative;
  96. z-index: 999;
  97. width: 100%;
  98. min-height: 80rpx;
  99. border-top: .05rem solid #f2f2f2;
  100. .icon {
  101. width: 20rpx;
  102. }
  103. }
  104. .icon-left {
  105. margin-left: 20rpx;
  106. }
  107. .icon-right {
  108. margin-right: 20rpx;
  109. }
  110. </style>