tabbar.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="tabbar">
  3. <u-tabbar
  4. :value="tabbarValue"
  5. @change="tabbarChange"
  6. :fixed="true"
  7. :placeholder="true"
  8. :border="false"
  9. inactiveColor="#666"
  10. activeColor="#00A447"
  11. :customStyle="{'padding-top':'5px','border-top':'1px solid #eee','z-index':'30'}"
  12. :safeAreaInsetBottom="true"
  13. >
  14. <u-tabbar-item text="商城" >
  15. <image
  16. class="u-page__item__slot-icon"
  17. slot="active-icon"
  18. :src="staticUrl+'/img/tabbar-mall.png'"
  19. ></image>
  20. <image
  21. class="u-page__item__slot-icon"
  22. slot="inactive-icon"
  23. :src="staticUrl+'/img/tabbar-mall-gray.png'"
  24. ></image>
  25. </u-tabbar-item>
  26. <!-- <u-tabbar-item text="分类" >
  27. <image
  28. class="u-page__item__slot-icon"
  29. slot="active-icon"
  30. :src="staticUrl+'/img/tabbar-classify.png'"
  31. ></image>
  32. <image
  33. class="u-page__item__slot-icon"
  34. slot="inactive-icon"
  35. :src="staticUrl+'/img/tabbar-classify-gray.png'"
  36. ></image>
  37. </u-tabbar-item> -->
  38. <u-tabbar-item text="关于旭烁" >
  39. <image
  40. class="u-page__item__slot-icon"
  41. slot="active-icon"
  42. :src="staticUrl+'/img/tabbar-xushuo-v2.png'"
  43. ></image>
  44. <image
  45. class="u-page__item__slot-icon"
  46. slot="inactive-icon"
  47. :src="staticUrl+'/img/tabbar-xushuo-v2-gray.png'"
  48. ></image>
  49. </u-tabbar-item>
  50. <!-- <u-tabbar-item text="购物车" >
  51. <image
  52. class="u-page__item__slot-icon"
  53. slot="active-icon"
  54. src="/static/img/tabbar-car.png"
  55. ></image>
  56. <image
  57. class="u-page__item__slot-icon"
  58. slot="inactive-icon"
  59. src="/static/img/tabbar-car-gray.png"
  60. ></image>
  61. </u-tabbar-item> -->
  62. <u-tabbar-item text="我的" >
  63. <image
  64. class="u-page__item__slot-icon"
  65. slot="active-icon"
  66. :src="staticUrl+'/img/tabbar-my.png'"
  67. ></image>
  68. <image
  69. class="u-page__item__slot-icon"
  70. slot="inactive-icon"
  71. :src="staticUrl+'/img/tabbar-my-gray.png'"
  72. ></image>
  73. </u-tabbar-item>
  74. </u-tabbar>
  75. </view>
  76. </template>
  77. <script>
  78. export default {
  79. name: 'tabbar',
  80. props:{
  81. tabbarIndexProps:{
  82. type:Number,
  83. default:0
  84. },
  85. },
  86. data() {
  87. return {
  88. staticUrl:this.$commonConfig.staticUrl,
  89. tabbarValue:0,
  90. }
  91. },
  92. watch:{
  93. 'tabbarIndexProps': {
  94. handler(newVal, oldVal) {
  95. // let pages = getCurrentPages();
  96. // console.log('pages============',pages);
  97. this.tabbarValue = newVal
  98. },
  99. immediate: true
  100. }
  101. },
  102. onLoad() {
  103. console.log('onLoad tabbarIndex',this.tabbarIndex);
  104. },
  105. onShow() {
  106. console.log('tabbarIndex',this.tabbarIndex);
  107. this.tabbarValue = this.tabbarIndex
  108. },
  109. methods: {
  110. tabbarChange(name){
  111. console.log('name====',name);
  112. const tabBarRoutes = {
  113. 0: '/pages/index/index',
  114. // 1: {
  115. // url: '/shopping/producTypetList',
  116. // query: {
  117. // navType: 'navigateTo'
  118. // }
  119. // },
  120. 1: '/xushuo/xushuo',
  121. // 3: '/shopping/cart',
  122. 2: '/center/center'
  123. };
  124. const targetRoute = tabBarRoutes[name];
  125. if (typeof targetRoute === 'string') {
  126. uni.reLaunch({url: targetRoute});
  127. } else if (typeof targetRoute === 'object') {
  128. if(targetRoute.query.navType=='navigateTo'){
  129. this.$u.route(targetRoute.url, targetRoute.query);
  130. return
  131. }
  132. let queryParams = uni.$u.queryParams(targetRoute.query);
  133. uni.reLaunch({url: targetRoute.url+queryParams});
  134. }
  135. // this.tabbarValue = name
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .u-page__item__slot-icon{
  142. width: 40rpx;
  143. height: 40rpx;
  144. &.big{
  145. transform: scale(1.5) translateY(-0.5em);
  146. }
  147. }
  148. </style>