设备升级记录
This commit is contained in:
parent
c09ca5eab0
commit
50d40b27d3
@ -7537,30 +7537,11 @@ export const PageDeviceUpgradeRecordInputSchema = {
|
|||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: '是否分页'
|
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: {
|
upgradeDate: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: '升级日期',
|
description: '升级日期',
|
||||||
format: 'date-time'
|
format: 'date-time',
|
||||||
|
nullable: true
|
||||||
},
|
},
|
||||||
upgradeSource: {
|
upgradeSource: {
|
||||||
'$ref': '#/components/schemas/DeviceUpgradeSourceTypeEnum'
|
'$ref': '#/components/schemas/DeviceUpgradeSourceTypeEnum'
|
||||||
|
|||||||
@ -4074,26 +4074,10 @@ export type PageDeviceUpgradeRecordInput = {
|
|||||||
* 是否分页
|
* 是否分页
|
||||||
*/
|
*/
|
||||||
isPage?: boolean;
|
isPage?: boolean;
|
||||||
/**
|
|
||||||
* 设备名称
|
|
||||||
*/
|
|
||||||
deviceName?: (string) | null;
|
|
||||||
/**
|
|
||||||
* 设备地址
|
|
||||||
*/
|
|
||||||
deviceAddress?: (string) | null;
|
|
||||||
/**
|
|
||||||
* 旧的固件版本
|
|
||||||
*/
|
|
||||||
oldFirmwareVersion?: (string) | null;
|
|
||||||
/**
|
|
||||||
* 当前固件版本
|
|
||||||
*/
|
|
||||||
nowFirmwareVersion?: (string) | null;
|
|
||||||
/**
|
/**
|
||||||
* 升级日期
|
* 升级日期
|
||||||
*/
|
*/
|
||||||
upgradeDate?: string;
|
upgradeDate?: (string) | null;
|
||||||
upgradeSource?: DeviceUpgradeSourceTypeEnum;
|
upgradeSource?: DeviceUpgradeSourceTypeEnum;
|
||||||
/**
|
/**
|
||||||
* 搜索关键字
|
* 搜索关键字
|
||||||
|
|||||||
@ -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) => {
|
||||||
|
// 当升级标识符号失焦时,如果值为空字符串或null,保持为undefined而不是清空
|
||||||
|
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>
|
||||||
|
|
||||||
@ -1,6 +1,191 @@
|
|||||||
/*
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||||
* @Description: 文件内容描述
|
|
||||||
* @Author: 陈益
|
import { computed } from 'vue';
|
||||||
* @Date: 2025-12-31 14:25:04
|
|
||||||
* @LastEditors: 陈益
|
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' },
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user