fix: iot 固件的优化

pull/345/head
YunaiV 2026-05-21 15:11:01 +08:00
parent 33cdfcac3c
commit d2587c17b0
3 changed files with 47 additions and 6 deletions

View File

@ -12,6 +12,14 @@ import { getRangePickerDefaultProps } from '#/utils';
let productList: IotProductApi.Product[] = [];
getSimpleProductList().then((data) => (productList = data));
/** 根据产品 ID 取产品名称 */
export function getProductName(productId?: number): string {
if (!productId) {
return '-';
}
return productList.find((p) => p.id === productId)?.name || '-';
}
/** 固件详情的描述字段 */
export function useDetailSchema(): DescriptionItemSchema[] {
return [
@ -58,6 +66,10 @@ export function useFormSchema(): VbenFormSchema[] {
placeholder: '请选择产品',
},
rules: 'required',
dependencies: {
triggerFields: ['id'],
show: (values) => !values.id,
},
},
{
fieldName: 'version',
@ -67,6 +79,10 @@ export function useFormSchema(): VbenFormSchema[] {
placeholder: '请输入版本号',
},
rules: 'required',
dependencies: {
triggerFields: ['id'],
show: (values) => !values.id,
},
},
{
fieldName: 'description',
@ -88,6 +104,10 @@ export function useFormSchema(): VbenFormSchema[] {
helpText: '支持上传 .bin、.hex、.zip 格式的固件文件,最大 50MB',
},
rules: 'required',
dependencies: {
triggerFields: ['id'],
show: (values) => !values.id,
},
},
];
}
@ -131,7 +151,6 @@ export function useGridFormSchema(): VbenFormSchema[] {
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{ type: 'checkbox', width: 40 },
{
field: 'id',
title: '固件编号',
@ -156,8 +175,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
field: 'productId',
title: '所属产品',
minWidth: 150,
formatter: ({ cellValue }) =>
productList.find((p) => p.id === cellValue)?.name || '-',
slots: { default: 'productName' },
},
{
field: 'fileUrl',

View File

@ -13,7 +13,7 @@ import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteOtaFirmware, getOtaFirmwarePage } from '#/api/iot/ota/firmware';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import { getProductName, useGridColumns, useGridFormSchema } from './data';
import OtaFirmwareForm from './modules/form.vue';
const { push } = useRouter();
@ -60,6 +60,11 @@ function handleDetail(row: IoTOtaFirmwareApi.Firmware) {
push({ name: 'IoTOtaFirmwareDetail', params: { id: row.id } });
}
/** 跳转到产品详情 */
function handleOpenProductDetail(productId: number) {
push({ name: 'IoTProductDetail', params: { id: productId } });
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@ -108,6 +113,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
]"
/>
</template>
<!-- 所属产品列点击跳产品详情 -->
<template #productName="{ row }">
<a
v-if="row.productId"
class="cursor-pointer text-primary hover:underline"
@click="handleOpenProductDetail(row.productId)"
>
{{ getProductName(row.productId) }}
</a>
<span v-else class="text-gray-400">-</span>
</template>
<!-- 固件文件列 -->
<template #fileUrl="{ row }">
<div

View File

@ -47,8 +47,15 @@ const [Modal, modalApi] = useVbenModal({
return;
}
modalApi.lock();
//
const data = (await formApi.getValues()) as IoTOtaFirmwareApi.Firmware;
// id / name / description
const values = (await formApi.getValues()) as IoTOtaFirmwareApi.Firmware;
const data: IoTOtaFirmwareApi.Firmware = formData.value?.id
? {
id: formData.value.id,
name: values.name,
description: values.description,
}
: values;
try {
await (formData.value?.id
? updateOtaFirmware(data)