442 lines
12 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 11:48:10 +08:00
import { getCommonGetSelectList, postOneNetProductListAsync } 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'),
2025-10-22 17:29:07 +08:00
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'),
2025-10-22 17:29:07 +08:00
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-23 09:37:23 +08:00
fieldName: 'standardFieldDisplayName',
label: $t('abp.thingModelInfos.StandardFieldDisplayName'),
2025-10-22 17:29:07 +08:00
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, $t('common.required')),
),
componentProps: (formValues: any) => ({
// 传入联动的类型编码(运行时具体值)
typeCode: formValues?.filedType ?? null,
onResolve: (item: any | null) => {
// 选择后自动回填:名称=displayText值类型=extendedAttribute(转大写)
2025-10-23 09:37:23 +08:00
formValues.standardFieldName = item?.code ?? '';
2025-10-22 17:29:07 +08:00
formValues.standardFieldValueType = (item?.extendedAttribute ?? '')
.toString()
.toUpperCase();
},
2025-10-22 17:06:15 +08:00
placeholder:
$t('common.pleaseSelect') + $t('abp.thingModelInfos.StandardFieldName'),
2025-10-22 17:29:07 +08:00
}),
2025-10-22 15:09:56 +08:00
},
2025-10-23 09:37:23 +08:00
{
component: 'Input',
fieldName: 'standardFieldName',
label: $t('abp.thingModelInfos.StandardFieldName'),
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, $t('common.required')),
),
componentProps: {
placeholder:
$t('common.pleaseInput') +
$t('abp.thingModelInfos.StandardFieldDisplayName'),
},
},
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 17:29:07 +08:00
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,
2025-10-22 17:29:07 +08:00
allowClear: true,
2025-10-22 17:06:15 +08:00
placeholder:
$t('common.pleaseSelect') +
$t('abp.thingModelInfos.StandardFieldValueType'),
afterFetch: (res: any) => {
2025-10-22 17:29:07 +08:00
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
2025-10-22 17:06:15 +08:00
return [];
},
2025-10-22 15:09:56 +08:00
},
2025-10-23 09:37:23 +08:00
},
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'),
2025-10-22 17:29:07 +08:00
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',
2025-10-23 09:37:23 +08:00
valueField: 'key',
2025-10-22 17:06:15 +08:00
optionsPropName: 'options',
immediate: true,
2025-10-23 09:37:23 +08:00
disabled: true, // 编辑时禁用
placeholder: $t('common.pleaseSelect') + $t('abp.thingModelInfos.FiledType'),
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
},
},
{
component: 'Input',
fieldName: 'ioTPlatformRawFieldName',
2025-10-22 17:06:15 +08:00
label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'),
2025-10-22 17:29:07 +08:00
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-23 09:37:23 +08:00
// disabled: true, // 编辑时禁用
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-23 09:37:23 +08:00
fieldName: 'standardFieldDisplayName',
label: $t('abp.thingModelInfos.StandardFieldDisplayName'),
2025-10-22 17:29:07 +08:00
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, $t('common.required')),
),
componentProps: (formValues: any) => ({
typeCode: formValues?.filedType ?? null,
2025-10-23 09:37:23 +08:00
disabled: true, // 编辑时禁用
2025-10-22 17:29:07 +08:00
onResolve: (item: any | null) => {
2025-10-23 09:37:23 +08:00
formValues.standardFieldDisplayName = item?.code ?? '';
2025-10-22 17:29:07 +08:00
formValues.standardFieldValueType = (item?.extendedAttribute ?? '')
.toString()
.toUpperCase();
},
2025-10-23 09:37:23 +08:00
placeholder: $t('common.pleaseInput') + $t('abp.thingModelInfos.StandardFieldDisplayName'),
2025-10-22 17:29:07 +08:00
}),
2025-10-22 15:09:56 +08:00
},
2025-10-23 09:37:23 +08:00
{
component: 'Input',
fieldName: 'standardFieldName',
label: $t('abp.thingModelInfos.StandardFieldName'),
rules: z.string().min(1, $t('common.required')),
componentProps: {
disabled: true, // 编辑时禁用
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'),
2025-10-23 09:37:23 +08:00
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',
},
},
optionsPropName: 'options',
immediate: true,
2025-10-23 09:37:23 +08:00
allowClear: true,
disabled: true, // 编辑时禁用
placeholder: $t('common.pleaseSelect') +
$t('abp.thingModelInfos.StandardFieldValueType'),
2025-10-22 17:06:15 +08:00
afterFetch: (res: any) => {
2025-10-23 09:37:23 +08:00
let items = [];
if (Array.isArray(res)) {
items = res;
} else if (res && Array.isArray(res.items)) {
items = res.items;
} else if (res && Array.isArray(res.data)) {
items = res.data;
}
// 转换选项值以匹配列表中的小写值
return items.map((item: any) => ({
...item,
// 使用secondValue的小写版本作为value保持label为原始value
value: item.secondValue?.toLowerCase() || item.value?.toLowerCase(),
label: item.value, // 显示文本
}));
2025-10-22 17:06:15 +08:00
},
2025-10-22 15:09:56 +08:00
},
2025-10-23 09:37:23 +08:00
},
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
},
]);
2025-10-23 11:48:10 +08:00
// 复制已有模型表单schema
export const copyThingModelFormSchema = computed(() => [
{
component: 'ApiSelect',
fieldName: 'sourceProductId',
label: '选择要复制的产品',
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, '请选择要复制的产品'),
),
componentProps: {
api: postOneNetProductListAsync,
params: {
query: {
input: {
pageIndex: 1,
pageSize: 1000,
},
},
},
labelField: 'productName',
valueField: 'ioTPlatformProductId',
optionsPropName: 'items',
immediate: true,
allowClear: true,
placeholder: '请选择产品',
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: 'filedType',
label: '选择物模型类型',
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, '请选择物模型类型'),
),
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'DataDictionaryTypeConst',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: '请选择物模型类型',
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 [];
},
},
},
]);