machineFun.js 797 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {inject, reactive} from "vue";
  2. import {useMachineStore} from "@/store/useMachineStore";
  3. export const machineFun = {
  4. machine: reactive({
  5. scan: false,
  6. bmi: false,
  7. }),
  8. notifyMachineUsb({id, up}) {
  9. console.log('notifyMachineUsb', id, up)
  10. const machineStore = useMachineStore()
  11. this.machine[id] = up
  12. machineStore.setStatus(id, up)
  13. },
  14. getOnlineUsb(machine, callback) {
  15. let list = machine.getOnlineUsb()
  16. if (list) {
  17. list.forEach(it => {
  18. this.notifyMachineUsb({
  19. id: it,
  20. up: true,
  21. })
  22. })
  23. }
  24. if (callback) callback()
  25. },
  26. setUsbNotify(open = true) {
  27. if (open) {
  28. uni.$on('machineUsb', this.notifyMachineUsb)
  29. } else {
  30. uni.$off('machineUsb', this.notifyMachineUsb)
  31. }
  32. },
  33. }