tabbar.vue 3.5 KB

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