├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

App.vue 6.0KB

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