import store from '@/store' let ws = null export function wsSocket () { ws = new WebSocket(`${PLATFROM_CONFIG.socketUrl}`) ws.onopen = function () { console.log('ws打开') } ws.onmessage = function (res) { const datas = JSON.parse(res.data) store.dispatch('app/getWsData', datas) console.log('ws数据', datas) } ws.onerror = function (err) { console.log('ws错误', err) } ws.onclose = function () { console.log('ws关闭') } } export function wsSendData (msg) { if (ws) { ws.send(msg) } } export function wsSocketClose () { if (ws) { ws.close() } }