Compare commits

..

No commits in common. "180718974d3ee06465ff11d873024f510980efe2" and "8b24e4219e6dcc8c8c67078b6489bb9ff1a36196" have entirely different histories.

7 changed files with 111 additions and 202 deletions

View File

@ -8,7 +8,7 @@ import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui'; import { Page } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { postCTWingLogInfoPage, postMetersPage } from '#/api-client'; import { postMetersPage, postCTWingLogInfoPage } from '#/api-client';
import DeviceSelect from '../deviceData/DeviceSelect.vue'; import DeviceSelect from '../deviceData/DeviceSelect.vue';
import { querySchema, tableSchema } from './schema'; import { querySchema, tableSchema } from './schema';
@ -89,21 +89,17 @@ const formOptions: VbenFormProps = {
if (deviceId) { if (deviceId) {
// deviceOptions // deviceOptions
let device = let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
deviceOptions.value.length > 0
? deviceOptions.value.find((d) => d.id === deviceId)
: null;
// DeviceSelect // DeviceSelect
if (!device && gridApi?.formApi) { if (!device && gridApi?.formApi) {
try { try {
// DeviceSelect // DeviceSelect
const deviceSelectRef = const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) { if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
device = deviceSelectRef.getSelectedDevice(); device = deviceSelectRef.getSelectedDevice();
} }
} catch { } catch (error) {
// //
} }
} }
@ -114,15 +110,14 @@ const formOptions: VbenFormProps = {
// //
setTimeout(() => { setTimeout(() => {
try { try {
const deviceSelectRef = const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) { if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
const delayedDevice = deviceSelectRef.getSelectedDevice(); const delayedDevice = deviceSelectRef.getSelectedDevice();
if (delayedDevice) { if (delayedDevice) {
selectedDeviceInfo.value = delayedDevice; selectedDeviceInfo.value = delayedDevice;
} }
} }
} catch { } catch (error) {
// //
} }
}, 100); }, 100);
@ -136,10 +131,10 @@ const formOptions: VbenFormProps = {
const relevantFields = new Set([ const relevantFields = new Set([
'DeviceId', 'DeviceId',
'DeviceType', 'DeviceType',
'EndCreationTime',
'IoTDataType', 'IoTDataType',
'StartCreationTime',
'SystemName', 'SystemName',
'StartCreationTime',
'EndCreationTime',
]); ]);
const hasRelevantChange = changedFields.some((field) => const hasRelevantChange = changedFields.some((field) =>
relevantFields.has(field), relevantFields.has(field),
@ -178,8 +173,8 @@ const gridOptions: VxeGridProps<any> = {
proxyConfig: { proxyConfig: {
ajax: { ajax: {
query: async ({ page }, formValues) => { query: async ({ page }, formValues) => {
// API // formValuesAPI
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {}; const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
// //
let deviceId = currentFormValues.DeviceId || ''; let deviceId = currentFormValues.DeviceId || '';
@ -187,14 +182,10 @@ const gridOptions: VxeGridProps<any> = {
const deviceType = currentFormValues.DeviceType || ''; const deviceType = currentFormValues.DeviceType || '';
// 使 // 使
const deviceInfo = const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
selectedDeviceInfo.value ||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
? getDeviceInfoById(currentFormValues.DeviceId)
: null);
if (deviceInfo) { if (deviceInfo) {
systemName = deviceInfo.businessSystemName || ''; systemName = deviceInfo.systemName || '';
// id // id
if (Number(deviceType) === 10) { if (Number(deviceType) === 10) {
// 使 focusId // 使 focusId
@ -204,6 +195,7 @@ const gridOptions: VxeGridProps<any> = {
deviceId = deviceInfo.meterId || deviceId; deviceId = deviceInfo.meterId || deviceId;
} }
} }
// //
const queryParams = { const queryParams = {
pageIndex: page.currentPage, pageIndex: page.currentPage,

View File

@ -4,7 +4,7 @@ import { computed } from 'vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { getSelectResultList } from '#/api-client'; import { getSelectResultList, postMetersPage } from '#/api-client';
import { $t } from '#/locales'; import { $t } from '#/locales';
export const querySchema = computed(() => [ export const querySchema = computed(() => [
@ -150,20 +150,7 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
minWidth: 150, minWidth: 150,
slots: {}, slots: {},
}, },
{ { field: 'systemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150, slots: {} },
field: 'formattedTimestamps',
title: $t('abp.IoTDBBase.FormattedTimestamps'),
minWidth: '150',
formatter: ({ cellValue }) => {
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
},
},
{
field: 'systemName',
title: $t('abp.IoTDBBase.SystemName'),
minWidth: 150,
slots: {},
},
{ {
field: 'deviceType', field: 'deviceType',
title: $t('abp.IoTDBBase.DeviceType'), title: $t('abp.IoTDBBase.DeviceType'),

View File

@ -1,9 +1,4 @@
import type { import type { FieldMapping, FieldTypeConfig, ColumnConfig, DynamicDeviceData } from './types';
ColumnConfig,
DynamicDeviceData,
FieldMapping,
FieldTypeConfig,
} from './types';
// 字段名映射配置 // 字段名映射配置
export const fieldNameMapping: FieldMapping = { export const fieldNameMapping: FieldMapping = {
@ -39,14 +34,11 @@ const FIXED_FIELDS = [
'DeviceType', 'DeviceType',
'IoTDataType', 'IoTDataType',
'DeviceId', 'DeviceId',
'Timestamps', 'Timestamps'
'FormattedTimestamps',
]; ];
// 动态生成表格列 // 动态生成表格列
export const generateDynamicColumns = ( export const generateDynamicColumns = (data: DynamicDeviceData[]): ColumnConfig[] => {
data: DynamicDeviceData[],
): ColumnConfig[] => {
if (!data || data.length === 0) return []; if (!data || data.length === 0) return [];
// 获取第一条数据的所有字段 // 获取第一条数据的所有字段
@ -55,11 +47,11 @@ export const generateDynamicColumns = (
const fields = Object.keys(firstRow); const fields = Object.keys(firstRow);
// 过滤掉不需要显示的字段和固定字段 // 过滤掉不需要显示的字段和固定字段
const excludeFields = new Set(['__typename', 'id', 'key', ...FIXED_FIELDS]); const excludeFields = ['id', 'key', '__typename', ...FIXED_FIELDS];
return fields return fields
.filter((field) => !excludeFields.has(field)) .filter(field => !excludeFields.includes(field))
.map((field) => { .map(field => {
// 确保字段名是有效的字符串 // 确保字段名是有效的字符串
const safeField = String(field || '').trim(); const safeField = String(field || '').trim();
if (!safeField) return null; if (!safeField) return null;
@ -75,10 +67,7 @@ export const generateDynamicColumns = (
// 应用字段类型配置,确保配置是安全的 // 应用字段类型配置,确保配置是安全的
if (fieldTypeConfig[safeField]) { if (fieldTypeConfig[safeField]) {
const typeConfig = fieldTypeConfig[safeField]; const typeConfig = fieldTypeConfig[safeField];
if ( if (typeConfig.formatter && typeof typeConfig.formatter === 'function') {
typeConfig.formatter &&
typeof typeConfig.formatter === 'function'
) {
columnConfig.formatter = typeConfig.formatter; columnConfig.formatter = typeConfig.formatter;
} }
if (typeConfig.width !== undefined) { if (typeConfig.width !== undefined) {
@ -105,7 +94,7 @@ export const getAllPossibleFields = () => {
// 预定义列配置(可选) // 预定义列配置(可选)
export const getPredefinedColumns = () => { export const getPredefinedColumns = () => {
return getAllPossibleFields().map((field) => ({ return getAllPossibleFields().map(field => ({
field, field,
title: fieldNameMapping[field] || field, title: fieldNameMapping[field] || field,
minWidth: 150, minWidth: 150,

View File

@ -2,7 +2,7 @@
import type { VbenFormProps } from '#/adapter/form'; import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table'; import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed, nextTick, onMounted, ref, watch } from 'vue'; import { computed, nextTick, ref, watch, onMounted } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui'; import { Page } from '@vben/common-ui';
@ -66,6 +66,7 @@ const formatDate = (date: Date | string) => {
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}; };
const route = useRoute(); const route = useRoute();
const { DeviceType, DeviceId, FocusAddress, SystemName } = route.query; const { DeviceType, DeviceId, FocusAddress, SystemName } = route.query;
@ -75,41 +76,11 @@ const dynamicColumns = ref<any[]>([]);
// - IoTDBTreeModelDeviceDataDto // - IoTDBTreeModelDeviceDataDto
const fixedColumns = [ const fixedColumns = [
{ title: '序号', type: 'seq', width: 50, field: 'seq', slots: {} }, { title: '序号', type: 'seq', width: 50, field: 'seq', slots: {} },
{ { field: 'Timestamps', title: $t('abp.IoTDBBase.Timestamps'), minWidth: 150, showOverflow: true, slots: {} },
field: 'Timestamps', { field: 'FormattedTimestamps', title: $t('abp.IoTDBBase.FormattedTimestamps'), minWidth: 150, showOverflow: true, slots: {} },
title: $t('abp.IoTDBBase.Timestamps'), { field: 'SystemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150, showOverflow: true, slots: {} },
minWidth: 150, { field: 'ProjectId', title: $t('abp.IoTDBBase.ProjectId'), minWidth: 150, showOverflow: true, slots: {} },
showOverflow: true, { field: 'DeviceType', title: $t('abp.IoTDBBase.DeviceType'), minWidth: 150, showOverflow: true, slots: {} },
slots: {},
},
{
field: 'FormattedTimestamps',
title: $t('abp.IoTDBBase.FormattedTimestamps'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{
field: 'SystemName',
title: $t('abp.IoTDBBase.SystemName'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{
field: 'ProjectId',
title: $t('abp.IoTDBBase.ProjectId'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{
field: 'DeviceType',
title: $t('abp.IoTDBBase.DeviceType'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{ {
field: 'IoTDataType', field: 'IoTDataType',
title: $t('abp.IoTDBBase.IoTDataType'), title: $t('abp.IoTDBBase.IoTDataType'),
@ -117,13 +88,7 @@ const fixedColumns = [
showOverflow: true, showOverflow: true,
slots: {}, slots: {},
}, },
{ { field: 'DeviceId', title: $t('abp.IoTDBBase.DeviceId'), minWidth: 150, showOverflow: true, slots: {} },
field: 'DeviceId',
title: $t('abp.IoTDBBase.DeviceId'),
minWidth: 150,
showOverflow: true,
slots: {},
},
]; ];
// - 使 // - 使
@ -137,11 +102,11 @@ const allColumns = computed(() => {
// //
if (dynamicColumns.value && Array.isArray(dynamicColumns.value)) { if (dynamicColumns.value && Array.isArray(dynamicColumns.value)) {
const validDynamicColumns = dynamicColumns.value const validDynamicColumns = dynamicColumns.value.filter(col =>
.filter((col) => col && typeof col === 'object' && col.field && col.title) col && typeof col === 'object' && col.field && col.title
.map((col) => ({ ).map(col => ({
...col, ...col,
slots: col.slots || {}, // slots slots: col.slots || {} // slots
})); }));
columns.push(...validDynamicColumns); columns.push(...validDynamicColumns);
} }
@ -179,11 +144,11 @@ const formOptions: VbenFormProps = {
const relevantFields = new Set([ const relevantFields = new Set([
'DeviceId', 'DeviceId',
'DeviceType', 'DeviceType',
'EndCreationTime',
'FocusAddress', 'FocusAddress',
'IoTDataType', 'IoTDataType',
'StartCreationTime',
'SystemName', 'SystemName',
'StartCreationTime',
'EndCreationTime',
]); ]);
const hasRelevantChange = changedFields.some((field) => const hasRelevantChange = changedFields.some((field) =>
relevantFields.has(field), relevantFields.has(field),
@ -195,21 +160,17 @@ const formOptions: VbenFormProps = {
if (deviceId) { if (deviceId) {
// deviceOptions // deviceOptions
let device = let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
deviceOptions.value.length > 0
? deviceOptions.value.find((d) => d.id === deviceId)
: null;
// DeviceSelect // DeviceSelect
if (!device && gridApi?.formApi) { if (!device && gridApi?.formApi) {
try { try {
// DeviceSelect // DeviceSelect
const deviceSelectRef = const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) { if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
device = deviceSelectRef.getSelectedDevice(); device = deviceSelectRef.getSelectedDevice();
} }
} catch { } catch (error) {
// //
} }
} }
@ -220,15 +181,14 @@ const formOptions: VbenFormProps = {
// //
setTimeout(() => { setTimeout(() => {
try { try {
const deviceSelectRef = const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) { if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
const delayedDevice = deviceSelectRef.getSelectedDevice(); const delayedDevice = deviceSelectRef.getSelectedDevice();
if (delayedDevice) { if (delayedDevice) {
selectedDeviceInfo.value = delayedDevice; selectedDeviceInfo.value = delayedDevice;
} }
} }
} catch { } catch (error) {
// //
} }
}, 100); }, 100);
@ -279,10 +239,7 @@ const gridOptions: VxeGridProps<any> = {
return { items: [], totalCount: 0 }; return { items: [], totalCount: 0 };
} }
// formValuesAPI // formValuesAPI
const currentFormValues = const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
formValues ||
(gridApi?.formApi ? await gridApi.formApi.getValues() : {}) ||
{};
// DeviceTypeIoTDataType // DeviceTypeIoTDataType
const deviceTypeValue = currentFormValues.DeviceType || DeviceType; const deviceTypeValue = currentFormValues.DeviceType || DeviceType;
const deviceTypeNumber = deviceTypeValue const deviceTypeNumber = deviceTypeValue
@ -292,23 +249,15 @@ const gridOptions: VxeGridProps<any> = {
const ioTDataTypeValue = currentFormValues.IoTDataType; const ioTDataTypeValue = currentFormValues.IoTDataType;
// //
const startCreationTime = currentFormValues.StartCreationTime const startCreationTime = currentFormValues.StartCreationTime ? formatDate(currentFormValues.StartCreationTime) : undefined;
? formatDate(currentFormValues.StartCreationTime) const endCreationTime = currentFormValues.EndCreationTime ? formatDate(currentFormValues.EndCreationTime) : undefined;
: undefined;
const endCreationTime = currentFormValues.EndCreationTime
? formatDate(currentFormValues.EndCreationTime)
: undefined;
// DeviceId(10)使focusId // DeviceId(10)使focusId
let finalDeviceId = currentFormValues.DeviceId || DeviceId || ''; let finalDeviceId = currentFormValues.DeviceId || DeviceId || '';
let finalFocusAddress = currentFormValues.FocusAddress || ''; let finalFocusAddress = currentFormValues.FocusAddress || '';
// 使 // 使
const deviceInfo = const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
selectedDeviceInfo.value ||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
? getDeviceInfoById(currentFormValues.DeviceId)
: null);
if (deviceInfo) { if (deviceInfo) {
finalFocusAddress = deviceInfo.focusAddress || ''; finalFocusAddress = deviceInfo.focusAddress || '';
@ -343,6 +292,8 @@ const gridOptions: VxeGridProps<any> = {
}, },
}); });
// 使 // 使
if (data?.items && data.items.length > 0) { if (data?.items && data.items.length > 0) {
try { try {
@ -460,14 +411,14 @@ watch(
() => [DeviceType, DeviceId, FocusAddress, SystemName], () => [DeviceType, DeviceId, FocusAddress, SystemName],
async (newValues, oldValues) => { async (newValues, oldValues) => {
// //
if (newValues.some(Boolean) && gridApi && isGridInitialized.value) { if (newValues.some(val => val) && gridApi && isGridInitialized.value) {
// //
setTimeout(() => { setTimeout(() => {
gridApi.reload(); gridApi.reload();
}, 100); }, 100);
} }
}, },
{ immediate: false }, // false { immediate: false } // false
); );
// //

View File

@ -146,6 +146,11 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
title: $t('abp.IoTDBBase.Timestamps'), title: $t('abp.IoTDBBase.Timestamps'),
minWidth: '150', minWidth: '150',
}, },
{
field: 'FormattedTimestamps',
title: $t('abp.IoTDBBase.FormattedTimestamps'),
minWidth: '150',
},
{ {
field: 'SystemName', field: 'SystemName',
title: $t('abp.IoTDBBase.SystemName'), title: $t('abp.IoTDBBase.SystemName'),

View File

@ -88,21 +88,17 @@ const formOptions: VbenFormProps = {
if (deviceId) { if (deviceId) {
// deviceOptions // deviceOptions
let device = let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
deviceOptions.value.length > 0
? deviceOptions.value.find((d) => d.id === deviceId)
: null;
// DeviceSelect // DeviceSelect
if (!device && gridApi?.formApi) { if (!device && gridApi?.formApi) {
try { try {
// DeviceSelect // DeviceSelect
const deviceSelectRef = const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) { if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
device = deviceSelectRef.getSelectedDevice(); device = deviceSelectRef.getSelectedDevice();
} }
} catch { } catch (error) {
// //
} }
} }
@ -113,15 +109,14 @@ const formOptions: VbenFormProps = {
// //
setTimeout(() => { setTimeout(() => {
try { try {
const deviceSelectRef = const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) { if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
const delayedDevice = deviceSelectRef.getSelectedDevice(); const delayedDevice = deviceSelectRef.getSelectedDevice();
if (delayedDevice) { if (delayedDevice) {
selectedDeviceInfo.value = delayedDevice; selectedDeviceInfo.value = delayedDevice;
} }
} }
} catch { } catch (error) {
// //
} }
}, 100); }, 100);
@ -135,10 +130,10 @@ const formOptions: VbenFormProps = {
const relevantFields = new Set([ const relevantFields = new Set([
'DeviceId', 'DeviceId',
'DeviceType', 'DeviceType',
'EndCreationTime',
'IoTDataType', 'IoTDataType',
'StartCreationTime',
'SystemName', 'SystemName',
'StartCreationTime',
'EndCreationTime',
]); ]);
const hasRelevantChange = changedFields.some((field) => const hasRelevantChange = changedFields.some((field) =>
relevantFields.has(field), relevantFields.has(field),
@ -162,6 +157,7 @@ const gridOptions: VxeGridProps<any> = {
columns: tableSchema.value, columns: tableSchema.value,
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
//
pager: true, pager: true,
pagerConfig: { pagerConfig: {
currentPage: 1, currentPage: 1,
@ -176,8 +172,8 @@ const gridOptions: VxeGridProps<any> = {
proxyConfig: { proxyConfig: {
ajax: { ajax: {
query: async ({ page }, formValues) => { query: async ({ page }, formValues) => {
// API // formValuesAPI
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {}; const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
// //
let deviceId = currentFormValues.DeviceId || ''; let deviceId = currentFormValues.DeviceId || '';
@ -185,14 +181,10 @@ const gridOptions: VxeGridProps<any> = {
const deviceType = currentFormValues.DeviceType || ''; const deviceType = currentFormValues.DeviceType || '';
// 使 // 使
const deviceInfo = const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
selectedDeviceInfo.value ||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
? getDeviceInfoById(currentFormValues.DeviceId)
: null);
if (deviceInfo) { if (deviceInfo) {
systemName = deviceInfo.businessSystemName || ''; systemName = deviceInfo.systemName || '';
// id // id
if (Number(deviceType) === 10) { if (Number(deviceType) === 10) {
// 使 focusId // 使 focusId
@ -259,6 +251,7 @@ watch(
}, },
); );
// //
onMounted(async () => { onMounted(async () => {
await fetchDeviceOptions(); await fetchDeviceOptions();

View File

@ -150,14 +150,6 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
minWidth: '150', minWidth: '150',
slots: {}, slots: {},
}, },
{
field: 'formattedTimestamps',
title: $t('abp.IoTDBBase.FormattedTimestamps'),
minWidth: '150',
formatter: ({ cellValue }) => {
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
},
},
{ {
field: 'systemName', field: 'systemName',
title: $t('abp.IoTDBBase.SystemName'), title: $t('abp.IoTDBBase.SystemName'),