tui-tabbar.vue 5.4 KB

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