tui-tabbar.vue 6.2 KB

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