notice.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import SettingMer from '@/libs/settingMer'
  2. import Vue from 'vue'
  3. function bindEvent(vm) {
  4. vm.$on('notice', function(data) {
  5. this.$notify.info({
  6. title: data.title || '消息',
  7. message: data.message,
  8. onClick() {
  9. console.log('click')
  10. }
  11. })
  12. })
  13. }
  14. function createWebScoket(token) {
  15. return new WebSocket(`${SettingMer.wsSocketUrl}?type=admin&token=${token}`)
  16. }
  17. function notice(token) {
  18. // const ws = createWebScoket(token)
  19. // const vm = new Vue()
  20. // let ping
  21. // function send(type, data) {
  22. // ws.send(JSON.stringify({ type, data }))
  23. // }
  24. // ws.onopen = function() {
  25. // vm.$emit('open')
  26. // ping = setInterval(function() {
  27. // send('ping')
  28. // }, 10000)
  29. // }
  30. // ws.onmessage = function(res) {
  31. // vm.$emit('message', res)
  32. // const data = JSON.parse(res.data)
  33. // if (data.status === 200) {
  34. // vm.$emit(data.data.status, data.data.result)
  35. // }
  36. // console.log(res)
  37. // }
  38. // ws.onclose = function(e) {
  39. // vm.$emit('close', e)
  40. // console.log('on close')
  41. // clearInterval(ping)
  42. // }
  43. // bindEvent(vm)
  44. // return function() {
  45. // ws.close()
  46. // }
  47. }
  48. export default notice