金诚优选前端代码
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.

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