390 lines
10 KiB
TypeScript
Raw Normal View History

2025-10-22 15:09:56 +08:00
import { computed } from 'vue';
import { z } from '@vben/common-ui';
import dayjs from 'dayjs';
2025-10-23 13:54:19 +08:00
import {
getCommonGetSelectList,
2025-12-17 17:04:20 +08:00
postAggregationIoTplatformGetIoTplatformProductInfoAsync,
2025-10-23 13:54:19 +08:00
} from '#/api-client';
2025-10-22 15:09:56 +08:00
import { $t } from '#/locales';
2025-12-17 17:04:20 +08:00
// 查询表单配置
2025-10-22 15:09:56 +08:00
export const querySchema = computed(() => [
2025-12-17 17:04:20 +08:00
{
component: 'ApiSelect',
fieldName: 'ioTPlatform',
label: $t('abp.deviceInfos.ioTPlatform'),
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'IoTPlatformTypeEnum',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder:
$t('common.pleaseSelect') + $t('abp.deviceInfos.ioTPlatform'),
afterFetch: (res: any) => {
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
return [];
},
},
},
{
component: 'ApiSelect',
fieldName: 'ioTPlatformProductId',
label: $t('common.BelongingProductName'),
dependencies: {
show(values: any) {
return !!values.ioTPlatform;
},
triggerFields: ['ioTPlatform'],
},
componentProps: (formValues: any) => {
const platform = formValues?.ioTPlatform;
return {
api: platform
? postAggregationIoTplatformGetIoTplatformProductInfoAsync
: null,
// 聚合服务要求 JSON Body 传参
params: {
body: {
ioTPlatformType:
typeof platform === 'string'
? Number.parseInt(platform)
: platform,
},
},
labelField: 'productName',
valueField: 'ioTPlatformProductId',
optionsPropName: 'options',
immediate: false,
allowClear: true,
placeholder:
$t('common.pleaseSelect') + $t('common.BelongingProductName'),
afterFetch: (res: any) => {
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
if (res && res.data && Array.isArray(res.data.items)) {
return res.data.items;
}
return [];
},
};
},
},
2025-10-22 15:09:56 +08:00
{
component: 'Input',
fieldName: 'SearchKeyWords',
2025-10-22 17:06:15 +08:00
label: $t('common.SearchKeyWords'),
2025-10-22 15:09:56 +08:00
},
]);
2025-12-17 17:04:20 +08:00
// 列表列配置
2025-10-22 15:09:56 +08:00
export const tableSchema = computed(() => [
{
2025-12-17 17:04:20 +08:00
field: 'deviceModelName',
title: '设备端物模型名称',
minWidth: 180,
showOverflow: 'tooltip',
},
{
field: 'ioTPlatform',
title: $t('abp.deviceInfos.ioTPlatform'),
2025-10-22 15:09:56 +08:00
minWidth: 120,
showOverflow: 'tooltip',
formatter: ({ cellValue }: { cellValue: any }) => {
2025-12-17 17:04:20 +08:00
const map: Record<string | number, string> = {
1: 'CTWing',
2: 'OneNET',
2025-10-22 15:09:56 +08:00
};
2025-12-17 17:04:20 +08:00
return map[cellValue] || cellValue || '-';
2025-10-22 15:09:56 +08:00
},
},
{
2025-12-17 17:04:20 +08:00
field: 'ioTPlatformProductId',
title: '平台产品ID',
minWidth: 160,
2025-10-22 15:09:56 +08:00
showOverflow: 'tooltip',
},
{
2025-12-17 17:04:20 +08:00
field: 'scriptName',
title: '脚本函数名称',
minWidth: 160,
2025-10-22 15:09:56 +08:00
showOverflow: 'tooltip',
},
{
2025-12-17 17:04:20 +08:00
field: 'functionAnalysisFlag',
title: '解析启用',
minWidth: 100,
slots: { default: 'functionAnalysisFlag' },
2025-10-22 15:09:56 +08:00
},
{
field: 'creationTime',
title: $t('common.creationTime'),
minWidth: 180,
formatter: ({ cellValue }: { cellValue: any }) => {
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
},
},
{
field: 'action',
title: $t('common.action'),
2025-12-19 15:45:19 +08:00
width: 360,
2025-10-22 15:09:56 +08:00
fixed: 'right',
slots: { default: 'action' },
},
]);
2025-12-17 17:04:20 +08:00
// 新增设备端物模型表单
export const addDeviceThingModelFormSchema = computed(() => [
{
component: 'Input',
fieldName: 'deviceModelName',
label: '设备端物模型名称',
rules: z
.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
componentProps: {
placeholder: $t('common.pleaseInput') + '设备端物模型名称',
},
},
2025-10-22 15:09:56 +08:00
{
2025-10-22 17:06:15 +08:00
component: 'ApiSelect',
2025-12-17 17:04:20 +08:00
fieldName: 'ioTPlatform',
label: $t('abp.deviceInfos.ioTPlatform'),
rules: z
.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
2025-10-22 15:09:56 +08:00
componentProps: {
2025-10-22 17:06:15 +08:00
api: getCommonGetSelectList,
params: {
query: {
2025-12-17 17:04:20 +08:00
typeName: 'IoTPlatformTypeEnum',
2025-10-22 17:06:15 +08:00
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder:
2025-12-17 17:04:20 +08:00
$t('common.pleaseSelect') + $t('abp.deviceInfos.ioTPlatform'),
2025-10-22 17:06:15 +08:00
afterFetch: (res: any) => {
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
return [];
},
2025-10-22 15:09:56 +08:00
},
},
{
2025-12-17 17:04:20 +08:00
component: 'ApiSelect',
fieldName: 'ioTPlatformProductId',
label: $t('common.BelongingProductName'),
rules: z
.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
componentProps: (formValues: any) => {
const platform = formValues?.ioTPlatform;
return {
api: platform
? postAggregationIoTplatformGetIoTplatformProductInfoAsync
: null,
params: {
body: {
ioTPlatformType:
typeof platform === 'string'
? Number.parseInt(platform)
: platform,
},
},
labelField: 'productName',
valueField: 'ioTPlatformProductId',
optionsPropName: 'options',
immediate: false,
allowClear: true,
placeholder:
$t('common.pleaseSelect') + $t('common.BelongingProductName'),
afterFetch: (res: any) => {
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
if (res && res.data && Array.isArray(res.data.items)) {
return res.data.items;
}
return [];
},
};
2025-10-22 15:09:56 +08:00
},
},
2025-10-23 09:37:23 +08:00
{
component: 'Input',
2025-12-17 17:04:20 +08:00
fieldName: 'scriptName',
label: '脚本函数名称',
rules: z
.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
2025-10-23 09:37:23 +08:00
componentProps: {
2025-12-17 17:04:20 +08:00
placeholder: $t('common.pleaseInput') + '脚本函数名称',
2025-10-23 09:37:23 +08:00
},
},
2025-10-22 15:09:56 +08:00
{
2025-12-17 17:04:20 +08:00
component: 'Textarea',
fieldName: 'functionScript',
label: '脚本函数体',
2025-10-22 15:09:56 +08:00
componentProps: {
2025-12-17 17:04:20 +08:00
rows: 6,
placeholder: '请输入脚本函数体用于解析MODBUS设备数据',
2025-10-22 15:09:56 +08:00
},
2025-10-23 13:54:19 +08:00
},
2025-12-17 17:04:20 +08:00
]);
// 编辑设备端物模型表单
export const editDeviceThingModelFormSchema = computed(() => [
2025-10-22 15:09:56 +08:00
{
2025-12-17 17:04:20 +08:00
component: 'Input',
fieldName: 'deviceModelName',
label: '设备端物模型名称',
rules: z
.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
2025-10-22 17:06:15 +08:00
componentProps: {
2025-12-17 17:04:20 +08:00
placeholder: $t('common.pleaseInput') + '设备端物模型名称',
2025-10-22 17:06:15 +08:00
},
2025-10-22 15:09:56 +08:00
},
{
2025-10-22 17:06:15 +08:00
component: 'ApiSelect',
2025-12-17 17:04:20 +08:00
fieldName: 'ioTPlatform',
label: $t('abp.deviceInfos.ioTPlatform'),
rules: z
.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
2025-10-22 15:09:56 +08:00
componentProps: {
2025-10-22 17:06:15 +08:00
api: getCommonGetSelectList,
params: {
query: {
2025-12-17 17:04:20 +08:00
typeName: 'IoTPlatformTypeEnum',
2025-10-22 17:06:15 +08:00
},
},
labelField: 'value',
2025-10-23 09:37:23 +08:00
valueField: 'key',
2025-10-22 17:06:15 +08:00
optionsPropName: 'options',
immediate: true,
2025-12-17 17:04:20 +08:00
allowClear: true,
disabled: true, // 编辑时不允许修改平台
2025-10-23 13:54:19 +08:00
placeholder:
2025-12-17 17:04:20 +08:00
$t('common.pleaseSelect') + $t('abp.deviceInfos.ioTPlatform'),
2025-10-22 17:06:15 +08:00
afterFetch: (res: any) => {
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
return [];
},
2025-10-22 15:09:56 +08:00
},
},
{
2025-10-22 17:06:15 +08:00
component: 'ApiSelect',
2025-12-17 17:04:20 +08:00
fieldName: 'ioTPlatformProductId',
label: $t('common.BelongingProductName'),
rules: z
.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
componentProps: (formValues: any) => {
const platform = formValues?.ioTPlatform;
return {
api: platform
? postAggregationIoTplatformGetIoTplatformProductInfoAsync
: null,
params: {
body: {
ioTPlatformType:
typeof platform === 'string'
? Number.parseInt(platform)
: platform,
},
2025-10-22 17:06:15 +08:00
},
2025-12-17 17:04:20 +08:00
labelField: 'productName',
valueField: 'ioTPlatformProductId',
optionsPropName: 'options',
immediate: false,
allowClear: true,
disabled: true, // 编辑时不允许修改平台产品
placeholder:
$t('common.pleaseSelect') + $t('common.BelongingProductName'),
afterFetch: (res: any) => {
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
if (res && res.data && Array.isArray(res.data.items)) {
return res.data.items;
}
return [];
},
};
2025-10-22 15:09:56 +08:00
},
2025-10-23 13:54:19 +08:00
},
2025-10-22 15:09:56 +08:00
{
2025-12-17 17:04:20 +08:00
component: 'Input',
fieldName: 'scriptName',
label: '脚本函数名称',
rules: z
.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
2025-10-22 17:06:15 +08:00
componentProps: {
2025-12-17 17:04:20 +08:00
placeholder: $t('common.pleaseInput') + '脚本函数名称',
2025-10-22 17:06:15 +08:00
},
2025-10-22 15:09:56 +08:00
},
2025-10-23 11:48:10 +08:00
{
2025-12-17 17:04:20 +08:00
component: 'Textarea',
fieldName: 'functionScript',
label: '脚本函数体',
2025-10-23 11:48:10 +08:00
componentProps: {
2025-12-17 17:04:20 +08:00
rows: 6,
placeholder: '请输入脚本函数体用于解析MODBUS设备数据',
2025-10-23 11:48:10 +08:00
},
},
]);
2025-12-17 17:04:20 +08:00