tui-tabbar.vue 5.5 KB

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