feat(theme): 实现日夜主题自动切换功能

- 添加日夜主题CSS变量定义,支持琥珀夜光和暖白琥珀两种风格
- 实现主题切换逻辑,根据时间自动切换白天(light)和夜间(dark)主题
- 在App.vue中集成主题初始化和token恢复功能
- 更新全局样式类应用主题颜色变量,包括卡片、文本、边框等
- 创建主题混入(mixin)供各页面使用,确保主题同步更新
- 实现导航栏和TabBar主题动态切换,提升用户体验
- 添加API服务层封装HaveADrink SDK,统一处理认证和请求
- 优化DrinkCard组件显示饮酒感受信息,丰富打卡记录展示
- 更新项目依赖配置,集成新的API客户端库
This commit is contained in:
cg
2026-07-16 22:47:38 +08:00
parent 145976f221
commit 860136bceb
22 changed files with 7051 additions and 155 deletions
+35 -17
View File
@@ -1,5 +1,5 @@
<template>
<view class="page-container login-page">
<view :class="themeClass" class="page-container login-page">
<!-- 顶部品牌区 -->
<view class="brand-area">
<view class="brand-glow"></view>
@@ -99,7 +99,11 @@
</template>
<script>
import themeMixin from '../../common/theme-mixin'
import client, { saveAuthTokens } from '../../common/api'
export default {
mixins: [themeMixin],
data() {
return {
showNotice: true,
@@ -138,29 +142,43 @@ export default {
}
this.loginLoading = true
try {
// 获取微信登录code(用于后续服务端鉴权)
const loginRes = await this.wxLogin().catch(() => null)
// 1. 获取微信登录 code
const loginRes = await this.wxLogin()
if (!loginRes || !loginRes.code) {
throw new Error('获取微信code失败')
}
// 2. 调用后端微信登录接口
const loginParams = {
code: loginRes.code,
nickName: this.nickname.trim() || '',
avatarUrl: this.avatarUrl || ''
}
const resp = await client.WechatLogin(loginParams)
// 3. 保存 token 和用户信息
saveAuthTokens(resp)
if (resp.user) {
uni.setStorageSync('user_info', JSON.stringify(resp.user))
}
uni.setStorageSync('is_logged_in', 'true')
uni.setStorageSync('is_guest', 'false')
uni.setStorageSync('is_first_launch', 'false')
this.finishLogin()
} catch (e) {
console.warn('后端登录失败,降级为本地模式:', e)
uni.showToast({ title: e.msg || '登录失败,使用本地模式', icon: 'none', duration: 2000 })
// 降级为本地登录
const userInfo = {
id: `user_${Date.now()}`,
nickname: this.nickname.trim() || '酒友',
avatar: this.avatarUrl || '',
wxCode: (loginRes && loginRes.code) || '',
joinedAt: new Date().toISOString().slice(0, 10),
preferences: null
}
uni.setStorageSync('user_info', JSON.stringify(userInfo))
this.finishLogin()
} catch (e) {
console.warn('登录失败,降级为本地登录:', e)
const userInfo = {
id: `user_${Date.now()}`,
nickname: this.nickname.trim() || '酒友',
avatar: '',
joinedAt: new Date().toISOString().slice(0, 10),
preferences: null
}
uni.setStorageSync('user_info', JSON.stringify(userInfo))
uni.setStorageSync('is_logged_in', 'true')
uni.setStorageSync('is_first_launch', 'false')
this.finishLogin()
} finally {
this.loginLoading = false
@@ -334,7 +352,7 @@ export default {
align-items: center;
justify-content: space-between;
padding: $sp-sm 0;
border-bottom: 2rpx solid rgba(255,255,255,0.04);
border-bottom: 2rpx solid var(--border-micro, rgba(255, 255, 255, 0.05));
}
.avatar-btn {
@@ -432,7 +450,7 @@ export default {
.login-divider-line {
flex: 1;
height: 2rpx;
background: rgba(255,255,255,0.06);
background: var(--bg-hover, rgba(255, 255, 255, 0.08));
}
.login-divider-text {