├── 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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. // 确保 initTheme 方法正确定义
  70. initTheme() {
  71. console.log('主题初始化开始');
  72. // 设置默认主题
  73. const themeName = uni.getStorageSync('selectedTheme') || 'aydzBlue';
  74. // 应用主题变量
  75. const themes = {
  76. aydzBlue: {
  77. '--primary-color': '#2a5caa',
  78. '--bg-color': '#e6f7ff',
  79. '--text-color': '#1a3353',
  80. '--card-bg': '#d0e8ff',
  81. '--header-bg': '#2a5caa'
  82. },
  83. default: {
  84. '--primary-color': '#1890ff',
  85. '--bg-color': '#f8f9fa',
  86. '--text-color': '#333',
  87. '--card-bg': '#ffffff'
  88. }
  89. };
  90. const theme = themes[themeName] || themes.default;
  91. // 应用主题变量
  92. Object.keys(theme).forEach(key => {
  93. document.documentElement.style.setProperty(key, theme[key]);
  94. });
  95. console.log('主题初始化完成');
  96. },
  97. reload() {
  98. this.isRouterAlive = false;
  99. this.$nextTick(() => {
  100. this.isRouterAlive = true;
  101. this.safeUpdateMenuVisibility();
  102. });
  103. },
  104. safeUpdateMenuVisibility() {
  105. // 确保组件已挂载且路由对象存在
  106. if (!this.isMounted || !this.$route || !this.$route.path) return;
  107. const currentPath = this.$route.path;
  108. // 检查是否显示底部TabBar
  109. this.showTabBar = this.tabBarPages.some(path =>
  110. currentPath.includes(path) || currentPath === path
  111. );
  112. // 检查是否显示顶部菜单
  113. this.showHeader = !this.hideMenuRoutes.some(route =>
  114. currentPath.includes(route) || currentPath === route
  115. );
  116. },
  117. initStoreState() {
  118. const token = uni.getStorageSync('token') || ''
  119. const readingProgress = uni.getStorageSync('readingProgress') || 1
  120. // 确保 store 存在并正确提交
  121. if (this.$store) {
  122. this.$store.commit('SET_TOKEN', token)
  123. this.$store.commit('SET_READING_PROGRESS', readingProgress)
  124. console.log('Store initialized:', this.$store.state)
  125. } else {
  126. console.error('Store is not available!')
  127. }
  128. },
  129. checkRouteAuth() {
  130. // 简单的路由权限检查
  131. if (!this.$route || !this.$route.path) return;
  132. const authRequiredRoutes = [
  133. '/pages/author/apply',
  134. '/pages/bookshelf/index',
  135. '/pages/me/index'
  136. ];
  137. if (authRequiredRoutes.some(route => this.$route.path.includes(route))) {
  138. if (!this.$store.getters.token) {
  139. uni.showToast({ title: '请先登录', icon: 'none' });
  140. this.$router.push('/pages/login');
  141. }
  142. }
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss">
  148. @import '@/styles/index.scss';
  149. /* 全局样式修复 */
  150. #app {
  151. min-height: 100vh;
  152. background-color: var(--bg-color);
  153. color: var(--text-color);
  154. }
  155. /* 确保菜单不被其他元素覆盖 */
  156. .custom-tabbar {
  157. z-index: 99999 !important;
  158. position: fixed !important;
  159. bottom: 0 !important;
  160. left: 0 !important;
  161. right: 0 !important;
  162. }
  163. /* 修复页面内容被遮挡的问题 */
  164. .page-content {
  165. padding-bottom: 140rpx !important;
  166. }
  167. /* 确保tabbar显示 */
  168. uni-tabbar {
  169. display: flex !important;
  170. position: fixed;
  171. bottom: 0;
  172. left: 0;
  173. right: 0;
  174. z-index: 9999;
  175. background-color: #fff;
  176. box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  177. }
  178. /* 修复高度问题 */
  179. uni-tabbar .uni-tabbar {
  180. height: 50px !important;
  181. }
  182. /* 页面内容区域 */
  183. .page-content {
  184. padding-bottom: 60px !important;
  185. }
  186. .app-header {
  187. background: var(--header-bg, #2a5caa);
  188. padding: 10px;
  189. display: flex;
  190. justify-content: space-around;
  191. position: sticky;
  192. top: 0;
  193. z-index: 1000;
  194. a {
  195. color: white;
  196. text-decoration: none;
  197. font-weight: bold;
  198. &.router-link-exact-active {
  199. color: #ffcc00;
  200. border-bottom: 2px solid #ffcc00;
  201. }
  202. }
  203. }
  204. </style>