大空间消毒机
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import { defineStore } from 'pinia'
  2. import Socket from '@/socket'
  3. export const useWebSocketStore = defineStore({
  4. id: 'websocket', // id必填,且需要唯一
  5. // state
  6. state: () => {
  7. return {
  8. // 命令websocket 实例
  9. socketCommandInstance: null,
  10. // 事件上报websocket 实例
  11. socketEventInstance: null,
  12. }
  13. },
  14. // actions
  15. actions: {
  16. initCommandSocket() {
  17. const url = 'ws://192.168.1.100:19001/'
  18. const init = new Socket(url)
  19. init.connect()
  20. init.ws.onmessage = function (ev) {
  21. console.log(ev)
  22. // switch (data.type) {
  23. // case 1:
  24. // break
  25. // case 2:
  26. // break
  27. // }
  28. }
  29. this.socketCommandInstance = init
  30. },
  31. sendCommandMsg(message) {
  32. this.socketCommandInstance?.msg(message)
  33. },
  34. initEventSocket() {
  35. const url = 'ws://192.168.1.100:19002/'
  36. const init = new Socket(url)
  37. init.connect()
  38. init.ws.onmessage = function (ev) {
  39. console.log(ev)
  40. // switch (data.type) {
  41. // case 1:
  42. // break
  43. // case 2:
  44. // break
  45. // }
  46. }
  47. this.socketEventInstance = init
  48. },
  49. sendEventMsg(message) {
  50. this.socketEventInstance?.msg(message)
  51. },
  52. },
  53. })