import { Module, MutationTree, ActionTree, GetterTree } from 'vuex' import { RootState } from '@/store' import { api } from '@/api' export interface INotifyState { websocketId?: string // 预留 unreadCount: number // 未读消息数量 } const mutations: MutationTree = { UPDATE_UNREAD_COUNT(state: INotifyState, count: number) { state.unreadCount = count }, UPDATE_WEBSOCKET_ID(state: INotifyState, websocketId: string) { state.websocketId = websocketId }, } const actions: ActionTree = { async updateUnreadCount({ commit }) { const res = await api.get('/api/Notify/UnReadedCount', {}) commit('UPDATE_UNREAD_COUNT', res.data.count) return res.data }, } const getters: GetterTree = { unreadCount: (state: INotifyState) => state.unreadCount, websocketId: (state: INotifyState) => state.websocketId, } const initState: INotifyState = { websocketId: undefined, unreadCount: 0, } const notify: Module = { namespaced: true, state: initState, mutations, getters, actions, } export default notify