| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <template>
- <view class="app-container">
- <router-view />
- </view>
- </template>
-
- <script>
- import config from './config'
- import { getToken } from '@/utils/auth'
-
- export default {
- onLaunch() {
- // 检查阅读进度
- this.checkReadingProgress()
- // 初始化主题(临时实现)
- this.initTheme()
- // 检查登录状态
- //this.checkLogin()
-
-
- },
- onShow() {
- // 检查云端阅读进度
- if (this.$store.getters.token) {
- this.syncReadingProgress()
- }
- },
- methods: {
- // 检查阅读进度
- checkReadingProgress() {
- const chapter = uni.getStorageSync('readingProgress') || 1
-
- // 如果用户阅读超过5章但未登录,提示登录
- if (chapter > 5 && !uni.getStorageSync('token')) {
- uni.showModal({
- title: '登录提示',
- content: `您已阅读到第${chapter}章,登录后继续阅读`,
- confirmText: '立即登录',
- success: (res) => {
- if (res.confirm) {
- uni.navigateTo({
- url: '/pages/login'
- })
- }
- }
- })
- }
- },
- async syncReadingProgress() {
- try {
- const res = await this.$api.getReadingProgress()
- const cloudChapter = res.data.chapter
- const localChapter = uni.getStorageSync('readingProgress') || 1
-
- // 使用最新的阅读进度
- if (cloudChapter > localChapter) {
- uni.setStorageSync('readingProgress', cloudChapter)
- } else if (localChapter > cloudChapter) {
- await this.$api.saveReadingProgress(localChapter)
- }
- } catch (err) {
- console.error('同步阅读进度失败', err)
- }
- },
- // 添加 checkLogin 方法
- // checkLogin() {
- // // 这里写登录检查逻辑
- // // 示例:检查本地存储的登录状态
- // const isLoggedIn = uni.getStorageSync('isLogin');
- // if (!isLoggedIn) {
- // uni.navigateTo({ url: '/pages/login' });
- // }
- // },
-
- // 临时主题初始化
- initTheme() {
- const themeName = uni.getStorageSync('selectedTheme') || 'aydzBlue'
-
- // 应用主题变量
- const themes = {
- aydzBlue: {
- '--primary-color': '#2a5caa',
- '--bg-color': '#e6f7ff',
- '--text-color': '#1a3353',
- '--card-bg': '#d0e8ff',
- '--header-bg': '#2a5caa'
- },
- darkMode: {
- '--primary-color': '#52c41a',
- '--bg-color': '#1a1a1a',
- '--text-color': '#e6e6e6',
- '--card-bg': '#2a2a2a'
- },
- default: {
- '--primary-color': '#1890ff',
- '--bg-color': '#f8f9fa',
- '--text-color': '#333',
- '--card-bg': '#ffffff'
- }
- }
-
- const root = document.documentElement
- const themeVars = themes[themeName] || themes.aydzBlue
-
- Object.keys(themeVars).forEach(key => {
- root.style.setProperty(key, themeVars[key])
- })
-
- // 动态设置导航栏颜色
- if (themeName === 'darkMode') {
- uni.setNavigationBarColor({
- frontColor: '#ffffff',
- backgroundColor: '#1a1a1a'
- })
- } else if (themeName === 'aydzBlue') {
- uni.setNavigationBarColor({
- frontColor: '#ffffff',
- backgroundColor: '#2a5caa'
- })
- }
- }
- }
- }
- </script>
-
- <style lang="scss">
- /* 保留原有样式 */
- uni-tabbar {
- z-index: 999;
- }
- </style>
|