├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

App.vue 6.6KB

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