tabbar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 :badge="v.badge?v.badge:''" v-for="(v,k) in menuList" :key="k">
  5. <template v-slot:text>
  6. <uv-button :class="['uv-tabbar-item__text',index==k?'s':'not']" open-type="contact"
  7. v-if="v.code=='custom'"
  8. :customStyle="{border: 'none',padding: 0,height:'1rem', fontSize: '.75rem', color: (index==k?'var(--color)':'#7d7e80')}">
  9. {{v.name}}
  10. </uv-button>
  11. <view v-else :class="['uv-tabbar-item__text',index==k?'s':'not']">
  12. <span class="text">{{v.name}}</span>
  13. </view>
  14. </template>
  15. <template v-slot:inactive-icon>
  16. <uv-button open-type="contact" v-if="v.code=='custom'"
  17. :customStyle="{border: 'none',padding: 0,height:'2rem'}">
  18. <uv-image class="icon" :src="'/static/icons/'+v.icon+'.png'" width="32"
  19. mode="widthFix"></uv-image>
  20. </uv-button>
  21. <uv-image v-else class="icon" :src="'/static/icons/'+v.icon+'.png'" width="32"
  22. mode="widthFix"></uv-image>
  23. </template>
  24. <template v-slot:active-icon>
  25. <uv-button open-type="contact" v-if="v.code=='custom'"
  26. :customStyle="{border: 'none',padding: 0,height:'2rem'}">
  27. <uv-image class="icon" :src="'/static/icons/'+v.icon+'-active.png'" width="32"
  28. mode="widthFix"></uv-image>
  29. </uv-button>
  30. <uv-image v-else class="icon" :src="'/static/icons/'+v.icon+'-active.png'" width="32"
  31. mode="widthFix"></uv-image>
  32. </template>
  33. </uv-tabbar-item>
  34. </uv-tabbar>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. name: "tabbar",
  40. props: {
  41. index: {
  42. type: [Boolean, Number],
  43. default: 0
  44. },
  45. menuType: {
  46. type: [Boolean, Number],
  47. default: 1
  48. },
  49. },
  50. data() {
  51. return {
  52. tab: this.index,
  53. menuList: [{
  54. name: '首页',
  55. code: 'home',
  56. icon: 'home',
  57. page: '/pages/index/index'
  58. }, {
  59. name: '在线咨询',
  60. code: 'custom',
  61. icon: 'custom',
  62. }, {
  63. name: '我的',
  64. code: 'mine',
  65. icon: 'mine',
  66. page: '/pages/mine/index'
  67. }]
  68. };
  69. },
  70. created() {
  71. },
  72. watch: {
  73. index(val) {
  74. this.tab = val
  75. }
  76. },
  77. methods: {
  78. onFeedTap() {
  79. let platform = uni.getSystemInfoSync().platform
  80. // #ifdef APP-PLUS
  81. if (platform == "ios") {
  82. let UIImpactFeedbackGenerator = plus.ios.importClass('UIImpactFeedbackGenerator');
  83. let impact = new UIImpactFeedbackGenerator();
  84. impact.prepare();
  85. impact.init(1);
  86. impact.impactOccurred();
  87. }
  88. if (platform == "android") {
  89. uni.vibrateShort();
  90. }
  91. // #endif
  92. },
  93. pageTo(index) {
  94. let item = this.menuList[index]
  95. this.onFeedTap();
  96. console.log(item.page)
  97. if (item.code == 'custom') {
  98. return false;
  99. }
  100. // #ifdef H5
  101. if (item.page == '/pages/index/index' || item.page ==
  102. '/pages/mine/index') {
  103. uni.switchTab({
  104. url: item.page
  105. });
  106. } else {
  107. uni.navigateTo({
  108. url: item.page
  109. });
  110. }
  111. // #endif
  112. // #ifdef APP||APP-NVUE||APP-PLUS||APP-VUE||MP-WEIXIN||MP
  113. uni.switchTab({
  114. url: item.page
  115. });
  116. // #endif
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. #tabbar {
  123. position: relative;
  124. z-index: 999;
  125. width: 100%;
  126. min-height: 100rpx;
  127. border-top: .05rem solid #f2f2f2;
  128. .icon {
  129. width: 32rpx;
  130. max-height: 36px;
  131. }
  132. ::v-deep .uv-image__image {
  133. max-height: 36px;
  134. }
  135. }
  136. ::v-deep .uv-tabbar {
  137. color: #7d7e80;
  138. .uv-tabbar-item__text {
  139. color: #7d7e80;
  140. margin-top: 2px;
  141. font-size: 12px;
  142. }
  143. }
  144. .uv-tabbar-item__text {
  145. color: #7d7e80;
  146. margin-top: .2rem;
  147. font-size: .75rem;
  148. &.s {
  149. color: var(--color);
  150. }
  151. }
  152. </style>