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[] = []; let productList: IotProductApi.Product[] = [];
getSimpleProductList().then((data) => (productList = data)); 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[] { export function useDetailSchema(): DescriptionItemSchema[] {
return [ return [
@ -58,6 +66,10 @@ export function useFormSchema(): VbenFormSchema[] {
placeholder: '请选择产品', placeholder: '请选择产品',
}, },
rules: 'required', rules: 'required',
dependencies: {
triggerFields: ['id'],
show: (values) => !values.id,
},
}, },
{ {
fieldName: 'version', fieldName: 'version',
@ -67,6 +79,10 @@ export function useFormSchema(): VbenFormSchema[] {
placeholder: '请输入版本号', placeholder: '请输入版本号',
}, },
rules: 'required', rules: 'required',
dependencies: {
triggerFields: ['id'],
show: (values) => !values.id,
},
}, },
{ {
fieldName: 'description', fieldName: 'description',
@ -88,6 +104,10 @@ export function useFormSchema(): VbenFormSchema[] {
helpText: '支持上传 .bin、.hex、.zip 格式的固件文件,最大 50MB', helpText: '支持上传 .bin、.hex、.zip 格式的固件文件,最大 50MB',
}, },
rules: 'required', rules: 'required',
dependencies: {
triggerFields: ['id'],
show: (values) => !values.id,
},
}, },
]; ];
} }
@ -131,7 +151,6 @@ export function useGridFormSchema(): VbenFormSchema[] {
/** 列表的字段 */ /** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] { export function useGridColumns(): VxeTableGridOptions['columns'] {
return [ return [
{ type: 'checkbox', width: 40 },
{ {
field: 'id', field: 'id',
title: '固件编号', title: '固件编号',
@ -156,8 +175,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
field: 'productId', field: 'productId',
title: '所属产品', title: '所属产品',
minWidth: 150, minWidth: 150,
formatter: ({ cellValue }) => slots: { default: 'productName' },
productList.find((p) => p.id === cellValue)?.name || '-',
}, },
{ {
field: 'fileUrl', 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 { deleteOtaFirmware, getOtaFirmwarePage } from '#/api/iot/ota/firmware';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data'; import { getProductName, useGridColumns, useGridFormSchema } from './data';
import OtaFirmwareForm from './modules/form.vue'; import OtaFirmwareForm from './modules/form.vue';
const { push } = useRouter(); const { push } = useRouter();
@ -60,6 +60,11 @@ function handleDetail(row: IoTOtaFirmwareApi.Firmware) {
push({ name: 'IoTOtaFirmwareDetail', params: { id: row.id } }); push({ name: 'IoTOtaFirmwareDetail', params: { id: row.id } });
} }
/** 跳转到产品详情 */
function handleOpenProductDetail(productId: number) {
push({ name: 'IoTProductDetail', params: { id: productId } });
}
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useGridFormSchema(), schema: useGridFormSchema(),
@ -108,6 +113,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
]" ]"
/> />
</template> </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 }"> <template #fileUrl="{ row }">
<div <div

View File

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