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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<template>
<div class="firmware_upgrade_wrap">
  <!-- 版本 -->
  <span class="version"> {{ device.firmware_version }}</span>
  <!-- tag -->
  <span v-if="getTagStatus(device)"
        class="status-tag pointer">
    <a-tag class="pointer"
           :color="getFirmwareTag(device.firmware_status).color"
           @click="deviceUpgrade(device)">
      {{ getFirmwareTag(device.firmware_status).text }}
    </a-tag>
  </span>
  <!-- 进度 -->
  <span v-if="device.firmware_status === DeviceFirmwareStatusEnum.DuringUpgrade">
  {{ `${device.firmware_progress}`}}
  </span>
</div>
</template>
 
<script lang="ts" setup>
import { defineProps, defineEmits, ref, watch, computed } from 'vue'
import { Device, DeviceFirmwareStatusEnum, DeviceFirmwareStatus, DeviceFirmwareStatusColor } from '/@/types/device'
 
const props = defineProps<{
  device: Device,
}>()
 
const emit = defineEmits(['device-upgrade'])
const needUpgrade = computed(() => {
  return props.device.firmware_status === DeviceFirmwareStatusEnum.ConsistencyUpgrade ||
         props.device.firmware_status === DeviceFirmwareStatusEnum.ToUpgraded
})
 
function getTagStatus (record: Device) {
  return record.firmware_status && record.firmware_status !== DeviceFirmwareStatusEnum.None
}
 
function getFirmwareTag (status: DeviceFirmwareStatusEnum) {
  return {
    text: DeviceFirmwareStatus[status] || '',
    color: DeviceFirmwareStatusColor[status] || ''
  }
}
 
function deviceUpgrade (record: Device) {
  if (!needUpgrade.value) return
  emit('device-upgrade', record)
}
 
</script>
 
<style lang="scss" scoped>
.firmware_upgrade_wrap{
 
  .status-tag{
    margin-left: 10px;
  }
 
  .pointer {
    cursor: pointer;
  }
}
</style>