feedback.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * 健康反馈状态模块
  3. * L1即时反馈状态 + L2每日反馈展示状态
  4. */
  5. import feedbackEngine from '../utils/feedback-engine.js'
  6. var feedbackStore = {
  7. state: {
  8. // L1 Toast
  9. toastVisible: false,
  10. toastText: '',
  11. toastIcon: '',
  12. toastAnimating: false,
  13. // L1 Celebration
  14. celebrationVisible: false,
  15. celebrationTitle: '',
  16. celebrationSubtitle: '',
  17. celebrationParticles: [],
  18. // L2 Daily summary
  19. dailyFeedback: null,
  20. dailyFeedbackLoaded: false
  21. },
  22. mutations: {
  23. showToast: function(state, payload) {
  24. state.toastText = payload.text
  25. state.toastIcon = payload.icon || '✅'
  26. state.toastVisible = true
  27. state.toastAnimating = true
  28. },
  29. hideToast: function(state) {
  30. state.toastVisible = false
  31. state.toastAnimating = false
  32. },
  33. showCelebration: function(state, payload) {
  34. state.celebrationTitle = payload.title
  35. state.celebrationSubtitle = payload.subtitle
  36. state.celebrationVisible = true
  37. // Generate 50 particles
  38. var particles = []
  39. for (var i = 0; i < 50; i++) {
  40. particles.push({
  41. id: i,
  42. left: Math.random() * 100,
  43. delay: Math.random() * 0.5,
  44. duration: 1 + Math.random() * 1.5,
  45. color: ['#FF6B9D', '#F97316', '#10B981', '#6366F1', '#F59E0B', '#FF8C42'][Math.floor(Math.random() * 6)],
  46. size: 8 + Math.floor(Math.random() * 16)
  47. })
  48. }
  49. state.celebrationParticles = particles
  50. },
  51. hideCelebration: function(state) {
  52. state.celebrationVisible = false
  53. state.celebrationParticles = []
  54. },
  55. setDailyFeedback: function(state, feedback) {
  56. state.dailyFeedback = feedback
  57. state.dailyFeedbackLoaded = true
  58. }
  59. },
  60. actions: {
  61. initEngine: function({ commit }) {
  62. // Register engine callbacks
  63. feedbackEngine.registerCallbacks(
  64. function(toastData) {
  65. commit('showToast', toastData)
  66. // Auto-hide after 2s
  67. setTimeout(function() {
  68. commit('hideToast')
  69. }, 2000)
  70. },
  71. function(celebrationData) {
  72. commit('showCelebration', celebrationData)
  73. // Auto-hide after 3s
  74. setTimeout(function() {
  75. commit('hideCelebration')
  76. }, 3000)
  77. }
  78. )
  79. }
  80. }
  81. }
  82. export default feedbackStore