tui-tabbar.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="tui-tabbar" :class="{'tui-tabbar-fixed':isFixed,'tui-unlined':unlined}" :style="{background:backgroundColor}">
  3. <block v-for="(item,index) in tabBar" :key="index">
  4. <view class="tui-tabbar-item" :class="{'tui-item-hump':item.hump}"
  5. :style="{backgroundColor:item.hump?backgroundColor:'none'}" @tap="tabbarSwitch(index,item.hump,item.pagePath,item.verify)">
  6. <view class="tui-icon-box" :class="{'tui-tabbar-hump':item.hump}">
  7. <image :src="current==index?item.selectedIconPath:item.iconPath" :class="[item.hump?'':'tui-tabbar-icon']"></image>
  8. <view :class="[item.isDot?'tui-badge-dot':'tui-badge']" :style="{color:badgeColor,backgroundColor:badgeBgColor}"
  9. v-if="item.num">{{item.isDot?"":item.num}}</view>
  10. </view>
  11. <view class="tui-text-scale" :class="{'tui-text-hump':item.hump}" :style="{color:current==index?selectedColor:color}">{{item.text}}</view>
  12. </view>
  13. </block>
  14. <view :class="{'tui-hump-box':hump}" v-if="hump && !unlined"></view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: "tuiTabbar",
  20. props: {
  21. //当前索引
  22. current: {
  23. type: Number,
  24. default: 0
  25. },
  26. //字体颜色
  27. color: {
  28. type: String,
  29. default: "#666"
  30. },
  31. //字体选中颜色
  32. selectedColor: {
  33. type: String,
  34. default: "#C74547"
  35. },
  36. //背景颜色
  37. backgroundColor: {
  38. type: String,
  39. default: "#FFFFFF"
  40. },
  41. //是否需要中间凸起按钮
  42. hump: {
  43. type: Boolean,
  44. default: false
  45. },
  46. //固定在底部
  47. isFixed: {
  48. type: Boolean,
  49. default: true
  50. },
  51. //tabbar
  52. // "pagePath": "/pages/my/my", 页面路径
  53. // "text": "thor", 标题
  54. // "iconPath": "thor_gray.png", 图标地址
  55. // "selectedIconPath": "thor_active.png", 选中图标地址
  56. // "hump": true, 是否为凸起图标
  57. // "num": 2, 角标数量
  58. // "isDot": true, 角标是否为圆点
  59. // "verify": true 是否验证 (如登录)
  60. tabBar: {
  61. type: Array,
  62. default () {
  63. return []
  64. }
  65. },
  66. //角标字体颜色
  67. badgeColor: {
  68. type: String,
  69. default: "#fff"
  70. },
  71. //角标背景颜色
  72. badgeBgColor: {
  73. type: String,
  74. default: "#F74D54"
  75. },
  76. unlined: {
  77. type: Boolean,
  78. default: false
  79. }
  80. },
  81. watch: {
  82. current() {
  83. }
  84. },
  85. data() {
  86. return {
  87. };
  88. },
  89. methods: {
  90. tabbarSwitch(index, hump, pagePath,verify) {
  91. this.$emit("click", {
  92. index: index,
  93. hump: hump,
  94. pagePath: pagePath,
  95. verify:verify
  96. })
  97. }
  98. }
  99. }
  100. </script>
  101. <style>
  102. .tui-tabbar {
  103. width: 100%;
  104. height: 100rpx;
  105. display: flex;
  106. align-items: center;
  107. justify-content: space-between;
  108. position: relative;
  109. }
  110. .tui-tabbar-fixed {
  111. position: fixed;
  112. z-index: 99999;
  113. left: 0;
  114. bottom: 0;
  115. padding-bottom: env(safe-area-inset-bottom);
  116. }
  117. .tui-tabbar::before {
  118. content: '';
  119. width: 100%;
  120. border-top: 1rpx solid #B2B2B2;
  121. position: absolute;
  122. top: 0;
  123. left: 0;
  124. transform: scaleY(0.5);
  125. transform-origin: 0 100%;
  126. }
  127. .tui-tabbar-item {
  128. height: 100%;
  129. flex: 1;
  130. display: flex;
  131. text-align: center;
  132. align-items: center;
  133. flex-direction: column;
  134. justify-content: space-between;
  135. position: relative;
  136. padding: 10rpx 0;
  137. box-sizing: border-box;
  138. }
  139. .tui-icon-box {
  140. position: relative;
  141. }
  142. .tui-item-hump {
  143. height: 98rpx;
  144. z-index: 2;
  145. }
  146. .tui-tabbar-icon {
  147. width: 52rpx;
  148. height: 52rpx;
  149. display: block;
  150. }
  151. .tui-hump-box {
  152. width: 120rpx;
  153. height: 120rpx;
  154. background: #FFFFFF;
  155. position: absolute;
  156. left: 50%;
  157. transform: translateX(-50%);
  158. top: -50rpx;
  159. border-radius: 50%;
  160. z-index: 1;
  161. }
  162. .tui-hump-box::before {
  163. content: '';
  164. height: 200%;
  165. width: 200%;
  166. border: 1rpx solid #B2B2B2;
  167. position: absolute;
  168. top: 0;
  169. left: 0;
  170. transform: scale(0.5) translateZ(0);
  171. transform-origin: 0 0;
  172. border-radius: 100%;
  173. }
  174. .tui-unlined::before {
  175. border: 0 !important
  176. }
  177. .tui-tabbar-hump {
  178. width: 100rpx;
  179. height: 100rpx;
  180. position: absolute;
  181. left: 50%;
  182. transform: translateX(-50%) rotate(0deg);
  183. top: -40rpx;
  184. transition: all 0.2s linear;
  185. }
  186. .tui-tabbar-hump image {
  187. width: 100rpx;
  188. height: 100rpx;
  189. display: block;
  190. }
  191. .tui-hump-active {
  192. transform: translateX(-50%) rotate(135deg);
  193. }
  194. .tui-text-hump {
  195. position: absolute;
  196. bottom: 10rpx;
  197. }
  198. .tui-text-scale {
  199. font-weight: bold;
  200. transform: scale(0.8);
  201. font-size: 25rpx;
  202. line-height: 28rpx;
  203. transform-origin: center 100%;
  204. }
  205. .tui-badge {
  206. position: absolute;
  207. font-size: 24rpx;
  208. height: 32rpx;
  209. min-width: 20rpx;
  210. padding: 0 6rpx;
  211. border-radius: 40rpx;
  212. right: 0;
  213. top: -5rpx;
  214. transform: translateX(70%);
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. }
  219. .tui-badge-dot {
  220. position: absolute;
  221. height: 16rpx;
  222. width: 16rpx;
  223. border-radius: 50%;
  224. right: -4rpx;
  225. top: -4rpx;
  226. }
  227. </style>