import { computed } from 'vue'; import { z } from '@vben/common-ui'; import dayjs from 'dayjs'; import { getCommonGetSelectList } from '#/api-client'; import { $t } from '#/locales'; export const querySchema = computed(() => [ { component: 'Input', fieldName: 'SearchKeyWords', label: $t('common.SearchKeyWords'), }, ]); export const tableSchema = computed(() => [ { field: 'filedType', title: $t('abp.thingModelInfos.FiledType'), minWidth: 120, showOverflow: 'tooltip', formatter: ({ cellValue }: { cellValue: any }) => { const typeMap: Record = { Property: '属性', Service: '服务', Event: '事件', }; return typeMap[cellValue] || cellValue; }, }, { field: 'ioTPlatformRawFieldName', title: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), minWidth: 150, showOverflow: 'tooltip', }, { field: 'standardFieldName', title: $t('abp.thingModelInfos.StandardFieldName'), minWidth: 150, showOverflow: 'tooltip', }, { field: 'standardFieldDisplayName', title: $t('abp.thingModelInfos.StandardFieldDisplayName'), minWidth: 150, showOverflow: 'tooltip', }, { field: 'standardFieldValueType', title: $t('abp.thingModelInfos.StandardFieldValueType'), minWidth: 120, showOverflow: 'tooltip', formatter: ({ cellValue }: { cellValue: any }) => { const typeMap: Record = { String: '字符串', Int32: '整数', Int64: '长整数', Float: '浮点数', Double: '双精度', Boolean: '布尔值', DateTime: '日期时间', Object: 'JSON对象', Array: '数组', }; return typeMap[cellValue] || cellValue; }, }, { field: 'isValueNeedConvert', title: $t('abp.thingModelInfos.IsValueNeedConvert'), 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(() => [ { component: 'ApiSelect', fieldName: 'filedType', label: $t('abp.thingModelInfos.FiledType'), rules: z.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), componentProps: { 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 []; }, }, }, { component: 'Input', fieldName: 'ioTPlatformRawFieldName', label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), rules: z.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), componentProps: { placeholder: $t('common.pleaseInput') + $t('abp.thingModelInfos.IoTPlatformRawFieldName'), }, }, { component: 'StandardThingModelCodeSelect', fieldName: 'standardFieldName', 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'], }, componentProps: { // 传入联动的类型编码 typeCode: (formValues: any) => formValues?.filedType, placeholder: $t('common.pleaseSelect') + $t('abp.thingModelInfos.StandardFieldName'), }, }, { component: 'ApiSelect', fieldName: 'standardFieldValueType', label: $t('abp.thingModelInfos.StandardFieldValueType'), rules: z.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), componentProps: { 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 []; }, }, }, { component: 'Input', fieldName: 'standardFieldDisplayName', label: $t('abp.thingModelInfos.StandardFieldDisplayName'), rules: z.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), componentProps: { placeholder: $t('common.pleaseInput') + $t('abp.thingModelInfos.StandardFieldDisplayName'), }, }, { component: 'Switch', fieldName: 'isValueNeedConvert', label: $t('abp.thingModelInfos.IsValueNeedConvert'), defaultValue: false, componentProps: { style: { width: 'auto' }, }, }, ]); // 编辑物模型表单schema export const editThingModelFormSchema = computed(() => [ { component: 'ApiSelect', fieldName: 'filedType', label: $t('abp.thingModelInfos.FiledType'), rules: z.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), componentProps: { 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 []; }, }, }, { component: 'Input', fieldName: 'ioTPlatformRawFieldName', label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), rules: z.preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), componentProps: { placeholder: $t('abp.thingModelInfos.PleaseInputIoTPlatformRawFieldName'), }, }, { component: 'StandardThingModelCodeSelect', fieldName: 'standardFieldName', 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'], }, componentProps: { typeCode: (formValues: any) => formValues?.filedType, placeholder: $t('abp.thingModelInfos.PleaseSelectStandardFieldName'), }, }, { component: 'ApiSelect', fieldName: 'standardFieldValueType', label: $t('abp.thingModelInfos.StandardFieldValueType'), rules: z.string().min(1, $t('common.required')), componentProps: { 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 []; }, }, }, { component: 'Input', fieldName: 'standardFieldDisplayName', label: $t('abp.thingModelInfos.StandardFieldDisplayName'), rules: z.string().min(1, $t('common.required')), componentProps: { placeholder: $t( 'abp.thingModelInfos.PleaseInputStandardFieldDisplayName', ), }, }, { component: 'Switch', fieldName: 'isValueNeedConvert', label: $t('abp.thingModelInfos.IsValueNeedConvert'), componentProps: { style: { width: 'auto' }, }, }, ]);