312 lines
8.8 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-22 17:06:15 +08:00
import { getCommonGetSelectList } from '#/api-client';
2025-10-22 15:09:56 +08:00
import { $t } from '#/locales';
export const querySchema = computed(() => [
{
component: 'Input',
fieldName: 'SearchKeyWords',
2025-10-22 17:06:15 +08:00
label: $t('common.SearchKeyWords'),
2025-10-22 15:09:56 +08:00
},
]);
export const tableSchema = computed(() => [
{
field: 'filedType',
2025-10-22 17:06:15 +08:00
title: $t('abp.thingModelInfos.FiledType'),
2025-10-22 15:09:56 +08:00
minWidth: 120,
showOverflow: 'tooltip',
formatter: ({ cellValue }: { cellValue: any }) => {
const typeMap: Record<string, string> = {
2025-10-22 17:06:15 +08:00
Property: '属性',
Service: '服务',
Event: '事件',
2025-10-22 15:09:56 +08:00
};
return typeMap[cellValue] || cellValue;
},
},
{
field: 'ioTPlatformRawFieldName',
2025-10-22 17:06:15 +08:00
title: $t('abp.thingModelInfos.IoTPlatformRawFieldName'),
2025-10-22 15:09:56 +08:00
minWidth: 150,
showOverflow: 'tooltip',
},
{
field: 'standardFieldName',
2025-10-22 17:06:15 +08:00
title: $t('abp.thingModelInfos.StandardFieldName'),
2025-10-22 15:09:56 +08:00
minWidth: 150,
showOverflow: 'tooltip',
},
{
field: 'standardFieldDisplayName',
2025-10-22 17:06:15 +08:00
title: $t('abp.thingModelInfos.StandardFieldDisplayName'),
2025-10-22 15:09:56 +08:00
minWidth: 150,
showOverflow: 'tooltip',
},
{
field: 'standardFieldValueType',
2025-10-22 17:06:15 +08:00
title: $t('abp.thingModelInfos.StandardFieldValueType'),
2025-10-22 15:09:56 +08:00
minWidth: 120,
showOverflow: 'tooltip',
formatter: ({ cellValue }: { cellValue: any }) => {
const typeMap: Record<string, string> = {
2025-10-22 17:06:15 +08:00
String: '字符串',
Int32: '整数',
Int64: '长整数',
Float: '浮点数',
Double: '双精度',
Boolean: '布尔值',
DateTime: '日期时间',
Object: 'JSON对象',
Array: '数组',
2025-10-22 15:09:56 +08:00
};
return typeMap[cellValue] || cellValue;
},
},
{
field: 'isValueNeedConvert',
2025-10-22 17:06:15 +08:00
title: $t('abp.thingModelInfos.IsValueNeedConvert'),
2025-10-22 15:09:56 +08:00
minWidth: 120,
slots: { default: 'isValueNeedConvert' },
},
{
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'),
width: 200,
fixed: 'right',
slots: { default: 'action' },
},
]);
// 添加物模型表单schema
export const addThingModelFormSchema = computed(() => [
{
2025-10-22 17:06:15 +08:00
component: 'ApiSelect',
2025-10-22 15:09:56 +08:00
fieldName: 'filedType',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.FiledType'),
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: {
typeName: 'DataDictionaryTypeConst',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder:
$t('common.pleaseSelect') + $t('abp.thingModelInfos.FiledType'),
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
},
},
{
component: 'Input',
fieldName: 'ioTPlatformRawFieldName',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'),
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
placeholder:
$t('common.pleaseInput') +
$t('abp.thingModelInfos.IoTPlatformRawFieldName'),
2025-10-22 15:09:56 +08:00
},
},
{
2025-10-22 17:06:15 +08:00
component: 'StandardThingModelCodeSelect',
2025-10-22 15:09:56 +08:00
fieldName: 'standardFieldName',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.StandardFieldName'),
rules: z.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
dependencies: {
show(values: any) {
return !!values?.filedType;
},
triggerFields: ['filedType'],
},
2025-10-22 15:09:56 +08:00
componentProps: {
2025-10-22 17:06:15 +08:00
// 传入联动的类型编码
typeCode: (formValues: any) => formValues?.filedType,
placeholder:
$t('common.pleaseSelect') + $t('abp.thingModelInfos.StandardFieldName'),
2025-10-22 15:09:56 +08:00
},
},
{
2025-10-22 17:06:15 +08:00
component: 'ApiSelect',
2025-10-22 15:09:56 +08:00
fieldName: 'standardFieldValueType',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.StandardFieldValueType'),
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: {
typeName: 'StandardThingModelDataTypeEnum',
},
},
labelField: 'value',
valueField: 'secondValue',
optionsPropName: 'options',
immediate: true,
placeholder:
$t('common.pleaseSelect') +
$t('abp.thingModelInfos.StandardFieldValueType'),
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
},
},
{
component: 'Input',
fieldName: 'standardFieldDisplayName',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.StandardFieldDisplayName'),
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
placeholder:
$t('common.pleaseInput') +
$t('abp.thingModelInfos.StandardFieldDisplayName'),
2025-10-22 15:09:56 +08:00
},
},
{
component: 'Switch',
fieldName: 'isValueNeedConvert',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.IsValueNeedConvert'),
2025-10-22 15:09:56 +08:00
defaultValue: false,
2025-10-22 17:06:15 +08:00
componentProps: {
style: { width: 'auto' },
},
2025-10-22 15:09:56 +08:00
},
]);
// 编辑物模型表单schema
export const editThingModelFormSchema = computed(() => [
{
2025-10-22 17:06:15 +08:00
component: 'ApiSelect',
2025-10-22 15:09:56 +08:00
fieldName: 'filedType',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.FiledType'),
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: {
typeName: 'DataDictionaryTypeConst',
},
},
labelField: 'value',
valueField: 'value',
optionsPropName: 'options',
immediate: true,
placeholder: $t('abp.thingModelInfos.PleaseSelectFiledType'),
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
},
},
{
component: 'Input',
fieldName: 'ioTPlatformRawFieldName',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'),
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
placeholder: $t('abp.thingModelInfos.PleaseInputIoTPlatformRawFieldName'),
2025-10-22 15:09:56 +08:00
},
},
{
2025-10-22 17:06:15 +08:00
component: 'StandardThingModelCodeSelect',
2025-10-22 15:09:56 +08:00
fieldName: 'standardFieldName',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.StandardFieldName'),
rules: z.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))),
dependencies: {
show(values: any) {
return !!values?.filedType;
},
triggerFields: ['filedType'],
},
2025-10-22 15:09:56 +08:00
componentProps: {
2025-10-22 17:06:15 +08:00
typeCode: (formValues: any) => formValues?.filedType,
placeholder: $t('abp.thingModelInfos.PleaseSelectStandardFieldName'),
2025-10-22 15:09:56 +08:00
},
},
{
2025-10-22 17:06:15 +08:00
component: 'ApiSelect',
2025-10-22 15:09:56 +08:00
fieldName: 'standardFieldValueType',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.StandardFieldValueType'),
2025-10-22 15:09:56 +08:00
rules: z.string().min(1, $t('common.required')),
componentProps: {
2025-10-22 17:06:15 +08:00
api: getCommonGetSelectList,
params: {
query: {
typeName: 'StandardThingModelDataTypeEnum',
},
},
labelField: 'value',
valueField: 'value',
optionsPropName: 'options',
immediate: true,
placeholder: $t('abp.thingModelInfos.PleaseSelectStandardFieldValueType'),
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
},
},
{
component: 'Input',
fieldName: 'standardFieldDisplayName',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.StandardFieldDisplayName'),
2025-10-22 15:09:56 +08:00
rules: z.string().min(1, $t('common.required')),
componentProps: {
2025-10-22 17:06:15 +08:00
placeholder: $t(
'abp.thingModelInfos.PleaseInputStandardFieldDisplayName',
),
2025-10-22 15:09:56 +08:00
},
},
{
component: 'Switch',
fieldName: 'isValueNeedConvert',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.IsValueNeedConvert'),
componentProps: {
style: { width: 'auto' },
},
2025-10-22 15:09:56 +08:00
},
]);