tui-tabbar.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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
  5. class="tui-tabbar-item"
  6. :class="{ 'tui-item-hump': item.hump }"
  7. :style="{ backgroundColor: item.hump ? 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 :class="{ 'tui-hump-box': hump }" v-if="hump && !unlined"></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: '#5677FC'
  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. watch: {
  87. current() {}
  88. },
  89. data() {
  90. return {};
  91. },
  92. methods: {
  93. tabbarSwitch(index, hump, pagePath, verify) {
  94. this.$emit('click', {
  95. index: index,
  96. hump: hump,
  97. pagePath: pagePath,
  98. verify: verify
  99. });
  100. }
  101. }
  102. };
  103. </script>
  104. <style scoped>
  105. .tui-tabbar {
  106. width: 100%;
  107. height: 100rpx;
  108. display: flex;
  109. align-items: center;
  110. justify-content: space-between;
  111. position: relative;
  112. }
  113. .tui-tabbar-fixed {
  114. position: fixed;
  115. z-index: 9999;
  116. left: 0;
  117. bottom: 0;
  118. padding-bottom: constant(safe-area-inset-bottom);
  119. padding-bottom: env(safe-area-inset-bottom);
  120. box-sizing: content-box !important;
  121. }
  122. .tui-tabbar::before {
  123. content: ' ';
  124. width: 100%;
  125. border-top: 1px solid #b2b2b2;
  126. position: absolute;
  127. top: 0;
  128. left: 0;
  129. transform: scaleY(0.5) translateZ(0);
  130. transform-origin: 0 0;
  131. display: block;
  132. z-index: 3;
  133. }
  134. .tui-tabbar-item {
  135. height: 100%;
  136. flex: 1;
  137. display: flex;
  138. text-align: center;
  139. align-items: center;
  140. flex-direction: column;
  141. justify-content: space-between;
  142. position: relative;
  143. padding: 10rpx 0;
  144. box-sizing: border-box;
  145. z-index: 5;
  146. }
  147. .tui-icon-box {
  148. position: relative;
  149. }
  150. .tui-item-hump {
  151. height: 98rpx;
  152. }
  153. .tui-tabbar-icon {
  154. width: 52rpx;
  155. height: 52rpx;
  156. display: block;
  157. }
  158. .tui-hump-box {
  159. width: 120rpx;
  160. height: 120rpx;
  161. background-color: #ffffff;
  162. position: absolute;
  163. left: 50%;
  164. transform: translateX(-50%);
  165. top: -50rpx;
  166. border-radius: 50%;
  167. z-index: 4;
  168. }
  169. .tui-hump-box::after {
  170. content: ' ';
  171. height: 200%;
  172. width: 200%;
  173. border: 1px solid #b2b2b2;
  174. position: absolute;
  175. top: 0;
  176. left: 0;
  177. transform: scale(0.5) translateZ(0);
  178. transform-origin: 0 0;
  179. border-radius: 120rpx;
  180. box-sizing: border-box;
  181. display: block;
  182. }
  183. .tui-unlined::after {
  184. height: 0 !important;
  185. }
  186. .tui-tabbar-hump {
  187. width: 100rpx;
  188. height: 100rpx;
  189. position: absolute;
  190. left: 50%;
  191. -webkit-transform: translateX(-50%) rotate(0deg);
  192. transform: translateX(-50%) rotate(0deg);
  193. top: -40rpx;
  194. -webkit-transition: all 0.2s linear;
  195. transition: all 0.2s linear;
  196. border-radius: 50%;
  197. z-index: 5;
  198. }
  199. .tui-tabbar-hump image {
  200. width: 100rpx;
  201. height: 100rpx;
  202. display: block;
  203. }
  204. .tui-hump-active {
  205. -webkit-transform: translateX(-50%) rotate(135deg);
  206. transform: translateX(-50%) rotate(135deg);
  207. }
  208. .tui-text-scale {
  209. font-weight: bold;
  210. transform: scale(0.8);
  211. font-size: 25rpx;
  212. line-height: 28rpx;
  213. transform-origin: center 100%;
  214. }
  215. .tui-text-hump {
  216. position: absolute;
  217. left: 50%;
  218. bottom: 10rpx;
  219. transform: scale(0.8) translateX(-50%);
  220. transform-origin: 0 100%;
  221. }
  222. .tui-badge {
  223. position: absolute;
  224. font-size: 24rpx;
  225. height: 32rpx;
  226. min-width: 20rpx;
  227. padding: 0 6rpx;
  228. border-radius: 40rpx;
  229. right: 0;
  230. top: -5rpx;
  231. transform: translateX(70%);
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. }
  236. .tui-badge-dot {
  237. position: absolute;
  238. height: 16rpx;
  239. width: 16rpx;
  240. border-radius: 50%;
  241. right: -4rpx;
  242. top: -4rpx;
  243. }
  244. </style>