| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /**
- * 健康预警状态模块
- * P1-2 健康行为智能预警
- */
- import api from '@/utils/api.js'
- var healthAlertStore = {
- state: {
- alerts: [],
- alertLoading: false,
- alertError: false,
- lastFetchTime: 0
- },
- mutations: {
- setAlerts: function(state, alerts) {
- state.alerts = alerts
- state.alertLoading = false
- state.alertError = false
- state.lastFetchTime = Date.now()
- },
- setAlertLoading: function(state) {
- state.alertLoading = true
- },
- setAlertError: function(state) {
- state.alertLoading = false
- state.alertError = true
- },
- dismissAlert: function(state, alertId) {
- state.alerts = state.alerts.filter(function(a) { return a.id !== alertId })
- }
- },
- actions: {
- fetchAlerts: function({ commit }, memberId) {
- if (!memberId) return
- commit('setAlertLoading')
- api.getActiveAlerts({ memberId: memberId }).then(function(res) {
- if (res.code === 200) {
- commit('setAlerts', res.data || [])
- } else {
- commit('setAlertError')
- }
- }).catch(function() {
- commit('setAlertError')
- })
- },
- dismissAlert: function({ commit }, alertId) {
- api.dismissAlert({ id: alertId }).then(function(res) {
- if (res.code === 200) {
- commit('dismissAlert', alertId)
- }
- }).catch(function() {
- // silent fail
- })
- }
- }
- }
- export default healthAlertStore
|