232 lines
6.2 KiB
TypeScript
Raw Normal View History

2025-06-25 17:29:57 +08:00
import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed } from 'vue';
2025-06-25 17:29:57 +08:00
2025-07-11 15:46:31 +08:00
import {
getSelectResultList,
postFocusesPage,
postMetersPage,
} from '#/api-client';
2025-06-25 17:29:57 +08:00
import { $t } from '#/locales';
export const querySchema = computed(() => [
2025-07-09 17:07:25 +08:00
{
component: 'ApiSelect',
2025-07-09 17:07:25 +08:00
fieldName: 'SystemName',
label: $t('abp.IoTDBBase.SystemName'),
componentProps: {
api: getSelectResultList,
params: {
query: {
TypeName: 'BusinessSystemEnum',
},
},
labelField: 'secondValue',
valueField: 'value',
optionsPropName: 'options',
immediate: true,
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
// 如果是包装在 items 中的,提取出来
if (res && Array.isArray(res.items)) {
return res.items;
}
// 如果是包装在 data 中的,提取出来
if (res && Array.isArray(res.data)) {
return res.data;
}
// 如果都不是,返回空数组
return [];
},
},
2025-07-09 17:07:25 +08:00
},
2025-07-10 10:28:06 +08:00
{
2025-07-11 15:46:31 +08:00
component: 'ApiSelect',
fieldName: 'DeviceType',
label: $t('abp.IoTDBBase.DeviceType'),
componentProps: {
api: getSelectResultList,
params: {
query: {
TypeName: 'MeterTypeEnum',
},
},
labelField: 'secondValue',
valueField: 'value',
optionsPropName: 'options',
immediate: true,
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
// 如果是包装在 items 中的,提取出来
if (res && Array.isArray(res.items)) {
return res.items;
}
// 如果是包装在 data 中的,提取出来
if (res && Array.isArray(res.data)) {
return res.data;
}
// 如果都不是,返回空数组
return [];
},
},
},
{
component: 'ApiSelect',
fieldName: 'IoTDataType',
label: $t('abp.IoTDBBase.IoTDataType'),
componentProps: {
api: getSelectResultList,
params: {
query: {
TypeName: 'IoTDBDataTypeConst',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
// 如果是包装在 items 中的,提取出来
if (res && Array.isArray(res.items)) {
return res.items;
}
// 如果是包装在 data 中的,提取出来
if (res && Array.isArray(res.data)) {
return res.data;
}
// 如果都不是,返回空数组
return [];
},
},
},
{
component: 'ApiSelect',
2025-07-10 10:28:06 +08:00
fieldName: 'FocusAddress',
label: $t('abp.focus.focusAddress'),
2025-07-11 15:46:31 +08:00
componentProps: {
api: postFocusesPage,
params: {
body: {
pageIndex: 1,
pageSize: 1000, // 获取足够多的数据用于下拉选择
},
},
labelField: 'name',
valueField: 'focusAddress',
optionsPropName: 'options',
immediate: true,
showSearch: true,
allowClear: true,
placeholder: $t('common.pleaseSelect') + $t('abp.focus.focusAddress'),
filterOption: false, // 禁用本地过滤,使用服务端搜索
optionFilterProp: 'label', // 根据 label 进行过滤
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
// 如果是包装在 items 中的,提取出来
if (res && Array.isArray(res.items)) {
return res.items;
}
// 如果是包装在 data 中的,提取出来
if (res && Array.isArray(res.data)) {
return res.data;
}
// 如果是包装在 data.items 中的,提取出来
if (res && res.data && Array.isArray(res.data.items)) {
return res.data.items;
}
// 如果都不是,返回空数组
return [];
},
},
},
{
component: 'ApiSelect',
fieldName: 'DeviceId',
label: $t('abp.log.deviceInfo'),
componentProps: {
api: postMetersPage,
params: {
body: {
pageIndex: 1,
pageSize: 1000, // 获取足够多的数据用于下拉选择
},
},
labelField: 'name',
valueField: 'focusAddress',
optionsPropName: 'options',
immediate: true,
showSearch: true,
allowClear: true,
placeholder: $t('common.pleaseSelect') + $t('abp.log.deviceInfo'),
filterOption: false, // 禁用本地过滤,使用服务端搜索
optionFilterProp: 'label', // 根据 label 进行过滤
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
// 如果是包装在 items 中的,提取出来
if (res && Array.isArray(res.items)) {
return res.items;
}
// 如果是包装在 data 中的,提取出来
if (res && Array.isArray(res.data)) {
return res.data;
}
// 如果是包装在 data.items 中的,提取出来
if (res && res.data && Array.isArray(res.data.items)) {
return res.data.items;
}
// 如果都不是,返回空数组
return [];
},
},
2025-07-10 10:28:06 +08:00
},
2025-06-25 17:29:57 +08:00
]);
export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 },
{
2025-07-10 10:28:06 +08:00
field: 'Timestamps',
title: $t('abp.IoTDBBase.Timestamps'),
2025-07-11 15:46:31 +08:00
minWidth: '150',
},
{
field: 'SystemName',
title: $t('abp.IoTDBBase.SystemName'),
minWidth: '150',
2025-06-25 17:29:57 +08:00
},
{
2025-07-10 10:28:06 +08:00
field: 'ProjectId',
title: $t('abp.IoTDBBase.ProjectId'),
2025-06-25 17:29:57 +08:00
minWidth: '150',
2025-07-11 15:46:31 +08:00
},
2025-06-25 17:29:57 +08:00
{
2025-07-10 10:28:06 +08:00
field: 'DeviceType',
title: $t('abp.IoTDBBase.DeviceType'),
2025-06-25 17:29:57 +08:00
minWidth: '150',
},
{
2025-07-10 10:28:06 +08:00
field: 'IoTDataType',
title: $t('abp.IoTDBBase.IoTDataType'),
2025-06-25 17:29:57 +08:00
minWidth: '150',
2025-07-11 15:46:31 +08:00
},
2025-07-10 10:28:06 +08:00
{
field: 'DeviceId',
title: $t('abp.IoTDBBase.DeviceId'),
minWidth: '150',
2025-07-11 15:46:31 +08:00
},
2025-06-25 17:29:57 +08:00
]);