├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.vue 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="custom-tabbar">
  3. <view
  4. v-for="(item, index) in list"
  5. :key="index"
  6. class="custom-tabbar-item"
  7. :class="{ 'custom-tabbar-item-active': selectedIndex === index }"
  8. @click="switchTab(item, index)"
  9. >
  10. <image
  11. :src="selectedIndex === index ? item.selectedIcon : item.icon"
  12. class="custom-tabbar-icon"
  13. />
  14. <text class="custom-tabbar-text">{{ item.text }}</text>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. selectedIndex: 0,
  23. list: [
  24. {
  25. pagePath: "/pages/index/index",
  26. icon: "/static/tabbar/home.png",
  27. selectedIcon: "/static/tabbar/home_selected.png",
  28. text: "首页"
  29. },
  30. {
  31. pagePath: "/pages/novel/list",
  32. icon: "/static/tabbar/novel.png",
  33. selectedIcon: "/static/tabbar/novel_selected.png",
  34. text: "小说"
  35. },
  36. {
  37. pagePath: "/pages/bookshelf/index",
  38. icon: "/static/tabbar/bookshelf.png",
  39. selectedIcon: "/static/tabbar/bookshelf_selected.png",
  40. text: "书架"
  41. },
  42. {
  43. pagePath: "/pages/me/index",
  44. icon: "/static/tabbar/mine.png",
  45. selectedIcon: "/static/tabbar/mine_selected.png",
  46. text: "我的"
  47. }
  48. ]
  49. }
  50. },
  51. mounted() {
  52. this.updateSelectedIndex();
  53. },
  54. methods: {
  55. switchTab(item, index) {
  56. if (this.selectedIndex === index) return;
  57. this.selectedIndex = index;
  58. uni.switchTab({
  59. url: item.pagePath
  60. });
  61. },
  62. // 添加 ref 引用以便外部调用
  63. updateSelectedIndex() {
  64. const pages = getCurrentPages();
  65. if (!pages.length) return;
  66. const currentPage = pages[pages.length - 1];
  67. const currentRoute = currentPage.route;
  68. const index = this.list.findIndex(item =>
  69. currentRoute.includes(item.pagePath.replace('/pages/', '').replace('/index', ''))
  70. );
  71. if (index !== -1) {
  72. this.selectedIndex = index;
  73. }
  74. }
  75. }
  76. }
  77. </script>
  78. <style scoped>
  79. .custom-tabbar {
  80. position: fixed;
  81. bottom: 0;
  82. left: 0;
  83. right: 0;
  84. display: flex;
  85. height: 120rpx; /* 增加高度 */
  86. background-color: #ffffff;
  87. box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1); /* 增强阴影 */
  88. z-index: 99999;
  89. }
  90. .custom-tabbar-item {
  91. flex: 1;
  92. display: flex;
  93. flex-direction: column;
  94. align-items: center;
  95. justify-content: center;
  96. padding: 10rpx 0;
  97. }
  98. .custom-tabbar-icon {
  99. width: 52rpx;
  100. height: 52rpx;
  101. margin-bottom: 8rpx;
  102. }
  103. .custom-tabbar-text {
  104. font-size: 26rpx;
  105. color: #7a7e83;
  106. }
  107. .custom-tabbar-item-active .custom-tabbar-text {
  108. color: #3a8ee6; /* 使用若依主题蓝色 */
  109. font-weight: bold;
  110. font-size: 28rpx;
  111. }
  112. </style>