fzzj hace 9 meses
padre
commit
ce02313439

+ 68
- 25
RuoYi-App/App.vue Ver fichero

@@ -10,13 +10,18 @@ import { getToken } from '@/utils/auth'
10 10
 
11 11
 export default {
12 12
   onLaunch() {
13
-    // 检查阅读进度
14
-    this.checkReadingProgress()  
15
-    // 初始化主题(临时实现)
13
+    // 初始化主题
16 14
     this.initTheme()
15
+    
16
+    // 检查阅读进度
17
+    this.checkReadingProgress()
18
+    
19
+    // 初始化 store 状态
20
+    this.initStoreState()
17 21
     // 检查登录状态
18 22
     //this.checkLogin()
19
-    
23
+      console.log('App launched, store:', this.$store)
24
+      console.log('TabBar config:', uni.getTabBar())
20 25
 
21 26
   },
22 27
   onShow() {
@@ -26,11 +31,21 @@ export default {
26 31
     }
27 32
   },
28 33
   methods: {
34
+    // 初始化 store 状态
35
+    initStoreState() {
36
+      // 从本地存储恢复状态
37
+      const token = uni.getStorageSync('token')
38
+      const readingProgress = uni.getStorageSync('readingProgress') || 1
39
+      
40
+      // 提交到 store
41
+      this.$store.commit('SET_TOKEN', token)
42
+      this.$store.commit('SET_READING_PROGRESS', readingProgress)
43
+    },
29 44
     // 检查阅读进度
30 45
     checkReadingProgress() {
46
+      // 直接从本地存储读取
31 47
       const chapter = uni.getStorageSync('readingProgress') || 1
32 48
       
33
-      // 如果用户阅读超过5章但未登录,提示登录
34 49
       if (chapter > 5 && !uni.getStorageSync('token')) {
35 50
         uni.showModal({
36 51
           title: '登录提示',
@@ -38,30 +53,37 @@ export default {
38 53
           confirmText: '立即登录',
39 54
           success: (res) => {
40 55
             if (res.confirm) {
41
-              uni.navigateTo({
42
-                url: '/pages/login'
43
-              })
56
+              uni.navigateTo({ url: '/pages/login' })
44 57
             }
45 58
           }
46 59
         })
47
-		}
48
-	},
49
-  async syncReadingProgress() {
50
-    try {
51
-      const res = await this.$api.getReadingProgress()
52
-      const cloudChapter = res.data.chapter
53
-      const localChapter = uni.getStorageSync('readingProgress') || 1
54
-      
55
-      // 使用最新的阅读进度
56
-      if (cloudChapter > localChapter) {
57
-        uni.setStorageSync('readingProgress', cloudChapter)
58
-      } else if (localChapter > cloudChapter) {
59
-        await this.$api.saveReadingProgress(localChapter)
60 60
       }
61
-    } catch (err) {
62
-      console.error('同步阅读进度失败', err)
63
-    }
64
-  },
61
+    },
62
+    // 同步阅读进度 (修改后)
63
+    async syncReadingProgress() {
64
+      try {
65
+        // 安全访问 store
66
+        if (!this.$store) {
67
+          console.warn('Store 未初始化,无法同步阅读进度')
68
+          return
69
+        }
70
+        
71
+        const token = this.$store.getters.token
72
+        if (!token) {
73
+          console.log('用户未登录,跳过同步')
74
+          return
75
+        }
76
+        
77
+        // 从本地存储获取进度
78
+        const localChapter = uni.getStorageSync('readingProgress') || 1
79
+        
80
+        // 调用 API 同步
81
+        const res = await this.$api.saveReadingProgress(localChapter)
82
+        console.log('进度同步成功:', res.data)
83
+      } catch (err) {
84
+        console.error('同步阅读进度失败', err)
85
+      }
86
+    },
65 87
     // 添加 checkLogin 方法
66 88
     // checkLogin() {
67 89
     //   // 这里写登录检查逻辑
@@ -124,6 +146,27 @@ export default {
124 146
 </script>
125 147
 
126 148
 <style lang="scss">
149
+/* 确保tabbar显示 */
150
+uni-tabbar {
151
+  display: flex !important;
152
+  position: fixed;
153
+  bottom: 0;
154
+  left: 0;
155
+  right: 0;
156
+  z-index: 9999;
157
+  background-color: #fff;
158
+  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
159
+}
160
+
161
+/* 修复高度问题 */
162
+uni-tabbar .uni-tabbar {
163
+  height: 50px !important;
164
+}
165
+
166
+/* 页面内容区域 */
167
+.page-content {
168
+  padding-bottom: 60px !important;
169
+}
127 170
 /* 保留原有样式 */
128 171
 uni-tabbar {
129 172
   z-index: 999;

+ 4
- 2
RuoYi-App/main.js Ver fichero

@@ -1,6 +1,7 @@
1 1
 import Vue from 'vue'
2 2
 import App from './App'
3
-import store from './store' // store
3
+import store from './store' // 确保路径正确
4
+
4 5
 import plugins from './plugins' // plugins
5 6
 import './permission' // permission
6 7
 import { getDicts } from "@/api/system/dict/data"
@@ -11,13 +12,14 @@ Vue.use(http)
11 12
 Vue.use(plugins)
12 13
 
13 14
 Vue.config.productionTip = false
15
+// 全局挂载 store
14 16
 Vue.prototype.$store = store
15 17
 Vue.prototype.getDicts = getDicts
16 18
 
17 19
 App.mpType = 'app'
18 20
 
19 21
 const app = new Vue({
22
+  store, // 关键:注入 store
20 23
   ...App
21 24
 })
22
-
23 25
 app.$mount()

+ 43
- 46
RuoYi-App/pages.json Ver fichero

@@ -7,13 +7,6 @@
7 7
         "enablePullDownRefresh": false
8 8
       }
9 9
     },
10
-	      {
11
-	        "path": "pages/novel/list",
12
-	        "style": {
13
-	                "navigationBarTitleText": "小说",
14
-	                "enablePullDownRefresh": false
15
-	              }
16
-	      },
17 10
     {
18 11
       "path": "pages/bookshelf/index",
19 12
       "style": {
@@ -27,56 +20,60 @@
27 20
       }
28 21
     },
29 22
     {
23
+      "path": "pages/novel/list", // 移动到tabBar页面组后面
24
+      "style": {
25
+        "navigationBarTitleText": "小说",
26
+        "enablePullDownRefresh": false
27
+      }
28
+    },
29
+    {
30 30
       "path": "pages/login",
31 31
       "style": {
32 32
         "navigationBarTitleText": "登录"
33 33
       }
34
-    }, 
34
+    },
35 35
     {
36
-    "path": "pages/register",
37
-    "style": {
38
-      "navigationBarTitleText": "注册"
39
-		}
40
-	}
41
-  ],
42
-  "tabBar": {
43
-    "color": "#7A7E83",
44
-    "selectedColor": "#2a5caa", // 使用主色调
45
-    "borderStyle": "white",
46
-    "backgroundColor": "#ffffff",
47
-    "height": "50px",
48
-    "list": [
49
-      {
50
-        "pagePath": "pages/index/index",
51
-        "iconPath": "static/images/tabbar/home.png",
52
-        "selectedIconPath": "static/tabbar/home_.png",
53
-        "text": "首页"
54
-      },
55
-	        {
56
-	          "pagePath": "pages/novel/list",
57
-	          "text": "小说"
58
-	        },
59
-      {
60
-        "pagePath": "pages/bookshelf/index",
61
-        "iconPath": "static/images/tabbar/work.png",
62
-        "selectedIconPath": "static/images/tabbar/work_.png",
63
-        "text": "书架"
64
-      },
65
-      {
66
-        "pagePath": "pages/me/index",
67
-        "iconPath": "static/images/tabbar/mine.png",
68
-        "selectedIconPath": "static/images/tabbar/mine_.png",
69
-        "text": "我的"
36
+      "path": "pages/register",
37
+      "style": {
38
+        "navigationBarTitleText": "注册"
70 39
       }
71
-    ]
72
-  },
40
+    }
41
+  ],
42
+"tabBar": {
43
+  "list": [
44
+    {
45
+      "pagePath": "pages/index/index",
46
+      "iconPath": "/static/tabbar/home.png",
47
+      "selectedIconPath": "/static/tabbar/home_selected.png",
48
+      "text": "首页"
49
+    },
50
+    {
51
+      "pagePath": "pages/novel/list",
52
+      "iconPath": "/static/tabbar/novel.png",
53
+      "selectedIconPath": "/static/tabbar/novel_selected.png",
54
+      "text": "小说"
55
+    },
56
+    {
57
+      "pagePath": "pages/bookshelf/index",
58
+      "iconPath": "/static/tabbar/bookshelf.png",
59
+      "selectedIconPath": "/static/tabbar/bookshelf_selected.png",
60
+      "text": "书架"
61
+    },
62
+    {
63
+      "pagePath": "pages/me/index",
64
+      "iconPath": "/static/tabbar/mine.png",
65
+      "selectedIconPath": "/static/tabbar/mine_selected.png",
66
+      "text": "我的"
67
+    }
68
+  ]
69
+},
73 70
   "globalStyle": {
74 71
     "navigationBarTextStyle": "black",
75 72
     "navigationBarTitleText": "哎呀免费小说",
76 73
     "navigationBarBackgroundColor": "#FFFFFF",
77 74
     "backgroundColor": "#F5F5F5",
78 75
     "app-plus": {
79
-      "titleNView": false // 禁用原生导航栏
76
+      "titleNView": false
80 77
     }
81 78
   }
82
-}
79
+}

+ 1
- 1
RuoYi-App/pages/index/index.vue Ver fichero

@@ -75,7 +75,7 @@ export default {
75 75
       recommendedBooks: [],
76 76
       serialBooks: [],
77 77
       currentReading: null,
78
-      showLoginPrompt: false,
78
+      //showLoginPrompt: false,
79 79
       maxFreeChapters: 5,
80 80
       freeChaptersRead: 0,
81 81
       currentChapter: 1, // 当前阅读章节

+ 6
- 1
RuoYi-App/pages/novel/list.vue Ver fichero

@@ -60,4 +60,9 @@ export default {
60 60
     }
61 61
   }
62 62
 }
63
-</script>
63
+</script>
64
+<style scoped>
65
+.novel-list-page {
66
+  padding-bottom: 120rpx !important;
67
+}
68
+</style>

+ 20
- 0
RuoYi-App/services/api.js Ver fichero

@@ -0,0 +1,20 @@
1
+import request from '@/utils/request'
2
+
3
+export default {
4
+  // 保存阅读进度
5
+  saveReadingProgress(chapter) {
6
+    return request({
7
+      url: '/java-api/reading/progress',
8
+      method: 'post',
9
+      data: { chapter }
10
+    })
11
+  },
12
+  
13
+  // 获取阅读进度
14
+  getReadingProgress() {
15
+    return request({
16
+      url: '/java-api/reading/progress',
17
+      method: 'get'
18
+    })
19
+  }
20
+}

BIN
RuoYi-App/static/tabbar/bookshelf.png Ver fichero


BIN
RuoYi-App/static/tabbar/bookshelf_selected.png Ver fichero


BIN
RuoYi-App/static/tabbar/home.png Ver fichero


BIN
RuoYi-App/static/tabbar/home_selected.png Ver fichero


BIN
RuoYi-App/static/tabbar/mine.png Ver fichero


BIN
RuoYi-App/static/tabbar/mine_selected.png Ver fichero


BIN
RuoYi-App/static/tabbar/novel.png Ver fichero


BIN
RuoYi-App/static/tabbar/novel_selected.png Ver fichero


+ 20
- 1
RuoYi-App/store/index.js Ver fichero

@@ -12,4 +12,23 @@ const store = new Vuex.Store({
12 12
   getters
13 13
 })
14 14
 
15
-export default store
15
+export default new Vuex.Store({
16
+  state: {
17
+    token: null,
18
+    readingProgress: 1
19
+  },
20
+  mutations: {
21
+    SET_TOKEN(state, token) {
22
+      state.token = token
23
+      uni.setStorageSync('token', token)
24
+    },
25
+    SET_READING_PROGRESS(state, progress) {
26
+      state.readingProgress = progress
27
+      uni.setStorageSync('readingProgress', progress)
28
+    }
29
+  },
30
+  getters: {
31
+    token: state => state.token,
32
+    getReadingProgress: state => state.readingProgress
33
+  }
34
+})

+ 1
- 1
RuoYi-App/utils/request.js Ver fichero

@@ -1,5 +1,5 @@
1 1
 import config from '@/config'
2
-
2
+import store from '@/store'
3 3
 const baseUrl = config.baseUrl
4 4
 
5 5
 export const http = {

Loading…
Cancelar
Guardar