feat: 添加模式选择功能与页面更新

- 在 onboarding 页面中新增使用模式选择功能,用户可选择“戒烟打卡”或“记录抽烟”模式
- 更新个人资料页面以显示当前模式并允许用户切换模式
- 在 pages.json 中注册新的模式选择页面
- 优化首页和其他相关页面以适应新模式功能
This commit is contained in:
你çšnepiedg
2026-03-18 00:06:01 +08:00
parent d101515d8d
commit 31e504a997
10 changed files with 1818 additions and 465 deletions
+9
View File
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import { storage, PROFILE_KEY } from '@/utils/storage'
import { getProfile, updateProfile } from '@/api/profile'
import { useUserStore } from '@/stores/user'
export const useProfileStore = defineStore('profile', {
state: () => ({
@@ -19,6 +20,7 @@ export const useProfileStore = defineStore('profile', {
async fetchProfile() {
try {
const res = await getProfile()
const userStore = useUserStore()
this.exists = res.data.exists
this.awakeMinutes = res.data.awake_minutes || 960
this.baselineIntervalMinutes = res.data.baseline_interval_minutes || 60
@@ -26,6 +28,9 @@ export const useProfileStore = defineStore('profile', {
if (res.data.profile) {
this.profile = res.data.profile
storage.set(PROFILE_KEY, res.data.profile)
if (res.data.profile.mode) {
userStore.setMode(res.data.profile.mode)
}
this.isCompleted = res.data.is_completed ||
!!res.data.profile.onboarding_completed_at ||
res.data.profile.baseline_cigs_per_day > 0
@@ -43,10 +48,14 @@ export const useProfileStore = defineStore('profile', {
async saveProfile(data) {
try {
const res = await updateProfile(data)
const userStore = useUserStore()
this.exists = res.data.exists
this.isCompleted = res.data.is_completed
this.profile = res.data.profile
storage.set(PROFILE_KEY, res.data.profile)
if (res.data.profile?.mode) {
userStore.setMode(res.data.profile.mode)
}
return res.data
} catch (e) {
console.error('saveProfile error:', e)
+11 -2
View File
@@ -1,11 +1,12 @@
import { defineStore } from 'pinia'
import { storage, USER_KEY, SESSION_KEY } from '@/utils/storage'
import { storage, USER_KEY, SESSION_KEY, USER_MODE_KEY, QUIT_CHECKIN_KEY } from '@/utils/storage'
export const useUserStore = defineStore('user', {
state: () => ({
user: storage.get(USER_KEY),
sessionKey: storage.get(SESSION_KEY),
isLoggedIn: !!storage.get(SESSION_KEY)
isLoggedIn: !!storage.get(SESSION_KEY),
mode: storage.get(USER_MODE_KEY)
}),
actions: {
@@ -17,12 +18,20 @@ export const useUserStore = defineStore('user', {
storage.set(SESSION_KEY, sessionKey)
},
setMode(mode) {
this.mode = mode
storage.set(USER_MODE_KEY, mode)
},
logout() {
this.user = null
this.sessionKey = null
this.isLoggedIn = false
this.mode = null
storage.remove(USER_KEY)
storage.remove(SESSION_KEY)
storage.remove(USER_MODE_KEY)
storage.remove(QUIT_CHECKIN_KEY)
}
}
})