初始化仓库
This commit is contained in:
76
store/index.js
Normal file
76
store/index.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import WebSocket from '@/common/common.js';
|
||||
import Utils from '@/common/utils.js';
|
||||
|
||||
import {
|
||||
registerList
|
||||
} from '@/api/consult.js'
|
||||
Vue.use(Vuex)
|
||||
const store = new Vuex.Store({
|
||||
state: {
|
||||
// url: 'wss://wss.nbxlmy.com/ws',
|
||||
webSocket: null,
|
||||
utils: null,
|
||||
consult: [], //咨询会话列表
|
||||
docSession: [], //医生首页消息会话列表
|
||||
status: 1
|
||||
},
|
||||
mutations: {
|
||||
SET_CONSULT(state, res) {
|
||||
state.consult = res;
|
||||
},
|
||||
SET_DOCSESSION(state, res) {
|
||||
state.docSession = res;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
logout({
|
||||
state,
|
||||
dispatch
|
||||
}) {
|
||||
dispatch('closeWebSocket')
|
||||
// state.webSocket.logout()
|
||||
},
|
||||
init({
|
||||
state,
|
||||
dispatch
|
||||
}) {
|
||||
console.log('这里是websocket init!!!!')
|
||||
// 拿到存储
|
||||
let userInfo = uni.getStorageSync('userInfo')
|
||||
if (userInfo) {
|
||||
console.log(1);
|
||||
// 连接socket
|
||||
state.webSocket = new WebSocket({
|
||||
url: state.url
|
||||
})
|
||||
// state.utils = new Utils()
|
||||
// 获取会话列表
|
||||
// dispatch('getSessionList')
|
||||
}
|
||||
},
|
||||
closeWebSocket({
|
||||
state
|
||||
}) {
|
||||
if (state.webSocket) {
|
||||
state.webSocket.close();
|
||||
}
|
||||
},
|
||||
// 获取挂号信息
|
||||
getConsult({
|
||||
state,
|
||||
commit
|
||||
}) {
|
||||
registerList({
|
||||
status: state.status,
|
||||
page: 1
|
||||
}).then(res => {
|
||||
if (res.errcode == 0) {
|
||||
commit('SET_CONSULT', res.data);
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
})
|
||||
export default store
|
||||
Reference in New Issue
Block a user