├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div id="app">
  3. <!-- 顶部菜单栏 -->
  4. <div v-if="showHeader" class="app-header">
  5. <router-link to="/">首页</router-link>
  6. <router-link to="/pages/novel/list">小说列表</router-link>
  7. <router-link to="/pages/author/apply">作者申请</router-link>
  8. <router-link to="/pages/search/index">搜索</router-link>
  9. </div>
  10. <!-- 主内容区 -->
  11. <router-view v-if="isRouterAlive" />
  12. <!-- 使用自定义TabBar组件 -->
  13. <CustomTabbar v-if="showTabBar" />
  14. </div>
  15. </template>
  16. <script>
  17. import CustomTabbar from '@/components/custom-tabbar/index.vue';
  18. export default {
  19. name: 'App',
  20. provide() {
  21. return {
  22. reload: this.reload
  23. }
  24. },
  25. components: { CustomTabbar },
  26. data() {
  27. return {
  28. // 确保所有属性都在这里定义
  29. isRouterAlive: true,
  30. showTabBar: false,
  31. showHeader: false,
  32. isMounted: false, // 添加组件挂载状态标志
  33. tabBarPages: [
  34. '/pages/index/index',
  35. '/pages/novel/list',
  36. '/pages/bookshelf/index',
  37. '/pages/me/index'
  38. ],
  39. hideMenuRoutes: [
  40. '/login',
  41. '/register',
  42. '/forgot-password',
  43. '/novel/reader'
  44. ]
  45. }
  46. },
  47. mounted() {
  48. this.isMounted = true;
  49. this.checkRouteAuth();
  50. this.initTheme();
  51. this.initStoreState();
  52. this.safeUpdateMenuVisibility();
  53. },
  54. beforeDestroy() {
  55. this.isMounted = false;
  56. },
  57. watch: {
  58. // 安全监听路由变化
  59. '$route': {
  60. immediate: true,
  61. handler(newRoute) {
  62. if (this.isMounted && newRoute && newRoute.path) {
  63. this.safeUpdateMenuVisibility();
  64. }
  65. }
  66. }
  67. },
  68. methods: {
  69. reload() {
  70. this.isRouterAlive = false;
  71. this.$nextTick(() => {
  72. this.isRouterAlive = true;
  73. this.safeUpdateMenuVisibility();
  74. });
  75. },
  76. safeUpdateMenuVisibility() {
  77. // 确保组件已挂载且路由对象存在
  78. if (!this.isMounted || !this.$route || !this.$route.path) return;
  79. const currentPath = this.$route.path;
  80. // 检查是否显示底部TabBar
  81. this.showTabBar = this.tabBarPages.some(path =>
  82. currentPath.includes(path) || currentPath === path
  83. );
  84. // 检查是否显示顶部菜单
  85. this.showHeader = !this.hideMenuRoutes.some(route =>
  86. currentPath.includes(route) || currentPath === route
  87. );
  88. },
  89. initStoreState() {
  90. const token = uni.getStorageSync('token') || '';
  91. const readingProgress = uni.getStorageSync('readingProgress') || 1;
  92. // 确保 store 存在
  93. if (this.$store) {
  94. this.$store.commit('SET_TOKEN', token);
  95. this.$store.commit('SET_READING_PROGRESS', readingProgress);
  96. }
  97. console.log('App launched, store:', this.$store ? this.$store.state : '未初始化');
  98. },
  99. initTheme() {
  100. // 主题初始化逻辑
  101. console.log('主题初始化完成');
  102. // 设置默认主题
  103. const themeName = uni.getStorageSync('selectedTheme') || 'aydzBlue';
  104. // 应用主题变量
  105. const themes = {
  106. aydzBlue: {
  107. '--primary-color': '#2a5caa',
  108. '--bg-color': '#e6f7ff',
  109. '--text-color': '#1a3353',
  110. '--card-bg': '#d0e8ff',
  111. '--header-bg': '#2a5caa'
  112. },
  113. default: {
  114. '--primary-color': '#1890ff',
  115. '--bg-color': '#f8f9fa',
  116. '--text-color': '#333',
  117. '--card-bg': '#ffffff'
  118. }
  119. };
  120. const theme = themes[themeName] || themes.default;
  121. // 应用主题变量
  122. Object.keys(theme).forEach(key => {
  123. document.documentElement.style.setProperty(key, theme[key]);
  124. });
  125. },
  126. checkRouteAuth() {
  127. // 简单的路由权限检查
  128. if (!this.$route || !this.$route.path) return;
  129. const authRequiredRoutes = [
  130. '/pages/author/apply',
  131. '/pages/bookshelf/index',
  132. '/pages/me/index'
  133. ];
  134. if (authRequiredRoutes.some(route => this.$route.path.includes(route))) {
  135. if (!this.$store.getters.token) {
  136. uni.showToast({ title: '请先登录', icon: 'none' });
  137. this.$router.push('/pages/login');
  138. }
  139. }
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss">
  145. @import '@/styles/index.scss';
  146. /* 全局样式修复 */
  147. #app {
  148. min-height: 100vh;
  149. background-color: var(--bg-color);
  150. color: var(--text-color);
  151. }
  152. /* 确保菜单不被其他元素覆盖 */
  153. .custom-tabbar {
  154. z-index: 99999 !important;
  155. position: fixed !important;
  156. bottom: 0 !important;
  157. left: 0 !important;
  158. right: 0 !important;
  159. }
  160. /* 修复页面内容被遮挡的问题 */
  161. .page-content {
  162. padding-bottom: 140rpx !important;
  163. }
  164. /* 确保tabbar显示 */
  165. uni-tabbar {
  166. display: flex !important;
  167. position: fixed;
  168. bottom: 0;
  169. left: 0;
  170. right: 0;
  171. z-index: 9999;
  172. background-color: #fff;
  173. box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  174. }
  175. /* 修复高度问题 */
  176. uni-tabbar .uni-tabbar {
  177. height: 50px !important;
  178. }
  179. /* 页面内容区域 */
  180. .page-content {
  181. padding-bottom: 60px !important;
  182. }
  183. .app-header {
  184. background: var(--header-bg, #2a5caa);
  185. padding: 10px;
  186. display: flex;
  187. justify-content: space-around;
  188. position: sticky;
  189. top: 0;
  190. z-index: 1000;
  191. a {
  192. color: white;
  193. text-decoration: none;
  194. font-weight: bold;
  195. &.router-link-exact-active {
  196. color: #ffcc00;
  197. border-bottom: 2px solid #ffcc00;
  198. }
  199. }
  200. }
  201. </style>