gaoluyang
2026-06-24 0ce68379718b7c751b8a84aa4b28cbaf072e6c8f
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { IoTOtaTaskRecordApi } from '#/api/iot/ota/task/record';
 
import { computed, ref, watch } from 'vue';
 
import { IoTOtaTaskRecordStatusEnum } from '../../../../../../packages/constants/src';
 
import { Card, message, Tabs } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  cancelOtaTaskRecord,
  getOtaTaskRecordPage,
} from '#/api/iot/ota/task/record';
import { $t } from '#/locales';
 
import { useGridColumns } from '../data';
 
const props = defineProps<{
  taskId: number | undefined;
}>();
 
const emit = defineEmits(['success']);
 
const activeTab = ref('');
 
/** 状态标签配置 */
const statusTabs = computed(() => {
  const tabs = [{ key: '', label: '全部设备' }];
  Object.values(IoTOtaTaskRecordStatusEnum).forEach((status) => {
    tabs.push({
      key: status.value.toString(),
      label: status.label,
    });
  });
  return tabs;
});
 
/** 切换标签 */
async function handleTabChange(tabKey: number | string) {
  activeTab.value = String(tabKey);
  await gridApi.reload();
}
 
/** 取消单条记录的升级 */
async function handleCancelUpgrade(record: IoTOtaTaskRecordApi.TaskRecord) {
  await cancelOtaTaskRecord(record.id!);
  message.success('取消成功');
  await gridApi.query();
  emit('success');
}
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns: useGridColumns(),
    height: 400,
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    pagerConfig: {
      enabled: true,
    },
    proxyConfig: {
      ajax: {
        query: async ({ page }) => {
          if (!props.taskId) {
            return { list: [], total: 0 };
          }
          return await getOtaTaskRecordPage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            taskId: props.taskId,
            status:
              activeTab.value === '' ? undefined : Number(activeTab.value),
          });
        },
      },
    },
    toolbarConfig: {
      enabled: false,
    },
  } as VxeTableGridOptions<IoTOtaTaskRecordApi.TaskRecord>,
});
 
/** taskId 变化时重新查询 */
watch(
  () => props.taskId,
  async (val) => {
    if (val) {
      activeTab.value = '';
      await gridApi.reload();
    }
  },
);
</script>
 
<template>
  <Card title="升级设备记录">
    <Tabs v-model:active-key="activeTab" @change="handleTabChange" class="mb-4">
      <Tabs.TabPane v-for="tab in statusTabs" :key="tab.key" :tab="tab.label" />
    </Tabs>
    <Grid>
      <template #actions="{ row }">
        <TableAction
          :actions="[
            {
              label: $t('common.cancel'),
              type: 'link',
              danger: true,
              icon: ACTION_ICON.DELETE,
              auth: ['iot:ota-task-record:cancel'],
              ifShow: [
                IoTOtaTaskRecordStatusEnum.PENDING.value,
                IoTOtaTaskRecordStatusEnum.PUSHED.value,
                IoTOtaTaskRecordStatusEnum.UPGRADING.value,
              ].includes(row.status!),
              popConfirm: {
                title: '确认要取消该设备的升级任务吗?',
                confirm: handleCancelUpgrade.bind(null, row),
              },
            },
          ]"
        />
      </template>
    </Grid>
  </Card>
</template>