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

This commit is contained in:
YunaiV
2026-05-19 14:51:54 +08:00
parent 0bc1981675
commit b9a7eddb72
6 changed files with 5 additions and 24 deletions

View File

@@ -1,5 +1,4 @@
<script setup lang="ts">
// TODO DONE @AI已挪到 firmware/modules/form.vue对齐 alert/config/modules/form.vue 风格
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
import { computed, ref } from 'vue';
@@ -18,8 +17,6 @@ import { $t } from '#/locales';
import { useFormSchema } from '../data';
defineOptions({ name: 'IoTOtaFirmwareForm' });
const emit = defineEmits<{
success: [];
}>();

View File

@@ -14,10 +14,6 @@ import OtaTaskRecordList from '../record/modules/list.vue';
import TaskInfo from './info.vue';
import UpgradeStatistics from './statistics.vue';
// TODO @AI是不是defineOptions、升级任务详情 注释需要?
/** IoT OTA 升级任务详情 */
defineOptions({ name: 'IoTOtaTaskDetail' });
const emit = defineEmits(['success']);
const taskId = ref<number>();

View File

@@ -12,10 +12,6 @@ import { $t } from '#/locales';
import { useFormSchema } from '../data';
// TODO @AI是不是defineOptions、升级任务表单 注释需要?
/** IoT OTA 升级任务表单 */
defineOptions({ name: 'IoTOtaTaskForm' });
const emit = defineEmits(['success']);
const [Form, formApi] = useVbenForm({
@@ -29,7 +25,6 @@ const [Form, formApi] = useVbenForm({
showDefaultActions: false,
});
// TODO @AI注释风格需要对齐其他 form
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
@@ -37,9 +32,11 @@ const [Modal, modalApi] = useVbenModal({
return;
}
modalApi.lock();
// 提交表单
const data = (await formApi.getValues()) as IoTOtaTaskApi.Task;
try {
const data = (await formApi.getValues()) as IoTOtaTaskApi.Task;
await createOtaTask(data);
// 关闭并提示
await modalApi.close();
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
@@ -51,6 +48,7 @@ const [Modal, modalApi] = useVbenModal({
if (!isOpen) {
return;
}
// 加载数据
const data = modalApi.getData<{ firmwareId: number; productId: number }>();
if (!data?.firmwareId || !data?.productId) {
return;
@@ -61,6 +59,7 @@ const [Modal, modalApi] = useVbenModal({
await formApi.setValues({ firmwareId: data.firmwareId });
// 加载产品下的设备列表
const devices = (await getDeviceListByProductId(data.productId)) || [];
// 注入到 deviceIds 字段的 options
formApi.updateSchema([
{
fieldName: 'deviceIds',

View File

@@ -7,10 +7,6 @@ import { useDescription } from '#/components/description';
import { useDetailSchema } from '../data';
// TODO @AI这里是不是可以去掉
/** IoT OTA 升级任务基本信息 */
defineOptions({ name: 'IoTOtaTaskInfo' });
defineProps<{
loading?: boolean;
task: IoTOtaTaskApi.Task;

View File

@@ -1,5 +1,4 @@
<script setup lang="ts">
// TODO @AI是不是改成 statistics.vue 简化掉?
import { computed } from 'vue';
import { DICT_TYPE } from '@vben/constants';

View File

@@ -15,10 +15,6 @@ import { IoTOtaTaskRecordStatusEnum } from '#/views/iot/utils/constants';
import { useGridColumns } from '../data';
/** IoT OTA 升级记录列表 */
// TODO @AIdefineOptions({ name: 'IoTOtaTaskRecordList' });还需要么?
defineOptions({ name: 'IoTOtaTaskRecordList' });
const props = defineProps<{
taskId: number | undefined;
}>();
@@ -48,7 +44,6 @@ async function handleTabChange(tabKey: number | string) {
}
/** 取消单条记录的升级 */
// TODO @AI需要类似别的写下注释么
async function handleCancelUpgrade(record: IoTOtaTaskRecordApi.TaskRecord) {
await cancelOtaTaskRecord(record.id as number);
message.success('取消成功');
@@ -77,7 +72,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
pageNo: page.currentPage,
pageSize: page.pageSize,
taskId: props.taskId,
// TODO @AI别的模块一般是独立的属性还是设置到 formValues 里?(调研下;)
status: activeTab.value === '' ? undefined : Number(activeTab.value),
});
},