tabbar.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view>
  3. <!-- <view>
  4. </view> -->
  5. <view style="height: 150rpx;"></view>
  6. <view class="tabbar-container" :class="isIpx?'IpxBot':''">
  7. <view class="tabbar-containers">
  8. <view class="tabbar-item" v-for="(item,index) in tabList" :class="[item.centerItem ? 'center-item' : '']"
  9. @click="changeItem(item)" :key="index">
  10. <view class="item-top">
  11. <image :src="tabId==item.id?item.selectIcon:item.icon" mode=""></image>
  12. </view>
  13. <view class="item-bottom" :class="[tabId==item.id ? 'item-active' : '']">
  14. <text>{{item.text}}</text>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. props: {
  24. currentPage: {
  25. type: Number,
  26. default: 0
  27. }
  28. },
  29. data() {
  30. return {
  31. //适配IPhoneX
  32. isIpx: false,
  33. //底部Tab
  34. tabId: 0,
  35. tabList: [{
  36. id: 0,
  37. path: "/pages/index/index",
  38. icon: "/static/table/tab1.png",
  39. selectIcon: "/static/table/tab1_pre.png",
  40. text: "首页",
  41. centerItem: false
  42. }, {
  43. id: 1,
  44. path: "/pages/code/code",
  45. icon: "/static/table/tab_code.png",
  46. selectIcon: "/static/table/tab_code.png",
  47. text: "",
  48. centerItem: true
  49. }, {
  50. id: 2,
  51. path: "/pages/mine/mine",
  52. icon: "/static/table/tab2.png",
  53. selectIcon: "/static/table/tab2_pre.png",
  54. text: "我的",
  55. centerItem: false
  56. }],
  57. };
  58. },
  59. mounted() {
  60. this.tabId = this.currentPage;
  61. //隐藏原生tab
  62. uni.hideTabBar();
  63. },
  64. created() {
  65. // 判断为 iPhone X 给予底部距离
  66. let that = this
  67. uni.getSystemInfo({
  68. success: function(res) {
  69. if (res.model.indexOf('iPhone X') !== -1) {
  70. that.isIpx = true;
  71. }
  72. }
  73. })
  74. },
  75. methods: {
  76. checkLogin() {
  77. var token = uni.getStorageSync('token')
  78. // var token = "df057579-73c8-4bdd-8312-f64db8efd699"
  79. if (token == undefined || token == '') {
  80. uni.reLaunch({
  81. url: '/pages/login/login'
  82. })
  83. return false
  84. }
  85. return true
  86. },
  87. // tab 切换
  88. changeItem(item) {
  89. var that=this;
  90. if (item.id == 1) {
  91. if (!this.checkLogin()) {
  92. return
  93. }
  94. // 判断是否能核销
  95. var businessId=uni.getStorageSync('businessId')
  96. if(businessId&&businessId=='-1'){
  97. uni.showToast({
  98. title:'暂无扫码核销权限',
  99. icon:"none"
  100. })
  101. }else{
  102. uni.navigateTo({
  103. url:'/pages/code/code'
  104. })
  105. }
  106. // uni.navigateTo({
  107. // url:item.path
  108. // })
  109. // console.log('点击中间' + '快速');
  110. } else {
  111. uni.switchTab({
  112. url: item.path,
  113. });
  114. }
  115. },
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. view {
  121. padding: 0;
  122. margin: 0;
  123. box-sizing: border-box;
  124. }
  125. .tabbar-container {
  126. position: fixed;
  127. bottom: 0;
  128. left: 0;
  129. width: 100%;
  130. background-color: #FFFFFF;
  131. }
  132. .tabbar-containers {
  133. height: 134rpx;
  134. box-sizing: border-box;
  135. /* height: 100rpx; */
  136. /* box-shadow: 0 0 5px #999; */
  137. box-shadow: 0px -6px 11px 0px rgba(215, 215, 215, 0.4);
  138. display: flex;
  139. align-items: center;
  140. /* padding: 24rpx 0; */
  141. color: #999999;
  142. }
  143. .tabbar-container .tabbar-item {
  144. width: 33.33%;
  145. /* height: 100rpx; */
  146. display: flex;
  147. flex-direction: column;
  148. justify-content: center;
  149. align-items: center;
  150. text-align: center;
  151. }
  152. .tabbar-container .item-active {
  153. color: #343434;
  154. }
  155. .tabbar-container .center-item {
  156. display: block;
  157. position: relative;
  158. }
  159. .tabbar-container .tabbar-item .item-top {
  160. width: 46rpx;
  161. height: 48rpx;
  162. margin-bottom: 10rpx;
  163. /* padding: 5rpx; */
  164. }
  165. .tabbar-container .center-item .item-top {
  166. flex-shrink: 0;
  167. width: 138rpx;
  168. height: 136rpx;
  169. position: absolute;
  170. bottom:calc(50% - 40rpx);
  171. left: calc(50% - 69rpx);
  172. border-radius: 50%;
  173. /* background-color: #FFFFFF; */
  174. /* box-shadow: 0px -6px 11px 0px rgba(215, 215, 215, 0.4); */
  175. }
  176. .tabbar-container .tabbar-item .item-top image {
  177. width: 100%;
  178. height: 100%;
  179. }
  180. .tabbar-container .tabbar-item .item-bottom {
  181. font-size: 26rpx;
  182. width: 100%;
  183. }
  184. .tabbar-container .center-item .item-bottom {
  185. position: absolute;
  186. bottom: 2rpx;
  187. }
  188. /* 适配iPhone X */
  189. .IpxBot {
  190. padding-bottom: 30rpx !important;
  191. }
  192. </style>