feat(iot):优化 ota 的代码风格(v6)

pull/345/head
YunaiV 2026-05-19 16:52:27 +08:00
parent ab15c884bf
commit 8bcfa20577
9 changed files with 23 additions and 28 deletions

View File

@ -17,7 +17,7 @@ const route = useRoute();
const firmwareId = ref(Number(route.params.id));
const firmwareLoading = ref(false);
const firmware = ref<IoTOtaFirmwareApi.Firmware>({} as IoTOtaFirmwareApi.Firmware);
const firmware = ref<IoTOtaFirmwareApi.Firmware>();
const firmwareStatisticsLoading = ref(false);
const firmwareStatistics = ref<Record<string, number>>({});

View File

@ -9,7 +9,7 @@ import { useDetailSchema } from '../../data';
/** IoT OTA 固件基本信息 */
defineProps<{
firmware: IoTOtaFirmwareApi.Firmware;
firmware?: IoTOtaFirmwareApi.Firmware;
loading?: boolean;
}>();

View File

@ -45,7 +45,7 @@ async function handleDelete(row: IoTOtaFirmwareApi.Firmware) {
duration: 0,
});
try {
await deleteOtaFirmware(row.id as number);
await deleteOtaFirmware(row.id!);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});

View File

@ -97,7 +97,6 @@ export function useFormSchema(): VbenFormSchema[] {
];
}
// TODO DONE @AI任务列表内嵌固件详情页单字段搜索意义不大已去掉搜索表单
/** 任务列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
@ -164,5 +163,3 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
},
];
}
// TODO DONE @AIrecord schema 已挪到 task/record/data.tslist 也独立成 task/record/modules/list.vue

View File

@ -6,9 +6,7 @@ import { ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { getOtaTask } from '#/api/iot/ota/task';
import {
getOtaTaskRecordStatusStatistics,
} from '#/api/iot/ota/task/record';
import { getOtaTaskRecordStatusStatistics } from '#/api/iot/ota/task/record';
import OtaTaskRecordList from '../record/modules/list.vue';
import TaskInfo from './info.vue';
@ -18,7 +16,7 @@ const emit = defineEmits(['success']);
const taskId = ref<number>();
const taskLoading = ref(false);
const task = ref<IoTOtaTaskApi.Task>({} as IoTOtaTaskApi.Task);
const task = ref<IoTOtaTaskApi.Task>();
const taskStatisticsLoading = ref(false);
const taskStatistics = ref<Record<string, number>>({});
@ -53,7 +51,7 @@ async function getStatistics() {
}
/** 单条记录取消后,刷新任务信息和统计 */
async function handleRecordCancelled() {
async function handleRecordSuccess() {
await getStatistics();
await getTaskInfo();
emit('success');
@ -92,7 +90,7 @@ const [Modal, modalApi] = useVbenModal({
</div>
<!-- 升级设备记录 -->
<div class="mt-4">
<OtaTaskRecordList :task-id="taskId" @cancelled="handleRecordCancelled" />
<OtaTaskRecordList :task-id="taskId" @success="handleRecordSuccess" />
</div>
</Modal>
</template>

View File

@ -83,7 +83,7 @@ const [Modal, modalApi] = useVbenModal({
</script>
<template>
<Modal class="w-3/5" title="新增升级任务">
<Modal class="w-3/5" :title="$t('ui.actionTitle.create', ['升级任务'])">
<Form class="mx-4" />
</Modal>
</template>

View File

@ -9,7 +9,7 @@ import { useDetailSchema } from '../data';
defineProps<{
loading?: boolean;
task: IoTOtaTaskApi.Task;
task?: IoTOtaTaskApi.Task;
}>();
const [Description] = useDescription({

View File

@ -10,6 +10,7 @@ import { Input, message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { cancelOtaTask, getOtaTaskPage } from '#/api/iot/ota/task';
import { $t } from '#/locales';
import { IoTOtaTaskStatusEnum } from '#/views/iot/utils/constants';
import { useGridColumns } from '../data';
@ -60,7 +61,7 @@ function handleDetail(row: IoTOtaTaskApi.Task) {
/** 取消任务 */
async function handleCancel(row: IoTOtaTaskApi.Task) {
await cancelOtaTask(row.id as number);
await cancelOtaTask(row.id!);
message.success('取消成功');
await handleRefresh();
}
@ -107,18 +108,18 @@ const [Grid, gridApi] = useVbenVxeGrid({
allow-clear
style="width: 200px"
@press-enter="handleSearch"
@change="(e: any) => !e.target.value && handleSearch()"
@clear="handleSearch"
/>
<TableAction
:actions="[
{
label: '搜索',
label: $t('common.search'),
type: 'default',
icon: 'ant-design:search-outlined',
onClick: handleSearch,
},
{
label: '新增',
label: $t('ui.actionTitle.create', ['升级任务']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['iot:ota-task:create'],
@ -132,14 +133,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
<TableAction
:actions="[
{
label: '详情',
label: $t('common.detail'),
type: 'link',
icon: ACTION_ICON.VIEW,
auth: ['iot:ota-task:query'],
onClick: handleDetail.bind(null, row),
},
{
label: '取消',
label: $t('common.cancel'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,

View File

@ -11,6 +11,7 @@ import {
cancelOtaTaskRecord,
getOtaTaskRecordPage,
} from '#/api/iot/ota/task/record';
import { $t } from '#/locales';
import { IoTOtaTaskRecordStatusEnum } from '#/views/iot/utils/constants';
import { useGridColumns } from '../data';
@ -19,7 +20,7 @@ const props = defineProps<{
taskId: number | undefined;
}>();
const emit = defineEmits(['cancelled']);
const emit = defineEmits(['success']);
const activeTab = ref('');
@ -43,10 +44,10 @@ async function handleTabChange(tabKey: number | string) {
/** 取消单条记录的升级 */
async function handleCancelUpgrade(record: IoTOtaTaskRecordApi.TaskRecord) {
await cancelOtaTaskRecord(record.id as number);
await cancelOtaTaskRecord(record.id!);
message.success('取消成功');
await gridApi.query();
emit('cancelled');
emit('success');
}
const [Grid, gridApi] = useVbenVxeGrid({
@ -84,15 +85,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
/** taskId 变化时重新查询 */
watch(
() => props.taskId,
(val) => {
async (val) => {
if (val) {
activeTab.value = '';
gridApi.query();
await gridApi.query();
}
},
);
defineExpose({ refresh: () => gridApi.query() });
</script>
<template>
@ -113,7 +112,7 @@ defineExpose({ refresh: () => gridApi.query() });
<TableAction
:actions="[
{
label: '取消',
label: $t('common.cancel'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,