tui-tabbar.vue 5.7 KB

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