├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

App.vue 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="app-container">
  3. <router-view />
  4. <!-- 使用自定义TabBar组件 -->
  5. <CustomTabbar v-if="showTabBar" />
  6. </view>
  7. </template>
  8. <script>
  9. import CustomTabbar from '@/components/custom-tabbar/index.vue'
  10. import config from './config'
  11. import { getToken } from '@/utils/auth'
  12. export default {
  13. components: { CustomTabbar },
  14. data() {
  15. return {
  16. showTabBar: false, // 默认不显示
  17. tabBarPages: [
  18. '/pages/index/index',
  19. '/pages/novel/list',
  20. '/pages/bookshelf/index',
  21. '/pages/me/index'
  22. ]
  23. }
  24. },
  25. watch: {
  26. '$route.path': {
  27. immediate: true,
  28. handler(newPath) {
  29. // 检查当前页面是否需要显示菜单
  30. this.showTabBar = this.tabBarPages.some(path =>
  31. newPath.includes(path)
  32. );
  33. // 特殊处理:在小说阅读页面也显示菜单
  34. if (newPath.includes('/pages/novel/read')) {
  35. this.showTabBar = true;
  36. }
  37. // 强制更新CustomTabbar组件
  38. this.$nextTick(() => {
  39. if (this.$refs.customTabbar) {
  40. this.$refs.customTabbar.updateSelectedIndex();
  41. }
  42. });
  43. }
  44. }
  45. },
  46. onLaunch() {
  47. // 初始化主题
  48. this.initTheme()
  49. // 检查阅读进度
  50. this.checkReadingProgress()
  51. // 初始化 store 状态
  52. this.initStoreState()
  53. console.log('App launched, store:', this.$store)
  54. },
  55. onShow() {
  56. // 初始检查路由
  57. this.$nextTick(() => {
  58. const currentPath = this.$route.path;
  59. this.showTabBar = this.tabBarPages.some(path =>
  60. currentPath.includes(path)
  61. );
  62. });
  63. // 检查云端阅读进度
  64. if (this.$store.getters.token) {
  65. this.syncReadingProgress()
  66. }
  67. },
  68. methods: {
  69. // 初始化 store 状态
  70. initStoreState() {
  71. // 从本地存储恢复状态
  72. const token = uni.getStorageSync('token')
  73. const readingProgress = uni.getStorageSync('readingProgress') || 1
  74. // 提交到 store
  75. this.$store.commit('SET_TOKEN', token)
  76. this.$store.commit('SET_READING_PROGRESS', readingProgress)
  77. },
  78. // 检查阅读进度
  79. checkReadingProgress() {
  80. // 直接从本地存储读取
  81. const chapter = uni.getStorageSync('readingProgress') || 1
  82. if (chapter > 5 && !uni.getStorageSync('token')) {
  83. uni.showModal({
  84. title: '登录提示',
  85. content: `您已阅读到第${chapter}章,登录后继续阅读`,
  86. confirmText: '立即登录',
  87. success: (res) => {
  88. if (res.confirm) {
  89. uni.navigateTo({ url: '/pages/login' })
  90. }
  91. }
  92. })
  93. }
  94. },
  95. // 同步阅读进度 (修改后)
  96. async syncReadingProgress() {
  97. try {
  98. // 安全访问 store
  99. if (!this.$store) {
  100. console.warn('Store 未初始化,无法同步阅读进度')
  101. return
  102. }
  103. const token = this.$store.getters.token
  104. if (!token) {
  105. console.log('用户未登录,跳过同步')
  106. return
  107. }
  108. // 从本地存储获取进度
  109. const localChapter = uni.getStorageSync('readingProgress') || 1
  110. // 调用 API 同步
  111. const res = await this.$api.saveReadingProgress(localChapter)
  112. console.log('进度同步成功:', res.data)
  113. } catch (err) {
  114. console.error('同步阅读进度失败', err)
  115. }
  116. },
  117. // 添加 checkLogin 方法
  118. // checkLogin() {
  119. // // 这里写登录检查逻辑
  120. // // 示例:检查本地存储的登录状态
  121. // const isLoggedIn = uni.getStorageSync('isLogin');
  122. // if (!isLoggedIn) {
  123. // uni.navigateTo({ url: '/pages/login' });
  124. // }
  125. // },
  126. // 临时主题初始化
  127. initTheme() {
  128. const themeName = uni.getStorageSync('selectedTheme') || 'aydzBlue'
  129. // 应用主题变量
  130. const themes = {
  131. aydzBlue: {
  132. '--primary-color': '#2a5caa',
  133. '--bg-color': '#e6f7ff',
  134. '--text-color': '#1a3353',
  135. '--card-bg': '#d0e8ff',
  136. '--header-bg': '#2a5caa'
  137. },
  138. darkMode: {
  139. '--primary-color': '#52c41a',
  140. '--bg-color': '#1a1a1a',
  141. '--text-color': '#e6e6e6',
  142. '--card-bg': '#2a2a2a'
  143. },
  144. default: {
  145. '--primary-color': '#1890ff',
  146. '--bg-color': '#f8f9fa',
  147. '--text-color': '#333',
  148. '--card-bg': '#ffffff'
  149. }
  150. }
  151. const root = document.documentElement
  152. const themeVars = themes[themeName] || themes.aydzBlue
  153. Object.keys(themeVars).forEach(key => {
  154. root.style.setProperty(key, themeVars[key])
  155. })
  156. // 动态设置导航栏颜色
  157. if (themeName === 'darkMode') {
  158. uni.setNavigationBarColor({
  159. frontColor: '#ffffff',
  160. backgroundColor: '#1a1a1a'
  161. })
  162. } else if (themeName === 'aydzBlue') {
  163. uni.setNavigationBarColor({
  164. frontColor: '#ffffff',
  165. backgroundColor: '#2a5caa'
  166. })
  167. }
  168. }
  169. },
  170. mounted() {
  171. this.checkInitialRoute();
  172. }
  173. }
  174. </script>
  175. <style lang="scss">
  176. /* 确保自定义TabBar有足够的空间 */
  177. .app-container {
  178. padding-bottom: 120rpx !important; /* 增加底部空间 */
  179. }
  180. /* 确保菜单不被其他元素覆盖 */
  181. .custom-tabbar {
  182. z-index: 99999 !important;
  183. position: fixed !important;
  184. bottom: 0 !important;
  185. left: 0 !important;
  186. right: 0 !important;
  187. }
  188. /* 修复页面内容被遮挡的问题 */
  189. .page-content {
  190. padding-bottom: 140rpx !important;
  191. }
  192. /* 确保tabbar显示 */
  193. uni-tabbar {
  194. display: flex !important;
  195. position: fixed;
  196. bottom: 0;
  197. left: 0;
  198. right: 0;
  199. z-index: 9999;
  200. background-color: #fff;
  201. box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  202. }
  203. /* 修复高度问题 */
  204. uni-tabbar .uni-tabbar {
  205. height: 50px !important;
  206. }
  207. /* 页面内容区域 */
  208. .page-content {
  209. padding-bottom: 60px !important;
  210. }
  211. /* 保留原有样式 */
  212. uni-tabbar {
  213. z-index: 999;
  214. }
  215. </style>