├── 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 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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="/novel/list">小说列表</router-link>
  7. <router-link to="/author/apply">作者申请</router-link>
  8. <router-link to="/search">搜索</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. import config from './config'
  19. import { getToken } from '@/utils/auth'
  20. export default {
  21. mounted() {
  22. // 确保方法名称正确
  23. this.checkRouteAuth();
  24. },
  25. name: 'App',
  26. provide() {
  27. return {
  28. reload: this.reload
  29. }
  30. },
  31. components: { CustomTabbar },
  32. data() {
  33. return {
  34. isRouterAlive: true,
  35. showTabBar: false, // 默认不显示
  36. tabBarPages: [
  37. '/pages/index/index',
  38. '/pages/novel/list',
  39. '/pages/bookshelf/index',
  40. '/pages/me/index'
  41. ],
  42. // 定义需要隐藏菜单的路由
  43. hideMenuRoutes: [
  44. '/login',
  45. '/register',
  46. '/forgot-password',
  47. '/novel/reader'
  48. ]
  49. }
  50. },
  51. watch: {
  52. '$route.path': {
  53. immediate: true,
  54. handler(newPath) {
  55. // 检查当前页面是否需要显示菜单
  56. this.showTabBar = this.tabBarPages.some(path =>
  57. newPath.includes(path)
  58. );
  59. // 特殊处理:在小说阅读页面也显示菜单
  60. if (newPath.includes('/pages/novel/read')) {
  61. this.showTabBar = true;
  62. }
  63. // 强制更新CustomTabbar组件
  64. this.$nextTick(() => {
  65. if (this.$refs.customTabbar) {
  66. this.$refs.customTabbar.updateSelectedIndex();
  67. }
  68. });
  69. }
  70. }
  71. },
  72. onLaunch() {
  73. // 初始化主题
  74. this.initTheme()
  75. // 检查阅读进度
  76. this.checkReadingProgress()
  77. // 初始化 store 状态
  78. this.initStoreState()
  79. console.log('App launched, store:', this.$store)
  80. },
  81. onShow() {
  82. // 初始检查路由
  83. this.$nextTick(() => {
  84. const currentPath = this.$route.path;
  85. this.showTabBar = this.tabBarPages.some(path =>
  86. currentPath.includes(path)
  87. );
  88. });
  89. // 检查云端阅读进度
  90. if (this.$store.getters.token) {
  91. this.syncReadingProgress()
  92. }
  93. },
  94. methods: {
  95. checkRouteAuth() {
  96. const noAuthPaths = ['/', '/home', '/novel'];
  97. if (!noAuthPaths.includes(this.$route.path)) {
  98. // 需要登录的路径处理
  99. }
  100. },
  101. reload() {
  102. this.isRouterAlive = false
  103. this.$nextTick(() => {
  104. this.isRouterAlive = true
  105. })
  106. },
  107. updateMenuVisibility() {
  108. const currentPath = this.$route.path;
  109. // 检查当前路由是否需要隐藏菜单
  110. this.showHeader = !this.hideMenuRoutes.some(route => currentPath.includes(route));
  111. this.showFooter = !this.hideMenuRoutes.some(route => currentPath.includes(route));
  112. },
  113. // 初始化 store 状态
  114. initStoreState() {
  115. // 从本地存储恢复状态
  116. const token = uni.getStorageSync('token')
  117. const readingProgress = uni.getStorageSync('readingProgress') || 1
  118. // 提交到 store
  119. this.$store.commit('SET_TOKEN', token)
  120. this.$store.commit('SET_READING_PROGRESS', readingProgress)
  121. },
  122. // 检查阅读进度
  123. checkReadingProgress() {
  124. // 直接从本地存储读取
  125. const chapter = uni.getStorageSync('readingProgress') || 1
  126. if (chapter > 5 && !uni.getStorageSync('token')) {
  127. uni.showModal({
  128. title: '登录提示',
  129. content: `您已阅读到第${chapter}章,登录后继续阅读`,
  130. confirmText: '立即登录',
  131. success: (res) => {
  132. if (res.confirm) {
  133. uni.navigateTo({ url: '/pages/login' })
  134. }
  135. }
  136. })
  137. }
  138. },
  139. // 同步阅读进度 (修改后)
  140. async syncReadingProgress() {
  141. try {
  142. // 安全访问 store
  143. if (!this.$store) {
  144. console.warn('Store 未初始化,无法同步阅读进度')
  145. return
  146. }
  147. const token = this.$store.getters.token
  148. if (!token) {
  149. console.log('用户未登录,跳过同步')
  150. return
  151. }
  152. // 从本地存储获取进度
  153. const localChapter = uni.getStorageSync('readingProgress') || 1
  154. // 调用 API 同步
  155. const res = await this.$api.saveReadingProgress(localChapter)
  156. console.log('进度同步成功:', res.data)
  157. } catch (err) {
  158. console.error('同步阅读进度失败', err)
  159. }
  160. },
  161. // 添加 checkLogin 方法
  162. // checkLogin() {
  163. // // 这里写登录检查逻辑
  164. // // 示例:检查本地存储的登录状态
  165. // const isLoggedIn = uni.getStorageSync('isLogin');
  166. // if (!isLoggedIn) {
  167. // uni.navigateTo({ url: '/pages/login' });
  168. // }
  169. // },
  170. // 临时主题初始化
  171. initTheme() {
  172. const themeName = uni.getStorageSync('selectedTheme') || 'aydzBlue'
  173. // 应用主题变量
  174. const themes = {
  175. aydzBlue: {
  176. '--primary-color': '#2a5caa',
  177. '--bg-color': '#e6f7ff',
  178. '--text-color': '#1a3353',
  179. '--card-bg': '#d0e8ff',
  180. '--header-bg': '#2a5caa'
  181. },
  182. darkMode: {
  183. '--primary-color': '#52c41a',
  184. '--bg-color': '#1a1a1a',
  185. '--text-color': '#e6e6e6',
  186. '--card-bg': '#2a2a2a'
  187. },
  188. default: {
  189. '--primary-color': '#1890ff',
  190. '--bg-color': '#f8f9fa',
  191. '--text-color': '#333',
  192. '--card-bg': '#ffffff'
  193. }
  194. }
  195. const root = document.documentElement
  196. const themeVars = themes[themeName] || themes.aydzBlue
  197. Object.keys(themeVars).forEach(key => {
  198. root.style.setProperty(key, themeVars[key])
  199. })
  200. // 动态设置导航栏颜色
  201. if (themeName === 'darkMode') {
  202. uni.setNavigationBarColor({
  203. frontColor: '#ffffff',
  204. backgroundColor: '#1a1a1a'
  205. })
  206. } else if (themeName === 'aydzBlue') {
  207. uni.setNavigationBarColor({
  208. frontColor: '#ffffff',
  209. backgroundColor: '#2a5caa'
  210. })
  211. }
  212. }
  213. },
  214. watch: {
  215. '$route.path': {
  216. immediate: true,
  217. handler() {
  218. this.updateMenuVisibility();
  219. }
  220. }
  221. }
  222. }
  223. </script>
  224. <style lang="scss">
  225. /* 确保自定义TabBar有足够的空间 */
  226. .app-container {
  227. padding-bottom: 120rpx !important; /* 增加底部空间 */
  228. }
  229. /* 确保菜单不被其他元素覆盖 */
  230. .custom-tabbar {
  231. z-index: 99999 !important;
  232. position: fixed !important;
  233. bottom: 0 !important;
  234. left: 0 !important;
  235. right: 0 !important;
  236. }
  237. /* 修复页面内容被遮挡的问题 */
  238. .page-content {
  239. padding-bottom: 140rpx !important;
  240. }
  241. /* 确保tabbar显示 */
  242. uni-tabbar {
  243. display: flex !important;
  244. position: fixed;
  245. bottom: 0;
  246. left: 0;
  247. right: 0;
  248. z-index: 9999;
  249. background-color: #fff;
  250. box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  251. }
  252. /* 修复高度问题 */
  253. uni-tabbar .uni-tabbar {
  254. height: 50px !important;
  255. }
  256. /* 页面内容区域 */
  257. .page-content {
  258. padding-bottom: 60px !important;
  259. }
  260. /* 保留原有样式 */
  261. uni-tabbar {
  262. z-index: 999;
  263. }
  264. #app {
  265. display: flex;
  266. flex-direction: column;
  267. min-height: 100vh;
  268. }
  269. .app-header, .app-footer {
  270. background: #f5f5f5;
  271. padding: 10px;
  272. display: flex;
  273. justify-content: space-around;
  274. z-index: 1000;
  275. }
  276. .app-header {
  277. position: sticky;
  278. top: 0;
  279. }
  280. .app-footer {
  281. position: fixed;
  282. bottom: 0;
  283. width: 100%;
  284. }
  285. .router-link-active {
  286. color: #42b983;
  287. font-weight: bold;
  288. }
  289. </style>