├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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