index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view class="tabbar-container">
  3. <block>
  4. <view class="tabbar-item"
  5. v-for="(item, index) in state.tabbarList" :key="index"
  6. :class="[item.centerItem ? ' center-item' : '']"
  7. @click="handleTabbarClick(item)">
  8. <view class="item-top"><image :src="state.currentItem == item.id ? item.selectIcon : item.icon" mode="widthFit"></image></view>
  9. <view class="item-bottom" :class="[state.currentItem == item.id ? 'item-active' : '',state.isIOS?'ios11':'']">
  10. <text>{{ item.text }}</text>
  11. </view>
  12. </view>
  13. </block>
  14. </view>
  15. </template>
  16. <script setup lang="ts" name="TabBar">
  17. import {onMounted, reactive, ref} from 'vue'
  18. import {onLoad, onShow} from "@dcloudio/uni-app";
  19. const props = defineProps({
  20. index: {
  21. type: Number,
  22. default: 0
  23. }
  24. })
  25. const state = reactive({
  26. currentItem:0,
  27. isIOS:false,
  28. tabbarList:[
  29. {
  30. id: 0,
  31. path: '/pages/index/index',
  32. icon: '/static/iconfont/default/Create-wash.svg',
  33. selectIcon: '/static/iconfont/Create-wash.svg',
  34. text: '网点',
  35. centerItem: false
  36. },
  37. {
  38. id: 1,
  39. path: '/pages-wash/scan/index',
  40. icon: '/static/tabbar/2.png',
  41. selectIcon: '/static/tabbar/2-1.png',
  42. text: '扫码',
  43. centerItem: true
  44. },
  45. {
  46. id: 2,
  47. path: '/pages/user/index',
  48. icon: '/static/iconfont/default/me.svg',
  49. selectIcon: '/static/iconfont/me.svg',
  50. text: '我的',
  51. centerItem: false
  52. }
  53. ]
  54. })
  55. onLoad(() => {
  56. state.currentItem = props.index;
  57. })
  58. onShow(() => {
  59. state.currentItem = props.index;
  60. const device = uni.getSystemInfoSync();
  61. state.isIOS = device.osName === "ios";
  62. })
  63. onMounted(()=>{
  64. state.currentItem = props.index;
  65. })
  66. const handleTabbarClick = (item: string) => {
  67. if(item.path.includes("scan")){
  68. uni.navigateTo({url:item.path})
  69. return;
  70. }
  71. uni.switchTab({
  72. url: item?.path,
  73. success: (e: any) => {
  74. console.log("tabbar switch>>>>", item,e)
  75. },
  76. fail: (e: any) => {
  77. console.error("swtich error >>>>>", JSON.stringify(e))
  78. }
  79. })
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. view {
  84. padding: 0;
  85. margin: 0;
  86. box-sizing: border-box;
  87. }
  88. .tabbar-container {
  89. position: fixed;
  90. bottom: 0;
  91. left: 0;
  92. width: 100%;
  93. height: 140rpx;
  94. //box-shadow: 0 0 3px #999;
  95. display: flex;
  96. align-items: center;
  97. padding: 25rpx 0;
  98. color: #999999;
  99. }
  100. .tabbar-container .tabbar-item {
  101. width: 33.3%;
  102. height: 100rpx;
  103. display: flex;
  104. flex-direction: column;
  105. justify-content: center;
  106. align-items: center;
  107. text-align: center;
  108. }
  109. .tabbar-container .item-active {
  110. color: $uni-color-primary;
  111. }
  112. .tabbar-container .center-item {
  113. display: block;
  114. position: relative;
  115. }
  116. .tabbar-container .tabbar-item .item-top {
  117. width: 70rpx;
  118. height: 70rpx;
  119. padding: 10rpx;
  120. }
  121. .tabbar-container .center-item .item-top {
  122. //flex-shrink: 0;
  123. width: 120rpx;
  124. height: 120rpx;
  125. position: absolute;
  126. top: -60rpx;
  127. left: calc(50% - 65rpx);
  128. border-radius: 50%;
  129. background-color: #ffffff;
  130. display: flex;
  131. justify-content: center;
  132. align-items: center;
  133. align-content: center;
  134. }
  135. .tabbar-container .center-item .item-top image{
  136. //width: 110rpx !important;
  137. //height: 110rpx !important;
  138. }
  139. .tabbar-container .tabbar-item .item-top image {
  140. width: 100%;
  141. height: 100%;
  142. }
  143. .tabbar-container .tabbar-item .item-bottom {
  144. font-size: 22rpx;
  145. width: 100%;
  146. }
  147. .tabbar-container .center-item .item-bottom {
  148. position: absolute;
  149. bottom: 0;
  150. }
  151. .ios{
  152. bottom: 30rpx !important;
  153. }
  154. </style>