fix: iot
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { deleteOtaFirmware, getOtaFirmwarePage } from '#/api/iot/ota/firmware';
|
||||
import { getSimpleProductList } from '#/api/iot/product/product';
|
||||
import { $t } from '#/locales';
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
/** 新增/修改固件的表单 */
|
||||
@@ -157,51 +152,3 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** Grid 配置项 */
|
||||
export function useGridOptions(): VxeTableGridOptions<IoTOtaFirmwareApi.Firmware> {
|
||||
return {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getOtaFirmwarePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** 删除固件 */
|
||||
export async function handleDeleteFirmware(
|
||||
row: IoTOtaFirmwareApi.Firmware,
|
||||
onSuccess: () => void,
|
||||
) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteOtaFirmware(row.id as number);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
|
||||
});
|
||||
onSuccess();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteOtaFirmware, getOtaFirmwarePage } from '#/api/iot/ota/firmware';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import Form from '../modules/OtaFirmwareForm.vue';
|
||||
import {
|
||||
handleDeleteFirmware,
|
||||
useGridFormSchema,
|
||||
useGridOptions,
|
||||
} from './data';
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
|
||||
defineOptions({ name: 'IoTOtaFirmware' });
|
||||
|
||||
@@ -35,21 +35,56 @@ function handleEdit(row: IoTOtaFirmwareApi.Firmware) {
|
||||
formModalApi.setData({ type: 'update', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 删除固件 */
|
||||
async function handleDelete(row: IoTOtaFirmwareApi.Firmware) {
|
||||
await handleDeleteFirmware(row, onRefresh);
|
||||
}
|
||||
|
||||
/** 查看固件详情 */
|
||||
function handleDetail(row: IoTOtaFirmwareApi.Firmware) {
|
||||
formModalApi.setData({ type: 'view', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 删除固件 */
|
||||
async function handleDelete(row: IoTOtaFirmwareApi.Firmware) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteOtaFirmware(row.id as number);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: useGridOptions(),
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getOtaFirmwarePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<IoTOtaFirmwareApi.Firmware>,
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -27,17 +27,17 @@ const firmwareStatisticsLoading = ref(false);
|
||||
const firmwareStatistics = ref<Record<string, number>>({});
|
||||
|
||||
/** 获取固件信息 */
|
||||
const getFirmwareInfo = async () => {
|
||||
async function getFirmwareInfo() {
|
||||
firmwareLoading.value = true;
|
||||
try {
|
||||
firmware.value = await IoTOtaFirmwareApi.getOtaFirmware(firmwareId.value);
|
||||
} finally {
|
||||
firmwareLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 获取升级统计 */
|
||||
const getStatistics = async () => {
|
||||
async function getStatistics() {
|
||||
firmwareStatisticsLoading.value = true;
|
||||
try {
|
||||
firmwareStatistics.value =
|
||||
@@ -47,7 +47,7 @@ const getStatistics = async () => {
|
||||
} finally {
|
||||
firmwareStatisticsLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
|
||||
@@ -27,17 +27,17 @@ const firmwareStatisticsLoading = ref(false);
|
||||
const firmwareStatistics = ref<Record<string, number>>({});
|
||||
|
||||
/** 获取固件信息 */
|
||||
const getFirmwareInfo = async () => {
|
||||
async function getFirmwareInfo() {
|
||||
firmwareLoading.value = true;
|
||||
try {
|
||||
firmware.value = await IoTOtaFirmwareApi.getOtaFirmware(firmwareId.value);
|
||||
} finally {
|
||||
firmwareLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 获取升级统计 */
|
||||
const getStatistics = async () => {
|
||||
async function getStatistics() {
|
||||
firmwareStatisticsLoading.value = true;
|
||||
try {
|
||||
firmwareStatistics.value =
|
||||
@@ -47,7 +47,7 @@ const getStatistics = async () => {
|
||||
} finally {
|
||||
firmwareStatisticsLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
|
||||
@@ -113,7 +113,7 @@ const columns: TableColumnsType = [
|
||||
const [ModalComponent, modalApi] = useVbenModal();
|
||||
|
||||
/** 获取任务详情 */
|
||||
const getTaskInfo = async () => {
|
||||
async function getTaskInfo() {
|
||||
if (!taskId.value) {
|
||||
return;
|
||||
}
|
||||
@@ -123,10 +123,10 @@ const getTaskInfo = async () => {
|
||||
} finally {
|
||||
taskLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 获取统计数据 */
|
||||
const getStatistics = async () => {
|
||||
async function getStatistics() {
|
||||
if (!taskId.value) {
|
||||
return;
|
||||
}
|
||||
@@ -140,10 +140,10 @@ const getStatistics = async () => {
|
||||
} finally {
|
||||
taskStatisticsLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 获取升级记录列表 */
|
||||
const getRecordList = async () => {
|
||||
async function getRecordList() {
|
||||
if (!taskId.value) {
|
||||
return;
|
||||
}
|
||||
@@ -156,26 +156,26 @@ const getRecordList = async () => {
|
||||
} finally {
|
||||
recordLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 切换标签 */
|
||||
const handleTabChange = (tabKey: number | string) => {
|
||||
function handleTabChange(tabKey: number | string) {
|
||||
activeTab.value = String(tabKey);
|
||||
queryParams.pageNo = 1;
|
||||
queryParams.status =
|
||||
activeTab.value === '' ? undefined : Number.parseInt(String(tabKey));
|
||||
getRecordList();
|
||||
};
|
||||
}
|
||||
|
||||
/** 分页变化 */
|
||||
const handleTableChange = (pagination: any) => {
|
||||
function handleTableChange(pagination: any) {
|
||||
queryParams.pageNo = pagination.current;
|
||||
queryParams.pageSize = pagination.pageSize;
|
||||
getRecordList();
|
||||
};
|
||||
}
|
||||
|
||||
/** 取消升级 */
|
||||
const handleCancelUpgrade = async (record: OtaTaskRecord) => {
|
||||
async function handleCancelUpgrade(record: OtaTaskRecord) {
|
||||
Modal.confirm({
|
||||
title: '确认取消',
|
||||
content: '确认要取消该设备的升级任务吗?',
|
||||
@@ -192,10 +192,10 @@ const handleCancelUpgrade = async (record: OtaTaskRecord) => {
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = (id: number) => {
|
||||
function open(id: number) {
|
||||
modalApi.open();
|
||||
taskId.value = id;
|
||||
activeTab.value = '';
|
||||
@@ -206,7 +206,7 @@ const open = (id: number) => {
|
||||
getTaskInfo();
|
||||
getStatistics();
|
||||
getRecordList();
|
||||
};
|
||||
}
|
||||
|
||||
/** 暴露方法 */
|
||||
defineExpose({ open });
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import type { DeviceVO } from '#/api/iot/device/device';
|
||||
import type { IotDeviceApi } from '#/api/iot/device/device';
|
||||
import type { OtaTask } from '#/api/iot/ota/task';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
@@ -57,7 +57,7 @@ const formRules = {
|
||||
},
|
||||
],
|
||||
};
|
||||
const devices = ref<DeviceVO[]>([]);
|
||||
const devices = ref<IotDeviceApi.Device[]>([]);
|
||||
|
||||
/** 设备选项 */
|
||||
const deviceOptions = computed(() => {
|
||||
@@ -107,7 +107,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
});
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
name: '',
|
||||
deviceScope: IoTOtaTaskDeviceScopeEnum.ALL.value,
|
||||
@@ -116,12 +116,12 @@ const resetForm = () => {
|
||||
deviceIds: [],
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
};
|
||||
}
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async () => {
|
||||
async function open() {
|
||||
await modalApi.open();
|
||||
};
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
@@ -40,7 +40,7 @@ const taskFormRef = ref(); // 任务表单引用
|
||||
const taskDetailRef = ref(); // 任务详情引用
|
||||
|
||||
/** 获取任务列表 */
|
||||
const getTaskList = async () => {
|
||||
async function getTaskList() {
|
||||
taskLoading.value = true;
|
||||
try {
|
||||
const data = await IoTOtaTaskApi.getOtaTaskPage(queryParams);
|
||||
@@ -49,32 +49,32 @@ const getTaskList = async () => {
|
||||
} finally {
|
||||
taskLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 搜索 */
|
||||
const handleQuery = () => {
|
||||
function handleQuery() {
|
||||
queryParams.pageNo = 1;
|
||||
getTaskList();
|
||||
};
|
||||
}
|
||||
|
||||
/** 打开任务表单 */
|
||||
const openTaskForm = () => {
|
||||
function openTaskForm() {
|
||||
taskFormRef.value?.open();
|
||||
};
|
||||
}
|
||||
|
||||
/** 处理任务创建成功 */
|
||||
const handleTaskCreateSuccess = () => {
|
||||
function handleTaskCreateSuccess() {
|
||||
getTaskList();
|
||||
emit('success');
|
||||
};
|
||||
}
|
||||
|
||||
/** 查看任务详情 */
|
||||
const handleTaskDetail = (id: number) => {
|
||||
function handleTaskDetail(id: number) {
|
||||
taskDetailRef.value?.open(id);
|
||||
};
|
||||
}
|
||||
|
||||
/** 取消任务 */
|
||||
const handleCancelTask = async (id: number) => {
|
||||
async function handleCancelTask(id: number) {
|
||||
Modal.confirm({
|
||||
title: '确认取消',
|
||||
content: '确认要取消该升级任务吗?',
|
||||
@@ -88,20 +88,20 @@ const handleCancelTask = async (id: number) => {
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/** 刷新数据 */
|
||||
const refresh = async () => {
|
||||
async function refresh() {
|
||||
await getTaskList();
|
||||
emit('success');
|
||||
};
|
||||
}
|
||||
|
||||
/** 分页变化 */
|
||||
const handleTableChange = (pagination: any) => {
|
||||
function handleTableChange(pagination: any) {
|
||||
queryParams.pageNo = pagination.current;
|
||||
queryParams.pageSize = pagination.pageSize;
|
||||
getTaskList();
|
||||
};
|
||||
}
|
||||
|
||||
/** 表格列配置 */
|
||||
const columns: TableColumnsType = [
|
||||
|
||||
Reference in New Issue
Block a user