├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

App.vue 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="app-container">
  3. <router-view />
  4. <!-- 若依风格自定义菜单 -->
  5. <view v-if="showMenu" class="ruoyi-tabbar">
  6. <view
  7. v-for="(item, index) in menuItems"
  8. :key="index"
  9. class="tab-item"
  10. :class="{ active: activeIndex === index }"
  11. @click="switchTab(item, index)"
  12. >
  13. <image class="icon" :src="activeIndex === index ? item.activeIcon : item.icon" />
  14. <text class="text">{{ item.text }}</text>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import CustomTabbar from '@/components/custom-tabbar/index.vue'
  21. import config from './config'
  22. import { getToken } from '@/utils/auth'
  23. export default {
  24. components: { CustomTabbar },
  25. data() {
  26. return {
  27. activeIndex: 0,
  28. showMenu: true,
  29. menuItems: [
  30. {
  31. path: '/pages/index/index',
  32. icon: '/static/tabbar/home.png',
  33. activeIcon: '/static/tabbar/home_selected.png',
  34. text: '首页'
  35. },
  36. {
  37. path: '/pages/novel/list',
  38. icon: '/static/tabbar/novel.png',
  39. activeIcon: '/static/tabbar/novel_selected.png',
  40. text: '小说'
  41. },
  42. {
  43. path: '/pages/bookshelf/index',
  44. icon: '/static/tabbar/bookshelf.png',
  45. activeIcon: '/static/tabbar/bookshelf_selected.png',
  46. text: '书架'
  47. },
  48. {
  49. path: '/pages/me/index',
  50. icon: '/static/tabbar/mine.png',
  51. activeIcon: '/static/tabbar/mine_selected.png',
  52. text: '我的'
  53. }
  54. ]
  55. }
  56. },
  57. watch: {
  58. '$route.path': {
  59. immediate: true,
  60. handler(path) {
  61. // 确定当前激活的菜单项
  62. this.activeIndex = this.menuItems.findIndex(item =>
  63. path.startsWith(item.path)
  64. );
  65. // 决定是否显示菜单
  66. this.showMenu = this.activeIndex !== -1;
  67. }
  68. }
  69. },
  70. methods: {
  71. switchTab(item, index) {
  72. if (this.activeIndex === index) return;
  73. this.activeIndex = index;
  74. uni.switchTab({
  75. url: item.path
  76. });
  77. }
  78. },
  79. onLaunch() {
  80. // 初始化主题
  81. this.initTheme()
  82. // 检查阅读进度
  83. this.checkReadingProgress()
  84. // 初始化 store 状态
  85. this.initStoreState()
  86. // 检查登录状态
  87. //this.checkLogin()
  88. console.log('App launched, store:', this.$store)
  89. },
  90. onShow() {
  91. // 检查云端阅读进度
  92. if (this.$store.getters.token) {
  93. this.syncReadingProgress()
  94. }
  95. },
  96. methods: {
  97. // 初始化 store 状态
  98. initStoreState() {
  99. // 从本地存储恢复状态
  100. const token = uni.getStorageSync('token')
  101. const readingProgress = uni.getStorageSync('readingProgress') || 1
  102. // 提交到 store
  103. this.$store.commit('SET_TOKEN', token)
  104. this.$store.commit('SET_READING_PROGRESS', readingProgress)
  105. },
  106. // 检查阅读进度
  107. checkReadingProgress() {
  108. // 直接从本地存储读取
  109. const chapter = uni.getStorageSync('readingProgress') || 1
  110. if (chapter > 5 && !uni.getStorageSync('token')) {
  111. uni.showModal({
  112. title: '登录提示',
  113. content: `您已阅读到第${chapter}章,登录后继续阅读`,
  114. confirmText: '立即登录',
  115. success: (res) => {
  116. if (res.confirm) {
  117. uni.navigateTo({ url: '/pages/login' })
  118. }
  119. }
  120. })
  121. }
  122. },
  123. // 同步阅读进度 (修改后)
  124. async syncReadingProgress() {
  125. try {
  126. // 安全访问 store
  127. if (!this.$store) {
  128. console.warn('Store 未初始化,无法同步阅读进度')
  129. return
  130. }
  131. const token = this.$store.getters.token
  132. if (!token) {
  133. console.log('用户未登录,跳过同步')
  134. return
  135. }
  136. // 从本地存储获取进度
  137. const localChapter = uni.getStorageSync('readingProgress') || 1
  138. // 调用 API 同步
  139. const res = await this.$api.saveReadingProgress(localChapter)
  140. console.log('进度同步成功:', res.data)
  141. } catch (err) {
  142. console.error('同步阅读进度失败', err)
  143. }
  144. },
  145. // 添加 checkLogin 方法
  146. // checkLogin() {
  147. // // 这里写登录检查逻辑
  148. // // 示例:检查本地存储的登录状态
  149. // const isLoggedIn = uni.getStorageSync('isLogin');
  150. // if (!isLoggedIn) {
  151. // uni.navigateTo({ url: '/pages/login' });
  152. // }
  153. // },
  154. // 临时主题初始化
  155. initTheme() {
  156. const themeName = uni.getStorageSync('selectedTheme') || 'aydzBlue'
  157. // 应用主题变量
  158. const themes = {
  159. aydzBlue: {
  160. '--primary-color': '#2a5caa',
  161. '--bg-color': '#e6f7ff',
  162. '--text-color': '#1a3353',
  163. '--card-bg': '#d0e8ff',
  164. '--header-bg': '#2a5caa'
  165. },
  166. darkMode: {
  167. '--primary-color': '#52c41a',
  168. '--bg-color': '#1a1a1a',
  169. '--text-color': '#e6e6e6',
  170. '--card-bg': '#2a2a2a'
  171. },
  172. default: {
  173. '--primary-color': '#1890ff',
  174. '--bg-color': '#f8f9fa',
  175. '--text-color': '#333',
  176. '--card-bg': '#ffffff'
  177. }
  178. }
  179. const root = document.documentElement
  180. const themeVars = themes[themeName] || themes.aydzBlue
  181. Object.keys(themeVars).forEach(key => {
  182. root.style.setProperty(key, themeVars[key])
  183. })
  184. // 动态设置导航栏颜色
  185. if (themeName === 'darkMode') {
  186. uni.setNavigationBarColor({
  187. frontColor: '#ffffff',
  188. backgroundColor: '#1a1a1a'
  189. })
  190. } else if (themeName === 'aydzBlue') {
  191. uni.setNavigationBarColor({
  192. frontColor: '#ffffff',
  193. backgroundColor: '#2a5caa'
  194. })
  195. }
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss">
  201. /* 确保自定义TabBar有足够的空间 */
  202. .app-container {
  203. padding-bottom: 100rpx;
  204. }
  205. .ruoyi-tabbar {
  206. position: fixed;
  207. bottom: 0;
  208. left: 0;
  209. right: 0;
  210. display: flex;
  211. height: 100rpx;
  212. background-color: #fff;
  213. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
  214. z-index: 9999;
  215. border-top: 1rpx solid #eee;
  216. .tab-item {
  217. flex: 1;
  218. display: flex;
  219. flex-direction: column;
  220. align-items: center;
  221. justify-content: center;
  222. .icon {
  223. width: 44rpx;
  224. height: 44rpx;
  225. margin-bottom: 6rpx;
  226. }
  227. .text {
  228. font-size: 22rpx;
  229. color: #666;
  230. }
  231. .active .text {
  232. color: #3a8ee6; /* 若依主题蓝色 */
  233. font-weight: 500;
  234. }
  235. }
  236. }
  237. /* 确保tabbar显示 */
  238. uni-tabbar {
  239. display: flex !important;
  240. position: fixed;
  241. bottom: 0;
  242. left: 0;
  243. right: 0;
  244. z-index: 9999;
  245. background-color: #fff;
  246. box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  247. }
  248. /* 修复高度问题 */
  249. uni-tabbar .uni-tabbar {
  250. height: 50px !important;
  251. }
  252. /* 页面内容区域 */
  253. .page-content {
  254. padding-bottom: 60px !important;
  255. }
  256. /* 保留原有样式 */
  257. uni-tabbar {
  258. z-index: 999;
  259. }
  260. </style>