162 lines
4.3 KiB
Vue
Raw Normal View History

2025-06-25 17:29:57 +08:00
<script setup lang="ts">
import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
2025-07-17 10:27:56 +08:00
import { ref, watch } from 'vue';
2025-06-25 17:29:57 +08:00
import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
2025-07-11 11:48:12 +08:00
import { postCTWingLogInfoPage } from '#/api-client';
2025-06-25 17:29:57 +08:00
2025-07-17 10:23:38 +08:00
import DeviceSelect from '../deviceData/DeviceSelect.vue';
2025-07-17 10:27:56 +08:00
import { querySchema, tableSchema } from './schema';
2025-06-25 17:29:57 +08:00
defineOptions({
2025-07-11 11:48:12 +08:00
name: 'CTWingLog',
2025-06-25 17:29:57 +08:00
});
const route = useRoute();
const { DeviceType, DeviceId, FocusAddress } = route.query;
2025-07-17 10:23:38 +08:00
// 添加设备选择器引用
const deviceSelectRef = ref();
// 添加选中的设备信息
const selectedDeviceInfo = ref<any>(null);
// 格式化日期函数
const formatDate = (date: any) => {
if (!date) return '';
if (typeof date === 'string') return date;
if (date.toISOString) return date.format('YYYY-MM-DD HH:mm:ss');
return '';
2025-07-17 10:27:56 +08:00
};
2025-06-25 17:29:57 +08:00
const formOptions: VbenFormProps = {
schema: querySchema.value,
};
2025-07-17 10:23:38 +08:00
2025-07-11 11:48:12 +08:00
const gridOptions: VxeGridProps<any> = {
2025-06-25 17:29:57 +08:00
checkboxConfig: {
highlight: true,
labelField: 'name',
},
2025-07-11 11:48:12 +08:00
columns: tableSchema.value,
2025-06-25 17:29:57 +08:00
height: 'auto',
keepSource: true,
2025-07-17 10:23:38 +08:00
pagerConfig: {
2025-07-17 10:27:56 +08:00
currentPage: 1,
2025-07-17 10:23:38 +08:00
pageSize: 10,
pageSizes: [10, 20, 100],
2025-07-17 10:27:56 +08:00
layouts: [
'PrevPage',
'JumpNumber',
'NextPage',
'FullJump',
'Sizes',
'Total',
],
2025-07-17 10:23:38 +08:00
},
2025-06-25 17:29:57 +08:00
toolbarConfig: {
custom: true,
},
customConfig: {
storage: true,
},
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
2025-07-17 10:23:38 +08:00
// 获取选中的设备信息
let deviceId = '';
let systemName = '';
2025-07-17 10:27:56 +08:00
const deviceType = formValues?.DeviceType || '';
const finalFocusAddress = formValues.FocusAddress || '';
2025-07-17 10:23:38 +08:00
if (deviceSelectRef.value) {
const deviceInfo = deviceSelectRef.value.getSelectedDeviceInfo();
if (deviceInfo) {
2025-07-17 10:27:56 +08:00
finalFocusAddress = deviceInfo.focusAddress || '';
2025-07-17 10:23:38 +08:00
systemName = deviceInfo.systemName || '';
// 设备类型为10时取focusId其他情况取meterId
2025-07-17 10:27:56 +08:00
deviceId =
Number(deviceType) === 10
? deviceInfo.focusId || ''
: deviceInfo.meterId || '';
2025-07-17 10:23:38 +08:00
}
}
2025-07-14 16:04:42 +08:00
// 构建查询参数
const queryParams: any = {
2025-07-11 11:48:12 +08:00
pageIndex: page.currentPage,
pageSize: page.pageSize,
2025-07-17 10:23:38 +08:00
SearchKeyword: formValues?.SearchKeyword || '',
DeviceType: deviceType,
IoTDataType: formValues?.IoTDataType || '',
DeviceId: deviceId,
SystemName: systemName || formValues?.SystemName || '',
StartCreationTime: formatDate(formValues?.StartCreationTime),
EndCreationTime: formatDate(formValues?.EndCreationTime),
2025-07-17 10:27:56 +08:00
FocusAddress: finalFocusAddress,
2025-07-14 16:04:42 +08:00
};
if (DeviceType) queryParams.DeviceType = DeviceType;
if (DeviceId) queryParams.DeviceId = DeviceId;
const { data } = await postCTWingLogInfoPage({
body: queryParams,
2025-07-11 11:48:12 +08:00
});
const result = {
items: data.items || [],
totalCount: data.totalCount || (data.items ? data.items.length : 0),
};
return result;
2025-06-25 17:29:57 +08:00
},
},
},
};
2025-07-17 10:23:38 +08:00
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
// 监听分页器状态变化
watch(
() => gridApi?.pagerApi?.pageSize,
(newSize, oldSize) => {
if (newSize !== oldSize && oldSize) {
// 重置到第一页
gridApi.pagerApi.currentPage = 1;
// 触发数据重新加载
gridApi.reload();
}
},
);
// 监听当前页变化
watch(
() => gridApi?.pagerApi?.currentPage,
(newPage, oldPage) => {
if (newPage !== oldPage && oldPage) {
// 触发数据重新加载
gridApi.reload();
}
},
);
// 监听DeviceId变化自动刷新表格
watch(
() => gridApi?.getFormModel?.()?.DeviceId,
(newVal, oldVal) => {
if (newVal !== oldVal) {
gridApi.reload();
}
},
);
2025-06-25 17:29:57 +08:00
</script>
<template>
<Page auto-content-height>
2025-07-17 10:23:38 +08:00
<Grid>
2025-07-17 10:27:56 +08:00
<template #DeviceId="{ model, field }">
<DeviceSelect ref="deviceSelectRef" v-model:value="model[field]"
:placeholder="$t('common.pleaseSelect') + $t('abp.log.deviceInfo')" allow-clear />
2025-07-17 10:23:38 +08:00
</template>
</Grid>
2025-06-25 17:29:57 +08:00
</Page>
</template>