修复下面的问题 和其他页面中的类似问题

1.apps/web-antd/src/views/iot/device/device/modules/DeviceForm.vue
type 是和方法分离的

2.apps/web-antd/src/views/iot/device/device/modules/detail/DeviceDetailsMessage.vue
const getMessageList = async () => {
方法使用function 不要用const,保持一致

3.apps/web-antd/src/views/iot/device/device/modules/detail/DeviceDetailsMessage.vue
<script setup lang="ts">
文件结构是

4.apps/web-antd/src/views/iot/rule/data/rule/index.vue
handleRefresh 统一命名

Signed-off-by: Administrator <425053404@qq.com>
This commit is contained in:
Administrator
2025-10-17 18:06:58 +08:00
parent 1190121773
commit cec1cc7590
18 changed files with 232 additions and 233 deletions

View File

@@ -21,7 +21,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -82,7 +82,7 @@ async function handleDelete(row: AlertConfigApi.AlertConfig) {
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
handleRefresh();
} finally {
hideLoading();
}
@@ -121,7 +121,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="告警配置列表">
<template #toolbar-tools>
<TableAction

View File

@@ -22,7 +22,7 @@ const productList = ref<any[]>([]);
const deviceList = ref<any[]>([]);
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}

View File

@@ -8,8 +8,8 @@ import {
createDevice,
getDevice,
updateDevice,
type IotDeviceApi
} from '#/api/iot/device/device';
import type { IotDeviceApi } from '#/api/iot/device/device';
import { $t } from '#/locales';
import { useFormSchema } from '../data';

View File

@@ -111,14 +111,14 @@ const [Modal, modalApi] = useVbenModal({
});
/** 下载模板 */
const handleDownloadTemplate = async () => {
async function handleDownloadTemplate() {
try {
const res = await importDeviceTemplate();
downloadFileFromBlobPart({ fileName: '设备导入模版.xls', source: res });
} catch (error: any) {
message.error(error.message || '下载失败');
}
};
}
</script>
<template>

View File

@@ -139,7 +139,7 @@ const rowSelection = computed(() => ({
}));
/** 查询列表 */
const getList = async () => {
async function getList() {
loading.value = true;
try {
if (props.productId) {
@@ -151,22 +151,22 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 搜索按钮操作 */
const handleQuery = () => {
function handleQuery() {
queryParams.pageNo = 1;
getList();
};
}
/** 重置按钮操作 */
const resetQuery = () => {
function resetQuery() {
queryFormRef.value.resetFields();
handleQuery();
};
}
/** 打开弹窗 */
const open = async () => {
async function open() {
dialogVisible.value = true;
// 重置选择状态
selectedDevices.value = [];
@@ -178,7 +178,7 @@ const open = async () => {
}
// 获取设备列表
await getList();
};
}
defineExpose({ open });
/** 处理行点击事件 */

View File

@@ -1,4 +1,164 @@
<!-- 设备消息列表 -->
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
import { ContentWrap } from '@vben/common-ui';
import { DICT_TYPE } from '@vben/constants';
import { IconifyIcon } from '@vben/icons';
import { formatDate } from '@vben/utils';
import { Button, Form, Pagination, Select, Switch, Table, Tag } from 'ant-design-vue';
import { getDeviceMessagePage } from '#/api/iot/device/device';
import { DictTag } from '#/components/dict-tag';
import { IotDeviceMessageMethodEnum } from '#/views/iot/utils/constants';
const props = defineProps<{
deviceId: number;
}>();
// 查询参数
const queryParams = reactive({
deviceId: props.deviceId,
method: undefined,
upstream: undefined,
pageNo: 1,
pageSize: 10,
});
// 列表数据
const loading = ref(false);
const total = ref(0);
const list = ref<any[]>([]);
const autoRefresh = ref(false); // 自动刷新开关
let autoRefreshTimer: any = null; // 自动刷新定时器
// 消息方法选项
const methodOptions = computed(() => {
return Object.values(IotDeviceMessageMethodEnum).map((item) => ({
label: item.name,
value: item.method,
}));
});
// 表格列定义
const columns = [
{
title: '时间',
dataIndex: 'ts',
key: 'ts',
align: 'center' as const,
width: 180,
},
{
title: '上行/下行',
dataIndex: 'upstream',
key: 'upstream',
align: 'center' as const,
width: 140,
},
{
title: '是否回复',
dataIndex: 'reply',
key: 'reply',
align: 'center' as const,
width: 140,
},
{
title: '请求编号',
dataIndex: 'requestId',
key: 'requestId',
align: 'center' as const,
width: 300,
},
{
title: '请求方法',
dataIndex: 'method',
key: 'method',
align: 'center' as const,
width: 140,
},
{
title: '请求/响应数据',
dataIndex: 'params',
key: 'params',
align: 'center' as const,
ellipsis: true,
},
];
/** 查询消息列表 */
async function getMessageList() {
if (!props.deviceId) return;
loading.value = true;
try {
const data = await getDeviceMessagePage(queryParams);
total.value = data.total;
list.value = data.list;
} finally {
loading.value = false;
}
}
/** 搜索操作 */
function handleQuery() {
queryParams.pageNo = 1;
getMessageList();
}
/** 监听自动刷新 */
watch(autoRefresh, (newValue) => {
if (newValue) {
autoRefreshTimer = setInterval(() => {
getMessageList();
}, 5000);
} else {
clearInterval(autoRefreshTimer);
autoRefreshTimer = null;
}
});
/** 监听设备标识变化 */
watch(
() => props.deviceId,
(newValue) => {
if (newValue) {
handleQuery();
}
},
);
/** 组件卸载时清除定时器 */
onBeforeUnmount(() => {
if (autoRefreshTimer) {
clearInterval(autoRefreshTimer);
autoRefreshTimer = null;
}
});
/** 初始化 */
onMounted(() => {
if (props.deviceId) {
getMessageList();
}
});
/** 刷新消息列表 */
function refresh(delay = 0) {
if (delay > 0) {
setTimeout(() => {
handleQuery();
}, delay);
} else {
handleQuery();
}
}
/** 暴露方法给父组件 */
defineExpose({
refresh,
});
</script>
<template>
<ContentWrap>
<!-- 搜索区域 -->
@@ -94,164 +254,3 @@
</div>
</ContentWrap>
</template>
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
import { ContentWrap } from '@vben/common-ui';
import { DICT_TYPE } from '@vben/constants';
import { IconifyIcon } from '@vben/icons';
import { formatDate } from '@vben/utils';
import { Button, Form, Pagination, Select, Switch, Table, Tag } from 'ant-design-vue';
import { getDeviceMessagePage } from '#/api/iot/device/device';
import { DictTag } from '#/components/dict-tag';
import { IotDeviceMessageMethodEnum } from '#/views/iot/utils/constants';
const props = defineProps<{
deviceId: number;
}>();
// 查询参数
const queryParams = reactive({
deviceId: props.deviceId,
method: undefined,
upstream: undefined,
pageNo: 1,
pageSize: 10,
});
// 列表数据
const loading = ref(false);
const total = ref(0);
const list = ref<any[]>([]);
const autoRefresh = ref(false); // 自动刷新开关
let autoRefreshTimer: any = null; // 自动刷新定时器
// 消息方法选项
const methodOptions = computed(() => {
return Object.values(IotDeviceMessageMethodEnum).map((item) => ({
label: item.name,
value: item.method,
}));
});
// 表格列定义
const columns = [
{
title: '时间',
dataIndex: 'ts',
key: 'ts',
align: 'center' as const,
width: 180,
},
{
title: '上行/下行',
dataIndex: 'upstream',
key: 'upstream',
align: 'center' as const,
width: 140,
},
{
title: '是否回复',
dataIndex: 'reply',
key: 'reply',
align: 'center' as const,
width: 140,
},
{
title: '请求编号',
dataIndex: 'requestId',
key: 'requestId',
align: 'center' as const,
width: 300,
},
{
title: '请求方法',
dataIndex: 'method',
key: 'method',
align: 'center' as const,
width: 140,
},
{
title: '请求/响应数据',
dataIndex: 'params',
key: 'params',
align: 'center' as const,
ellipsis: true,
},
];
/** 查询消息列表 */
const getMessageList = async () => {
if (!props.deviceId) return;
loading.value = true;
try {
const data = await getDeviceMessagePage(queryParams);
total.value = data.total;
list.value = data.list;
} finally {
loading.value = false;
}
};
/** 搜索操作 */
const handleQuery = () => {
queryParams.pageNo = 1;
getMessageList();
};
/** 监听自动刷新 */
watch(autoRefresh, (newValue) => {
if (newValue) {
autoRefreshTimer = setInterval(() => {
getMessageList();
}, 5000);
} else {
clearInterval(autoRefreshTimer);
autoRefreshTimer = null;
}
});
/** 监听设备标识变化 */
watch(
() => props.deviceId,
(newValue) => {
if (newValue) {
handleQuery();
}
},
);
/** 组件卸载时清除定时器 */
onBeforeUnmount(() => {
if (autoRefreshTimer) {
clearInterval(autoRefreshTimer);
autoRefreshTimer = null;
}
});
/** 初始化 */
onMounted(() => {
if (props.deviceId) {
getMessageList();
}
});
/** 刷新消息列表 */
const refresh = (delay = 0) => {
if (delay > 0) {
setTimeout(() => {
handleQuery();
}, delay);
} else {
handleQuery();
}
};
/** 暴露方法给父组件 */
defineExpose({
refresh,
});
</script>

View File

@@ -52,7 +52,7 @@ const serviceThingModels = computed(() => {
});
/** 查询列表 */
const getList = async () => {
async function getList() {
if (!props.deviceId) return;
loading.value = true;
try {
@@ -62,43 +62,43 @@ const getList = async () => {
} finally {
loading.value = false;
}
};
}
/** 搜索按钮操作 */
const handleQuery = () => {
function handleQuery() {
queryParams.pageNo = 1;
getList();
};
}
/** 重置按钮操作 */
const resetQuery = () => {
function resetQuery() {
queryFormRef.value?.resetFields();
queryParams.identifier = '';
queryParams.times = [];
handleQuery();
};
}
/** 获取服务名称 */
const getServiceName = (identifier: string | undefined) => {
function getServiceName(identifier: string | undefined) {
if (!identifier) return '-';
const service = serviceThingModels.value.find(
(item: ThingModelData) => item.identifier === identifier,
);
return service?.name || identifier;
};
}
/** 获取调用方式 */
const getCallType = (identifier: string | undefined) => {
function getCallType(identifier: string | undefined) {
if (!identifier) return '-';
const service = serviceThingModels.value.find(
(item: ThingModelData) => item.identifier === identifier,
);
if (!service?.service?.callType) return '-';
return getThingModelServiceCallTypeLabel(service.service.callType) || '-';
};
}
/** 解析参数 */
const parseParams = (params: string) => {
function parseParams(params: string) {
if (!params) return '-';
try {
const parsed = JSON.parse(params);
@@ -109,7 +109,7 @@ const parseParams = (params: string) => {
} catch {
return params;
}
};
}
/** 初始化 */
onMounted(() => {

View File

@@ -22,7 +22,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -47,7 +47,7 @@ async function handleDelete(row: IotDeviceGroupApi.DeviceGroup) {
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
handleRefresh();
} finally {
hideLoading();
}
@@ -97,7 +97,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="设备分组列表">
<template #toolbar-tools>
<TableAction

View File

@@ -22,7 +22,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -52,7 +52,7 @@ async function handleDelete(row: IoTOtaFirmwareApi.Firmware) {
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
handleRefresh();
} finally {
hideLoading();
}
@@ -91,7 +91,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="固件列表">
<template #toolbar-tools>
<TableAction

View File

@@ -21,7 +21,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -46,7 +46,7 @@ async function handleDelete(row: IoTOtaFirmwareApi.Firmware) {
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
handleRefresh();
} finally {
hideLoading();
}
@@ -85,7 +85,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="OTA 固件列表">
<template #toolbar-tools>
<TableAction

View File

@@ -21,7 +21,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -46,7 +46,7 @@ async function handleDelete(row: any) {
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
handleRefresh();
} finally {
hideLoading();
}
@@ -85,7 +85,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="数据规则列表">
<template #toolbar-tools>
<TableAction

View File

@@ -21,7 +21,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -46,7 +46,7 @@ async function handleDelete(row: any) {
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
handleRefresh();
} finally {
hideLoading();
}
@@ -85,7 +85,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="数据规则列表">
<template #toolbar-tools>
<TableAction

View File

@@ -21,7 +21,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -46,7 +46,7 @@ async function handleDelete(row: any) {
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
handleRefresh();
} finally {
hideLoading();
}
@@ -85,7 +85,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="数据目的列表">
<template #toolbar-tools>
<TableAction

View File

@@ -33,7 +33,7 @@ const subGroup = useVModel(props, 'modelValue', emit);
const maxConditions = computed(() => props.maxConditions || 3); // 最大条件数量
/** 添加条件 */
const addCondition = async () => {
async function addCondition() {
// 确保 subGroup.value 是一个数组
if (!subGroup.value) {
subGroup.value = [];
@@ -58,7 +58,7 @@ const addCondition = async () => {
if (subGroup.value) {
subGroup.value.push(newCondition);
}
};
}
/**
* 移除条件

View File

@@ -25,7 +25,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -51,7 +51,7 @@ async function handleToggleStatus(row: RuleSceneApi.SceneRule) {
message.success({
content: newStatus === 0 ? '启用成功' : '停用成功',
});
onRefresh();
handleRefresh();
} finally {
hideLoading();
}
@@ -68,7 +68,7 @@ async function handleDelete(row: RuleSceneApi.SceneRule) {
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
handleRefresh();
} finally {
hideLoading();
}
@@ -107,7 +107,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="场景规则列表">
<template #toolbar-tools>
<TableAction

View File

@@ -63,17 +63,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
});
// 新增功能
const handleCreate = () => {
function handleCreate() {
thingModelFormRef.value?.open('create');
};
}
// 编辑功能
const handleEdit = (row: any) => {
function handleEdit(row: any) {
thingModelFormRef.value?.open('update', row.id);
};
}
// 删除功能
const handleDelete = async (row: any) => {
async function handleDelete(row: any) {
try {
await deleteThingModel(row.id);
message.success('删除成功');
@@ -81,31 +81,31 @@ const handleDelete = async (row: any) => {
} catch (error) {
console.error('删除失败:', error);
}
};
}
// 打开 TSL
const handleOpenTSL = () => {
function handleOpenTSL() {
thingModelTSLRef.value?.open();
};
}
// 获取数据类型标签
const getDataTypeLabel = (row: any) => {
function getDataTypeLabel(row: any) {
return getDataTypeOptionsLabel(row.property?.dataType) || '-';
};
}
// 刷新表格
const handleRefresh = () => {
function handleRefresh() {
gridApi.reload();
};
}
// 获取产品信息
const getProductData = async () => {
async function getProductData() {
try {
product.value = await getProduct(props.productId);
} catch (error) {
console.error('获取产品信息失败:', error);
}
};
}
// 初始化
onMounted(async () => {

View File

@@ -61,7 +61,7 @@ const formData = ref<any>({
const formRef = ref(); // 表单 Ref
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
async function open(type: string, id?: number) {
dialogVisible.value = true;
// 设置标题create -> 新增update -> 编辑
dialogTitle.value = type === 'create' ? $t('page.action.add') : $t('page.action.edit');
@@ -137,7 +137,7 @@ const open = async (type: string, id?: number) => {
formLoading.value = false;
}
}
};
}
defineExpose({ open, close: () => (dialogVisible.value = false) });
async function submitForm() {

View File

@@ -18,17 +18,17 @@ const product = inject<Ref<IotProductApi.Product>>(IOT_PROVIDE_KEY.PRODUCT); //
const viewMode = ref('view'); // 查看模式view-代码视图editor-编辑器视图
/** 打开弹窗 */
const open = async () => {
async function open() {
dialogVisible.value = true;
await getTsl();
};
}
defineExpose({ open });
/** 获取 TSL */
const thingModelTSL = ref<any>({});
const tslString = ref(''); // 用于编辑器的字符串格式
const getTsl = async () => {
async function getTsl() {
try {
thingModelTSL.value = await getThingModelTSL(product?.value?.id || 0);
// 将对象转换为格式化的 JSON 字符串
@@ -38,7 +38,7 @@ const getTsl = async () => {
thingModelTSL.value = {};
tslString.value = '{}';
}
};
}
/** 格式化的 TSL 用于只读展示 */
const formattedTSL = computed(() => {