设备数据查看优化
This commit is contained in:
parent
fa8a4c9cc7
commit
b4530f1360
@ -197,12 +197,12 @@ async function submit() {
|
||||
|
||||
const fetchParams: any = isEdit
|
||||
? {
|
||||
id: editRow.value.id,
|
||||
...formValues,
|
||||
}
|
||||
id: editRow.value.id,
|
||||
...formValues,
|
||||
}
|
||||
: {
|
||||
...formValues,
|
||||
};
|
||||
...formValues,
|
||||
};
|
||||
|
||||
try {
|
||||
const resp = await api({ body: fetchParams });
|
||||
@ -311,20 +311,20 @@ async function onStatusChange(record: any) {
|
||||
<Grid>
|
||||
<template #toolbar-actions>
|
||||
<TableAction :actions="[
|
||||
{
|
||||
label: $t('common.add'),
|
||||
type: 'primary',
|
||||
icon: 'ant-design:plus-outlined',
|
||||
onClick: openAddModal.bind(null),
|
||||
auth: ['AbpIdentity.Users.Create'],
|
||||
},
|
||||
{
|
||||
label: $t('common.add'),
|
||||
type: 'primary',
|
||||
icon: 'ant-design:plus-outlined',
|
||||
onClick: openAddModal.bind(null),
|
||||
auth: ['AbpIdentity.Users.Create'],
|
||||
},
|
||||
]" />
|
||||
</template>
|
||||
|
||||
<template #isEnable="{ row }">
|
||||
<component :is="h(Tag, { color: row.isEnabled ? 'green' : 'red' }, () =>
|
||||
row.isEnabled ? $t('common.yes') : $t('common.no'),
|
||||
)
|
||||
)
|
||||
" />
|
||||
</template>
|
||||
|
||||
@ -338,13 +338,13 @@ async function onStatusChange(record: any) {
|
||||
|
||||
<template #action="{ row }">
|
||||
<TableAction :actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
size: 'small',
|
||||
auth: ['AbpIdentity.Users.Update'],
|
||||
onClick: onEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
size: 'small',
|
||||
auth: ['AbpIdentity.Users.Update'],
|
||||
onClick: onEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: row.isEnabled ? '禁用' : '启用',
|
||||
type: 'link',
|
||||
|
||||
@ -229,15 +229,12 @@ function onDel(row: any) {
|
||||
},
|
||||
});
|
||||
}
|
||||
const toStatusData = (row: Record<string, any>) => {
|
||||
const toDeviceInfoData = (row: Record<string, any>) => {
|
||||
// 或者使用编程式导航
|
||||
router.push({
|
||||
path: '/iotdb/deviceData',
|
||||
path: '/iotdbdatamanagement/deviceData',
|
||||
query: {
|
||||
DeviceType: row.ioTPlatform,
|
||||
DeviceId: row.deviceAddress,
|
||||
FocusAddress: row.ioTPlatformDeviceOpenInfo,
|
||||
DataBaseName: row.deviceName,
|
||||
DeviceAddress: row.deviceAddress,
|
||||
},
|
||||
});
|
||||
};
|
||||
@ -359,7 +356,7 @@ const toolbarActions = computed(() => [
|
||||
type: 'link',
|
||||
size: 'small',
|
||||
auth: ['AbpIdentity.Users.Update'],
|
||||
onClick: toStatusData.bind(null, row),
|
||||
onClick: toDeviceInfoData.bind(null, row),
|
||||
},
|
||||
]" :drop-down-actions="[
|
||||
{
|
||||
|
||||
@ -16,7 +16,7 @@ export const querySchema = computed(() => [
|
||||
api: getCommonGetSelectList,
|
||||
params: {
|
||||
query: {
|
||||
typeName: 'IoTDBDataTypeConst',
|
||||
typeName: 'IoTDBDataTypeConst',
|
||||
},
|
||||
},
|
||||
labelField: 'value',
|
||||
|
||||
@ -68,7 +68,7 @@ const formatDate = (date: Date | string) => {
|
||||
};
|
||||
|
||||
const route = useRoute();
|
||||
const { DeviceType, DeviceId } = route.query;
|
||||
const { DeviceType, DeviceAddress } = route.query;
|
||||
|
||||
// 动态列定义
|
||||
const dynamicColumns = ref<any[]>([]);
|
||||
@ -146,6 +146,8 @@ const initDefaultColumns = () => {
|
||||
|
||||
// 表格是否已初始化
|
||||
const isGridInitialized = ref(false);
|
||||
// 是否正在初始化,用于防止重复查询
|
||||
const isInitializing = ref(false);
|
||||
|
||||
// 初始化默认列
|
||||
initDefaultColumns();
|
||||
@ -154,12 +156,17 @@ const formOptions: VbenFormProps = {
|
||||
schema: querySchema.value,
|
||||
initialValues: {
|
||||
DeviceType: DeviceType ? Number(DeviceType) : undefined,
|
||||
DeviceAddress: DeviceId as string, // 使用DeviceId作为DeviceAddress的初始值
|
||||
DeviceAddress: DeviceAddress as string, // 使用DeviceAddress作为初始值
|
||||
},
|
||||
// 禁用表单值变化时自动提交,使用自定义处理函数
|
||||
submitOnChange: false,
|
||||
// 添加表单值变化的处理函数
|
||||
handleValuesChange: async (values, changedFields) => {
|
||||
// 如果正在初始化,不触发查询
|
||||
if (isInitializing.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 当任何相关字段发生变化时,刷新表格数据
|
||||
const relevantFields = new Set([
|
||||
'DeviceAddress',
|
||||
@ -266,6 +273,11 @@ const gridOptions: VxeGridProps<any> = {
|
||||
formValues ||
|
||||
(gridApi?.formApi ? await gridApi.formApi.getValues() : {}) ||
|
||||
{};
|
||||
|
||||
// 如果表单中没有DeviceAddress,但有路由参数,使用路由参数
|
||||
if (!currentFormValues.DeviceAddress && DeviceAddress) {
|
||||
currentFormValues.DeviceAddress = DeviceAddress as string;
|
||||
}
|
||||
// 处理DeviceType和IoTDataType,确保传递数字类型
|
||||
const deviceTypeValue = currentFormValues.DeviceType;
|
||||
const deviceTypeNumber = deviceTypeValue
|
||||
@ -285,11 +297,16 @@ const gridOptions: VxeGridProps<any> = {
|
||||
// 获取选中的设备信息
|
||||
let deviceAddress = currentFormValues.DeviceAddress || '';
|
||||
|
||||
// 如果表单中没有DeviceAddress,但有路由参数,使用路由参数
|
||||
if (!deviceAddress && DeviceAddress) {
|
||||
deviceAddress = DeviceAddress as string;
|
||||
}
|
||||
|
||||
// 优先使用选中的设备信息
|
||||
const deviceInfo =
|
||||
selectedDeviceInfo.value ||
|
||||
(currentFormValues.DeviceAddress && deviceOptions.value.length > 0
|
||||
? getDeviceInfoByAddress(currentFormValues.DeviceAddress)
|
||||
(deviceAddress && deviceOptions.value.length > 0
|
||||
? getDeviceInfoByAddress(deviceAddress)
|
||||
: null);
|
||||
|
||||
if (deviceInfo) {
|
||||
@ -365,7 +382,7 @@ const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
||||
watch(
|
||||
() => gridApi?.pagerApi?.pageSize,
|
||||
(newSize, oldSize) => {
|
||||
if (newSize !== oldSize && oldSize) {
|
||||
if (newSize !== oldSize && oldSize && !isInitializing.value) {
|
||||
// 重置到第一页
|
||||
gridApi.pagerApi.currentPage = 1;
|
||||
// 触发数据重新加载
|
||||
@ -378,7 +395,7 @@ watch(
|
||||
watch(
|
||||
() => gridApi?.pagerApi?.currentPage,
|
||||
(newPage, oldPage) => {
|
||||
if (newPage !== oldPage && oldPage) {
|
||||
if (newPage !== oldPage && oldPage && !isInitializing.value) {
|
||||
// 触发数据重新加载
|
||||
gridApi.reload();
|
||||
}
|
||||
@ -388,6 +405,9 @@ watch(
|
||||
// 初始化函数
|
||||
const initializeGrid = async () => {
|
||||
try {
|
||||
// 设置初始化标志
|
||||
isInitializing.value = true;
|
||||
|
||||
// 获取设备信息数据
|
||||
await fetchDeviceOptions();
|
||||
|
||||
@ -409,23 +429,47 @@ const initializeGrid = async () => {
|
||||
}
|
||||
|
||||
// 如果有路由参数,自动触发查询
|
||||
if (DeviceType || DeviceId) {
|
||||
if (DeviceType || DeviceAddress) {
|
||||
// 延迟一下确保表格已完全初始化
|
||||
setTimeout(() => {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
setTimeout(async () => {
|
||||
if (gridApi && gridApi.formApi) {
|
||||
// 确保表单值正确设置
|
||||
const currentValues = await gridApi.formApi.getValues();
|
||||
if (!currentValues.DeviceAddress && DeviceAddress) {
|
||||
await gridApi.formApi.setValues({
|
||||
...currentValues,
|
||||
DeviceAddress: DeviceAddress as string,
|
||||
});
|
||||
}
|
||||
// 延迟清除初始化标志,确保只触发一次查询
|
||||
setTimeout(() => {
|
||||
isInitializing.value = false;
|
||||
// 确保表单值正确设置后再触发查询
|
||||
gridApi.reload();
|
||||
}, 200);
|
||||
} else {
|
||||
isInitializing.value = false;
|
||||
}
|
||||
}, 300);
|
||||
} else {
|
||||
// 如果没有路由参数,直接清除初始化标志
|
||||
isInitializing.value = false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('初始化表格失败:', error);
|
||||
isInitializing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 监听路由参数变化,当有路由参数时自动触发查询
|
||||
watch(
|
||||
() => [DeviceType, DeviceId],
|
||||
() => [DeviceType, DeviceAddress],
|
||||
async (newValues, oldValues) => {
|
||||
// 如果正在初始化,不触发额外的查询
|
||||
if (isInitializing.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果有路由参数,等待设备信息加载完成后自动触发查询
|
||||
if (newValues.some(Boolean) && gridApi && isGridInitialized.value) {
|
||||
// 延迟一下确保表单值已经设置
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user