TabBar.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <template>
  2. <div class="tab-bar">
  3. <div class="tab-bar-content">
  4. <div
  5. class="tab-item"
  6. v-for="tab in tabs"
  7. :key="tab.path"
  8. @click="switchTab(tab.path)"
  9. :class="{ active: currentPath === tab.path }"
  10. >
  11. <div class="tab-icon-wrapper">
  12. <div class="tab-icon" :class="getIconClass(tab)">
  13. <i :class="tab.iconClass"></i>
  14. </div>
  15. <div class="active-indicator" v-if="currentPath === tab.path"></div>
  16. </div>
  17. <span class="tab-title">{{ tab.title }}</span>
  18. </div>
  19. </div>
  20. <!-- 背景装饰 -->
  21. <div class="tab-background"></div>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. name: 'TabBar',
  27. data() {
  28. return {
  29. currentPath: '/home',
  30. tabs: [
  31. {
  32. path: '/home',
  33. title: '首页',
  34. iconClass: 'icon-home',
  35. color: '#667eea'
  36. },
  37. {
  38. path: '/mall',
  39. title: '退休计划',
  40. iconClass: 'icon-plan',
  41. color: '#51cf66'
  42. },
  43. {
  44. path: '/Medical',
  45. title: '红旗基金',
  46. iconClass: 'icon-fund',
  47. color: '#ff6b6b'
  48. },
  49. {
  50. path: '/profile',
  51. title: '我的',
  52. iconClass: 'icon-profile',
  53. color: '#ffd43b'
  54. }
  55. ]
  56. }
  57. },
  58. methods: {
  59. switchTab(path) {
  60. this.currentPath = path
  61. this.$router.push(path)
  62. },
  63. getIconClass(tab) {
  64. return {
  65. 'active': this.currentPath === tab.path,
  66. [tab.iconClass]: true
  67. }
  68. }
  69. },
  70. created() {
  71. this.currentPath = this.$route.path
  72. },
  73. watch: {
  74. '$route'(to) {
  75. this.currentPath = to.path
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .tab-bar {
  82. position: fixed;
  83. bottom: 0;
  84. left: 0;
  85. right: 0;
  86. height: 75px;
  87. z-index: 999;
  88. padding: 0 15px 15px;
  89. box-sizing: border-box;
  90. }
  91. .tab-background {
  92. position: absolute;
  93. top: 0;
  94. left: 0;
  95. right: 0;
  96. bottom: 0;
  97. background: linear-gradient(145deg, #ffffff, #f8f9fa);
  98. border-radius: 25px 25px 0 0;
  99. box-shadow:
  100. 0 -12px 35px rgba(0, 0, 0, 0.15),
  101. 0 -6px 18px rgba(0, 0, 0, 0.1),
  102. inset 0 1px 0 rgba(255, 255, 255, 0.8);
  103. backdrop-filter: blur(15px);
  104. // 顶部高光效果
  105. &::before {
  106. content: '';
  107. position: absolute;
  108. top: 0;
  109. left: 50%;
  110. transform: translateX(-50%);
  111. width: 80px;
  112. height: 4px;
  113. background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.4), transparent);
  114. border-radius: 0 0 25px 25px;
  115. }
  116. }
  117. .tab-bar-content {
  118. position: relative;
  119. z-index: 2;
  120. height: 100%;
  121. display: flex;
  122. align-items: center;
  123. justify-content: space-around;
  124. padding: 12px 0;
  125. }
  126. .tab-item {
  127. flex: 1;
  128. display: flex;
  129. flex-direction: column;
  130. align-items: center;
  131. justify-content: center;
  132. cursor: pointer;
  133. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  134. padding: 10px 8px;
  135. border-radius: 16px;
  136. position: relative;
  137. &:hover {
  138. background: rgba(102, 126, 234, 0.06);
  139. transform: translateY(-3px);
  140. }
  141. &.active {
  142. .tab-title {
  143. color: #667eea;
  144. font-weight: 700;
  145. text-shadow: 0 1px 3px rgba(102, 126, 234, 0.2);
  146. transform: scale(1.05);
  147. }
  148. }
  149. }
  150. .tab-icon-wrapper {
  151. position: relative;
  152. margin-bottom: 6px;
  153. transition: all 0.3s ease;
  154. }
  155. .tab-icon {
  156. width: 32px;
  157. height: 32px;
  158. border-radius: 12px;
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. transition: all 0.3s ease;
  163. background: linear-gradient(145deg, #f8f9fa, #e9ecef);
  164. box-shadow:
  165. 0 4px 8px rgba(0, 0, 0, 0.1),
  166. inset 0 1px 0 rgba(255, 255, 255, 0.5);
  167. i {
  168. font-style: normal;
  169. font-size: 18px;
  170. font-weight: bold;
  171. color: #666;
  172. transition: all 0.3s ease;
  173. }
  174. &.active {
  175. background: linear-gradient(145deg, #667eea, #764ba2);
  176. box-shadow:
  177. 0 6px 16px rgba(102, 126, 234, 0.3),
  178. inset 0 1px 0 rgba(255, 255, 255, 0.2);
  179. transform: scale(1.1);
  180. i {
  181. color: white;
  182. text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  183. }
  184. }
  185. }
  186. .active-indicator {
  187. position: absolute;
  188. top: -4px;
  189. left: 50%;
  190. transform: translateX(-50%);
  191. width: 8px;
  192. height: 8px;
  193. background: linear-gradient(145deg, #667eea, #764ba2);
  194. border-radius: 50%;
  195. box-shadow:
  196. 0 3px 8px rgba(102, 126, 234, 0.4),
  197. 0 0 0 3px rgba(255, 255, 255, 0.9);
  198. animation: pulse 2s infinite;
  199. }
  200. .tab-title {
  201. font-size: 12px;
  202. color: #666;
  203. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  204. font-weight: 600;
  205. line-height: 1.2;
  206. text-align: center;
  207. letter-spacing: 0.5px;
  208. }
  209. // 脉搏动画
  210. @keyframes pulse {
  211. 0% {
  212. transform: translateX(-50%) scale(1);
  213. opacity: 1;
  214. }
  215. 50% {
  216. transform: translateX(-50%) scale(1.3);
  217. opacity: 0.7;
  218. }
  219. 100% {
  220. transform: translateX(-50%) scale(1);
  221. opacity: 1;
  222. }
  223. }
  224. // 首页图标
  225. .icon-home {
  226. i::before {
  227. content: '🏠';
  228. }
  229. &.active {
  230. background: linear-gradient(145deg, #667eea, #764ba2);
  231. }
  232. }
  233. // 退休计划图标
  234. .icon-plan {
  235. i::before {
  236. content: '📊';
  237. }
  238. &.active {
  239. background: linear-gradient(145deg, #51cf66, #40c057);
  240. }
  241. }
  242. // 红旗基金图标
  243. .icon-fund {
  244. i::before {
  245. content: '💰';
  246. }
  247. &.active {
  248. background: linear-gradient(145deg, #ff6b6b, #e74c3c);
  249. }
  250. }
  251. // 我的图标
  252. .icon-profile {
  253. i::before {
  254. content: '👤';
  255. }
  256. &.active {
  257. background: linear-gradient(145deg, #ffd43b, #fab005);
  258. }
  259. }
  260. // 点击反馈动画
  261. .tab-item:active {
  262. transform: translateY(-1px) scale(0.98);
  263. .tab-icon {
  264. transform: scale(0.95);
  265. }
  266. }
  267. // 为不同标签页的激活指示器添加特殊颜色
  268. .tab-item:nth-child(1).active {
  269. .active-indicator {
  270. background: linear-gradient(145deg, #667eea, #764ba2);
  271. }
  272. }
  273. .tab-item:nth-child(2).active {
  274. .active-indicator {
  275. background: linear-gradient(145deg, #51cf66, #40c057);
  276. }
  277. }
  278. .tab-item:nth-child(3).active {
  279. .active-indicator {
  280. background: linear-gradient(145deg, #ff6b6b, #e74c3c);
  281. }
  282. }
  283. .tab-item:nth-child(4).active {
  284. .active-indicator {
  285. background: linear-gradient(145deg, #ffd43b, #fab005);
  286. }
  287. }
  288. // 响应式设计
  289. @media (max-width: 375px) {
  290. .tab-bar {
  291. height: 68px;
  292. padding: 0 10px 10px;
  293. }
  294. .tab-icon {
  295. width: 28px;
  296. height: 28px;
  297. border-radius: 10px;
  298. i {
  299. font-size: 16px;
  300. }
  301. }
  302. .tab-title {
  303. font-size: 11px;
  304. }
  305. .active-indicator {
  306. width: 6px;
  307. height: 6px;
  308. }
  309. }
  310. @media (min-width: 414px) {
  311. .tab-bar {
  312. height: 80px;
  313. padding: 0 20px 20px;
  314. }
  315. .tab-icon {
  316. width: 36px;
  317. height: 36px;
  318. border-radius: 14px;
  319. i {
  320. font-size: 20px;
  321. }
  322. }
  323. .tab-title {
  324. font-size: 13px;
  325. }
  326. .active-indicator {
  327. width: 10px;
  328. height: 10px;
  329. }
  330. }
  331. // 添加微妙的进入动画
  332. .tab-item {
  333. animation: slideUp 0.5s ease-out;
  334. }
  335. @keyframes slideUp {
  336. from {
  337. opacity: 0;
  338. transform: translateY(20px);
  339. }
  340. to {
  341. opacity: 1;
  342. transform: translateY(0);
  343. }
  344. }
  345. // 为每个标签项添加延迟动画
  346. .tab-item:nth-child(1) { animation-delay: 0.1s; }
  347. .tab-item:nth-child(2) { animation-delay: 0.2s; }
  348. .tab-item:nth-child(3) { animation-delay: 0.3s; }
  349. .tab-item:nth-child(4) { animation-delay: 0.4s; }
  350. </style>