xieb
2023-09-13 3667807a7b7418efc090ee3fa6a6b734bc3080bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Ref, ref } from 'vue'
import { Device } from '/@/types/device'
import { postDeviceUpgrade, DeviceUpgradeBody } from '/@/api/device-upgrade'
 
export function useDeviceFirmwareUpgrade (workspaceId: string) {
  const deviceFirmwareUpgradeModalVisible = ref(false)
  const selectedDevice: Ref<null | Device> = ref(null)
 
  function setDeviceFirmwareUpgradeModalVisible (visible: boolean) {
    deviceFirmwareUpgradeModalVisible.value = visible
  }
 
  function setSelectedDevice (device: null | Device) {
    selectedDevice.value = device
  }
 
  // 点击设备升级
  function onDeviceUpgrade (record: Device) {
    if (!record) {
      return
    }
    setSelectedDevice(record)
    setDeviceFirmwareUpgradeModalVisible(true)
  }
 
  // 确认设备升级
  async function onUpgradeDeviceOk (deviceUpgradeBody: DeviceUpgradeBody) {
    const { code } = await postDeviceUpgrade(workspaceId, deviceUpgradeBody)
    if (code === 0) {
      // setDeviceFirmwareUpgradeModalVisible(false)
    }
  }
 
  return {
    deviceFirmwareUpgradeModalVisible,
    setDeviceFirmwareUpgradeModalVisible,
    selectedDevice,
    setSelectedDevice,
    onDeviceUpgrade,
    onUpgradeDeviceOk,
  }
}