├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

App.vue 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="app-container">
  3. <router-view />
  4. </view>
  5. </template>
  6. <script>
  7. import config from './config'
  8. import { getToken } from '@/utils/auth'
  9. export default {
  10. onLaunch() {
  11. // 初始化主题
  12. this.initTheme()
  13. // 检查阅读进度
  14. this.checkReadingProgress()
  15. // 初始化 store 状态
  16. this.initStoreState()
  17. // 检查登录状态
  18. //this.checkLogin()
  19. console.log('App launched, store:', this.$store)
  20. console.log('TabBar config:', uni.getTabBar())
  21. },
  22. onShow() {
  23. // 检查云端阅读进度
  24. if (this.$store.getters.token) {
  25. this.syncReadingProgress()
  26. }
  27. },
  28. methods: {
  29. // 初始化 store 状态
  30. initStoreState() {
  31. // 从本地存储恢复状态
  32. const token = uni.getStorageSync('token')
  33. const readingProgress = uni.getStorageSync('readingProgress') || 1
  34. // 提交到 store
  35. this.$store.commit('SET_TOKEN', token)
  36. this.$store.commit('SET_READING_PROGRESS', readingProgress)
  37. },
  38. // 检查阅读进度
  39. checkReadingProgress() {
  40. // 直接从本地存储读取
  41. const chapter = uni.getStorageSync('readingProgress') || 1
  42. if (chapter > 5 && !uni.getStorageSync('token')) {
  43. uni.showModal({
  44. title: '登录提示',
  45. content: `您已阅读到第${chapter}章,登录后继续阅读`,
  46. confirmText: '立即登录',
  47. success: (res) => {
  48. if (res.confirm) {
  49. uni.navigateTo({ url: '/pages/login' })
  50. }
  51. }
  52. })
  53. }
  54. },
  55. // 同步阅读进度 (修改后)
  56. async syncReadingProgress() {
  57. try {
  58. // 安全访问 store
  59. if (!this.$store) {
  60. console.warn('Store 未初始化,无法同步阅读进度')
  61. return
  62. }
  63. const token = this.$store.getters.token
  64. if (!token) {
  65. console.log('用户未登录,跳过同步')
  66. return
  67. }
  68. // 从本地存储获取进度
  69. const localChapter = uni.getStorageSync('readingProgress') || 1
  70. // 调用 API 同步
  71. const res = await this.$api.saveReadingProgress(localChapter)
  72. console.log('进度同步成功:', res.data)
  73. } catch (err) {
  74. console.error('同步阅读进度失败', err)
  75. }
  76. },
  77. // 添加 checkLogin 方法
  78. // checkLogin() {
  79. // // 这里写登录检查逻辑
  80. // // 示例:检查本地存储的登录状态
  81. // const isLoggedIn = uni.getStorageSync('isLogin');
  82. // if (!isLoggedIn) {
  83. // uni.navigateTo({ url: '/pages/login' });
  84. // }
  85. // },
  86. // 临时主题初始化
  87. initTheme() {
  88. const themeName = uni.getStorageSync('selectedTheme') || 'aydzBlue'
  89. // 应用主题变量
  90. const themes = {
  91. aydzBlue: {
  92. '--primary-color': '#2a5caa',
  93. '--bg-color': '#e6f7ff',
  94. '--text-color': '#1a3353',
  95. '--card-bg': '#d0e8ff',
  96. '--header-bg': '#2a5caa'
  97. },
  98. darkMode: {
  99. '--primary-color': '#52c41a',
  100. '--bg-color': '#1a1a1a',
  101. '--text-color': '#e6e6e6',
  102. '--card-bg': '#2a2a2a'
  103. },
  104. default: {
  105. '--primary-color': '#1890ff',
  106. '--bg-color': '#f8f9fa',
  107. '--text-color': '#333',
  108. '--card-bg': '#ffffff'
  109. }
  110. }
  111. const root = document.documentElement
  112. const themeVars = themes[themeName] || themes.aydzBlue
  113. Object.keys(themeVars).forEach(key => {
  114. root.style.setProperty(key, themeVars[key])
  115. })
  116. // 动态设置导航栏颜色
  117. if (themeName === 'darkMode') {
  118. uni.setNavigationBarColor({
  119. frontColor: '#ffffff',
  120. backgroundColor: '#1a1a1a'
  121. })
  122. } else if (themeName === 'aydzBlue') {
  123. uni.setNavigationBarColor({
  124. frontColor: '#ffffff',
  125. backgroundColor: '#2a5caa'
  126. })
  127. }
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss">
  133. /* 确保tabbar显示 */
  134. uni-tabbar {
  135. display: flex !important;
  136. position: fixed;
  137. bottom: 0;
  138. left: 0;
  139. right: 0;
  140. z-index: 9999;
  141. background-color: #fff;
  142. box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  143. }
  144. /* 修复高度问题 */
  145. uni-tabbar .uni-tabbar {
  146. height: 50px !important;
  147. }
  148. /* 页面内容区域 */
  149. .page-content {
  150. padding-bottom: 60px !important;
  151. }
  152. /* 保留原有样式 */
  153. uni-tabbar {
  154. z-index: 999;
  155. }
  156. </style>