设备升级记录

This commit is contained in:
ChenYi 2025-12-31 15:28:45 +08:00
parent c09ca5eab0
commit 50d40b27d3
4 changed files with 367 additions and 44 deletions

View File

@ -7537,30 +7537,11 @@ export const PageDeviceUpgradeRecordInputSchema = {
type: 'boolean',
description: '是否分页'
},
deviceName: {
type: 'string',
description: '设备名称',
nullable: true
},
deviceAddress: {
type: 'string',
description: '设备地址',
nullable: true
},
oldFirmwareVersion: {
type: 'string',
description: '旧的固件版本',
nullable: true
},
nowFirmwareVersion: {
type: 'string',
description: '当前固件版本',
nullable: true
},
upgradeDate: {
type: 'string',
description: '升级日期',
format: 'date-time'
format: 'date-time',
nullable: true
},
upgradeSource: {
'$ref': '#/components/schemas/DeviceUpgradeSourceTypeEnum'

View File

@ -4074,26 +4074,10 @@ export type PageDeviceUpgradeRecordInput = {
*
*/
isPage?: boolean;
/**
*
*/
deviceName?: (string) | null;
/**
*
*/
deviceAddress?: (string) | null;
/**
*
*/
oldFirmwareVersion?: (string) | null;
/**
*
*/
nowFirmwareVersion?: (string) | null;
/**
*
*/
upgradeDate?: string;
upgradeDate?: (string) | null;
upgradeSource?: DeviceUpgradeSourceTypeEnum;
/**
*

View File

@ -0,0 +1,173 @@
<script setup lang="ts">
import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed, h } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, message as Message, Modal, Tag } from 'ant-design-vue';
import dayjs from 'dayjs';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
postUpgradeRecordDeleteAsync,
postUpgradeRecordPage,
} from '#/api-client';
import { TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import { querySchema, tableSchema } from './schema';
defineOptions({
name: 'DeviceUpgradeRecord',
});
const formOptions: VbenFormProps = {
schema: querySchema.value,
submitOnChange: false,
handleValuesChange: async (values, changedFields) => {
// nullundefined
if (changedFields.includes('upgradeIdentifier')) {
if (values.upgradeIdentifier === '' || values.upgradeIdentifier === null) {
// undefined
if (gridApi?.formApi) {
await gridApi.formApi.setFieldValue('upgradeIdentifier', undefined);
}
}
}
},
};
const gridOptions: VxeGridProps<any> = {
columns: tableSchema.value,
height: 'auto',
keepSource: true,
pagerConfig: {},
toolbarConfig: {
custom: true,
},
customConfig: {
storage: true,
},
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
const currentFormValues = gridApi?.formApi
? await gridApi.formApi.getValues()
: formValues || {};
const finalFormValues = { ...formValues, ...currentFormValues };
// upgradeIdentifier
if (finalFormValues.upgradeIdentifier !== undefined && finalFormValues.upgradeIdentifier !== null && finalFormValues.upgradeIdentifier !== '') {
finalFormValues.upgradeIdentifier = Number(finalFormValues.upgradeIdentifier);
} else {
// undefined
finalFormValues.upgradeIdentifier = undefined;
}
const { data } = await postUpgradeRecordPage({
body: {
pageIndex: page.currentPage,
pageSize: page.pageSize,
...finalFormValues,
},
});
return data;
},
},
},
};
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
//
function onDel(row: any) {
Modal.confirm({
title: `${$t('common.confirmDelete')}升级记录 ?`,
content: `设备:${row.deviceName || row.deviceAddress || '-'},升级日期:${row.upgradeDate ? dayjs(row.upgradeDate).format('YYYY-MM-DD HH:mm:ss') : '-'}`,
onOk: async () => {
try {
const result = await postUpgradeRecordDeleteAsync({
body: { id: row.id },
});
if (result.data) {
gridApi.reload();
Message.success($t('common.deleteSuccess'));
} else {
Message.error($t('common.deleteFail'));
}
} catch (error) {
console.error('删除升级记录失败:', error);
Message.error($t('common.deleteFail'));
}
},
});
}
//
const getUpgradeStatusColor = (status: string) => {
const statusMap: Record<string, string> = {
'进行中': 'processing',
'成功': 'success',
'失败': 'error',
'已取消': 'default',
};
return statusMap[status] || 'default';
};
//
const getUpgradeResultColor = (result: string) => {
if (!result) return 'default';
if (result.includes('成功') || result.includes('完成')) return 'success';
if (result.includes('失败') || result.includes('错误')) return 'error';
if (result.includes('进行中') || result.includes('处理中')) return 'processing';
return 'default';
};
</script>
<template>
<Page auto-content-height>
<Grid>
<template #upgradeStatus="{ row }">
<component
:is="
h(
Tag,
{ color: getUpgradeStatusColor(row.upgradeStatusName || '') },
() => row.upgradeStatusName || '-',
)
"
/>
</template>
<template #upgradeResult="{ row }">
<component
:is="
h(
Tag,
{ color: getUpgradeResultColor(row.upgradeResultName || '') },
() => row.upgradeResultName || '-',
)
"
/>
</template>
<template #action="{ row }">
<div style="display: flex; gap: 8px; align-items: center">
<Button
size="small"
type="link"
style="color: #ff4d4f"
@click="onDel.bind(null, row)()"
>
{{ $t('common.delete') }}
</Button>
</div>
</template>
</Grid>
</Page>
</template>

View File

@ -1,6 +1,191 @@
/*
* @Description:
* @Author:
* @Date: 2025-12-31 14:25:04
* @LastEditors:
*/
import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed } from 'vue';
import dayjs from 'dayjs';
import { getCommonGetSelectList } from '#/api-client';
import { $t } from '#/locales';
export const querySchema = computed(() => [
{
component: 'Input',
fieldName: 'searchKeyword',
label: '搜索关键字',
componentProps: {
placeholder: '请输入搜索关键字',
},
},
{
component: 'ApiSelect',
fieldName: 'upgradeSource',
label: '升级来源',
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'DeviceUpgradeSourceTypeEnum',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: '请选择升级来源',
afterFetch: (res: any) => {
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
return [];
},
},
},
{
component: 'ApiSelect',
fieldName: 'upgradeResult',
label: '升级结果',
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'DeviceUpgradeStatusTypeEnum',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: '请选择升级结果',
afterFetch: (res: any) => {
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
return [];
},
},
},
{
component: 'Input',
fieldName: 'upgradeIdentifier',
label: '升级标识符号',
componentProps: {
placeholder: '请输入升级标识符号',
onInput: (e: Event) => {
const target = e.target as HTMLInputElement;
// 只允许输入数字
const value = target.value.replace(/[^\d]/g, '');
if (target.value !== value) {
target.value = value;
// 触发 input 事件,确保表单值更新
target.dispatchEvent(new Event('input', { bubbles: true }));
}
},
},
},
{
component: 'DatePicker',
fieldName: 'upgradeDate',
label: '升级日期',
componentProps: {
placeholder: '请选择升级日期',
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
allowClear: true,
},
},
]);
export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 },
{
field: 'deviceName',
title: '设备名称',
minWidth: '150',
},
{
field: 'deviceAddress',
title: '设备地址',
minWidth: '150',
},
{
field: 'oldFirmwareVersion',
title: '旧固件版本',
minWidth: '150',
},
{
field: 'nowFirmwareVersion',
title: '当前固件版本',
minWidth: '150',
},
{
field: 'upgradeDate',
title: '升级日期',
minWidth: '180',
formatter: ({ cellValue }) => {
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
},
},
{
field: 'upgradeSourceTypeName',
title: '升级来源',
minWidth: '120',
},
{
field: 'upgradeStatusName',
title: '升级状态',
minWidth: '120',
slots: { default: 'upgradeStatus' },
},
{
field: 'upgradeResultName',
title: '升级结果',
minWidth: '120',
slots: { default: 'upgradeResult' },
},
{
field: 'upgradeIdentifier',
title: '升级标识符',
minWidth: '120',
},
{
field: 'upgradeMessage',
title: '升级信息',
minWidth: '200',
showOverflow: 'tooltip',
},
{
field: 'firmwareSignature',
title: '签名校验值',
minWidth: '200',
showOverflow: 'tooltip',
},
{
field: 'creationTime',
title: '创建时间',
minWidth: '180',
formatter: ({ cellValue }) => {
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
},
},
{
title: $t('common.action'),
field: 'action',
fixed: 'right',
width: '150',
slots: { default: 'action' },
},
]);