金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.4 KiB

  1. <template>
  2. <view>
  3. <view class="occupy-position"></view>
  4. <view class="content">
  5. <view class="tabbar-box">
  6. <view class="tab-item"
  7. :class="{'tab-active': currentTabBar == index}"
  8. :style="{'width': 100 / show_count +'%'}"
  9. @click="clickTab(item, index)"
  10. v-if="item.show"
  11. v-for="(item, index) in tabbars" :key="index">
  12. <view class="tab-icon">
  13. <text class="lf-font-40 lf-iconfont" :class="item.icon"></text>
  14. </view>
  15. <view class="tab-name">{{ item.text }}</view>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import { mapGetters } from "vuex";
  23. export default {
  24. props: {
  25. type: {
  26. type: String, // 默认跳转方式redirect,可选switch
  27. default: 'redirect'
  28. }
  29. },
  30. data(){
  31. return {
  32. show_count: 0
  33. }
  34. },
  35. computed: {
  36. ...mapGetters(['currentTabBar', 'tabbars', 'isShowTabBar'])
  37. },
  38. created(){
  39. // 组件被创建时检查当前在哪个页面,然后校验currentTabBar是否与之匹配
  40. let pages = getCurrentPages();
  41. let page = pages[pages.length - 1].route;
  42. let tabbars = this.tabbars;
  43. let tabbar_name = tabbars[this.currentTabBar].path;
  44. let current = 0;
  45. let show_count = 0;
  46. tabbars.map((item, index) => {
  47. if(item.path == '/'+ page){
  48. current = index;
  49. }
  50. if(item.show){
  51. show_count++;
  52. }
  53. })
  54. this.show_count = show_count;
  55. if(tabbar_name != '/'+ page){
  56. this.$store.commit('setCurrentTabBar', current);
  57. }
  58. },
  59. methods: {
  60. clickTab(item, index){
  61. if(this.currentTabBar == index) return;
  62. this.$store.commit('setCurrentTabBar', index);
  63. uni.vibrateShort();
  64. this.$url(item.path, {type: this.type});
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped="scoped">
  70. .lf-font-40{
  71. font-size: 40rpx;
  72. }
  73. .occupy-position{
  74. width: 750rpx;
  75. height: 120rpx;
  76. box-sizing: content-box;
  77. padding-bottom: constant(safe-area-inset-bottom);
  78. padding-bottom: env(safe-area-inset-bottom);
  79. }
  80. .content{
  81. width: 750rpx;
  82. height: 120rpx;
  83. background-color: #FFFFFF;
  84. border-radius: 60rpx 60rpx 0 0;
  85. box-shadow: 0rpx -2rpx 8rpx 1rpx rgba(0, 0, 0, 0.1);
  86. position: fixed;
  87. bottom: 0;
  88. left: 0;
  89. z-index: 99999;
  90. padding-bottom: constant(safe-area-inset-bottom);
  91. padding-bottom: env(safe-area-inset-bottom);
  92. display: flex;
  93. align-items: center;
  94. box-sizing: content-box;
  95. .tabbar-box{
  96. width: 100%;
  97. height: 100rpx;
  98. display: flex;
  99. .tab-item{
  100. display: flex;
  101. justify-content: center;
  102. align-items: center;
  103. flex-direction: column;
  104. .tab-name{
  105. font-size: 24rpx;
  106. color: #777777;
  107. }
  108. &.tab-active{
  109. .tab-icon{
  110. background-color: #15716E;
  111. width: 60rpx;
  112. height: 60rpx;
  113. display: flex;
  114. justify-content: center;
  115. align-items: center;
  116. // transform: translateY(-20rpx) scale(1.4);
  117. border-radius: 50%;
  118. color: #FFFFFF;
  119. overflow: hidden;
  120. animation: wobble 1s .2s ease both;
  121. text{
  122. transform: scale(0.8);
  123. }
  124. }
  125. .tab-name{
  126. color: #15716E;
  127. font-weight: bold;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. @keyframes wobble{
  134. 0%{transform:translateX(0%)}
  135. 15%{transform:translateX(-25%) rotate(-5deg)}
  136. 30%{transform:translateX(20%) rotate(3deg)}
  137. 45%{transform:translateX(-15%) rotate(-3deg)}
  138. 60%{transform:translateX(10%) rotate(2deg)}
  139. 75%{transform:translateX(-5%) rotate(-1deg)}
  140. 99%{transform:translateX(0%)}
  141. 100%{transform: translateY(-20rpx) scale(1.4);}
  142. }
  143. </style>