/** * 健康反馈状态模块 * L1即时反馈状态 + L2每日反馈展示状态 */ import feedbackEngine from '../utils/feedback-engine.js' var feedbackStore = { state: { // L1 Toast toastVisible: false, toastText: '', toastIcon: '', toastAnimating: false, // L1 Celebration celebrationVisible: false, celebrationTitle: '', celebrationSubtitle: '', celebrationParticles: [], // L2 Daily summary dailyFeedback: null, dailyFeedbackLoaded: false }, mutations: { showToast: function(state, payload) { state.toastText = payload.text state.toastIcon = payload.icon || '✅' state.toastVisible = true state.toastAnimating = true }, hideToast: function(state) { state.toastVisible = false state.toastAnimating = false }, showCelebration: function(state, payload) { state.celebrationTitle = payload.title state.celebrationSubtitle = payload.subtitle state.celebrationVisible = true // Generate 50 particles var particles = [] for (var i = 0; i < 50; i++) { particles.push({ id: i, left: Math.random() * 100, delay: Math.random() * 0.5, duration: 1 + Math.random() * 1.5, color: ['#FF6B9D', '#F97316', '#10B981', '#6366F1', '#F59E0B', '#FF8C42'][Math.floor(Math.random() * 6)], size: 8 + Math.floor(Math.random() * 16) }) } state.celebrationParticles = particles }, hideCelebration: function(state) { state.celebrationVisible = false state.celebrationParticles = [] }, setDailyFeedback: function(state, feedback) { state.dailyFeedback = feedback state.dailyFeedbackLoaded = true } }, actions: { initEngine: function({ commit }) { // Register engine callbacks feedbackEngine.registerCallbacks( function(toastData) { commit('showToast', toastData) // Auto-hide after 2s setTimeout(function() { commit('hideToast') }, 2000) }, function(celebrationData) { commit('showCelebration', celebrationData) // Auto-hide after 3s setTimeout(function() { commit('hideCelebration') }, 3000) } ) } } } export default feedbackStore