├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

useReadingProgress.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { ref } from 'vue'
  2. export function useReadingProgress() {
  3. // 保存阅读进度
  4. const saveProgress = (novelId, chapterId, progress) => {
  5. try {
  6. const key = `reading_progress_${novelId}_${chapterId}`
  7. uni.setStorageSync(key, JSON.stringify(progress))
  8. // 同时保存到云端(如果有登录)
  9. if (uni.getStorageSync('token')) {
  10. uni.request({
  11. url: 'https://api.aiyadianzi.ltd/reading/progress',
  12. method: 'POST',
  13. data: {
  14. novelId,
  15. chapterId,
  16. ...progress
  17. },
  18. header: {
  19. 'Authorization': `Bearer ${uni.getStorageSync('token')}`
  20. }
  21. })
  22. }
  23. } catch (e) {
  24. console.error('保存阅读进度失败', e)
  25. }
  26. }
  27. // 加载阅读进度
  28. const loadProgress = (novelId, chapterId) => {
  29. return new Promise((resolve) => {
  30. try {
  31. // 先尝试从本地加载
  32. const key = `reading_progress_${novelId}_${chapterId}`
  33. const localData = uni.getStorageSync(key)
  34. if (localData) {
  35. resolve(JSON.parse(localData))
  36. return
  37. }
  38. // 如果登录了,尝试从云端加载
  39. if (uni.getStorageSync('token')) {
  40. uni.request({
  41. url: `https://api.aiyadianzi.ltd/reading/progress?novelId=${novelId}&chapterId=${chapterId}`,
  42. method: 'GET',
  43. header: {
  44. 'Authorization': `Bearer ${uni.getStorageSync('token')}`
  45. },
  46. success: (res) => {
  47. if (res.data.success && res.data.data) {
  48. resolve(res.data.data)
  49. } else {
  50. resolve(null)
  51. }
  52. },
  53. fail: () => resolve(null)
  54. })
  55. } else {
  56. resolve(null)
  57. }
  58. } catch (e) {
  59. console.error('加载阅读进度失败', e)
  60. resolve(null)
  61. }
  62. })
  63. }
  64. return {
  65. saveProgress,
  66. loadProgress
  67. }
  68. }