import Vue from 'vue' import Vuex from 'vuex' import { disconnectWebSocket } from '@/utils/ws/initWebSocket.js'; import { registerList } from '@/api/consult.js' Vue.use(Vuex) const store = new Vuex.Store({ state: { utils: null, consult: [], //咨询会话列表 docSession: [], //医生首页消息会话列表 status: 1 }, mutations: { SET_CONSULT(state, res) { state.consult = res; }, SET_DOCSESSION(state, res) { state.docSession = res; }, }, actions: { /** * 登出 * 职责:断开WebSocket连接,清理状态 */ logout({ state, dispatch }) { dispatch('closeWebSocket'); }, /** * 初始化(保留用于其他初始化逻辑) * 注意:WebSocket初始化已在App.vue中统一处理 */ init({ state, dispatch }) { // WebSocket初始化已移至App.vue,这里保留其他初始化逻辑 // state.utils = new Utils() // 获取会话列表 // dispatch('getSessionList') }, /** * 关闭WebSocket * 职责:断开WebSocket连接 */ closeWebSocket() { disconnectWebSocket(); }, // 获取挂号信息 getConsult({ state, commit }) { registerList({ status: state.status, page: 1 }).then(res => { if (res.errcode == 0) { commit('SET_CONSULT', res.data); } }) }, } }) export default store