├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. created() {
  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. updateSelectedIndex() {
  63. const pages = getCurrentPages();
  64. if (!pages.length) return;
  65. const currentPage = pages[pages.length - 1];
  66. const currentRoute = currentPage.route;
  67. const index = this.list.findIndex(item =>
  68. item.pagePath.includes(currentRoute)
  69. );
  70. if (index !== -1) {
  71. this.selectedIndex = index;
  72. }
  73. }
  74. }
  75. }
  76. </script>
  77. <style scoped>
  78. .custom-tabbar {
  79. position: fixed;
  80. bottom: 0;
  81. left: 0;
  82. right: 0;
  83. display: flex;
  84. height: 100rpx;
  85. background-color: #ffffff;
  86. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
  87. z-index: 9999;
  88. }
  89. .custom-tabbar-item {
  90. flex: 1;
  91. display: flex;
  92. flex-direction: column;
  93. align-items: center;
  94. justify-content: center;
  95. }
  96. .custom-tabbar-icon {
  97. width: 48rpx;
  98. height: 48rpx;
  99. margin-bottom: 6rpx;
  100. }
  101. .custom-tabbar-text {
  102. font-size: 24rpx;
  103. color: #7a7e83;
  104. }
  105. .custom-tabbar-item-active .custom-tabbar-text {
  106. color: #3cc51f;
  107. font-weight: bold;
  108. }
  109. </style>