import { computed } from 'vue'; import { z } from '@vben/common-ui'; import dayjs from 'dayjs'; import { getCommonGetSelectList, postOneNetProductListAsync, } 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: 'standardFieldDisplayName', label: $t('abp.thingModelInfos.StandardFieldDisplayName'), 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(转大写) formValues.standardFieldName = item?.code ?? ''; formValues.standardFieldValueType = (item?.extendedAttribute ?? '') .toString() .toUpperCase(); }, placeholder: $t('common.pleaseSelect') + $t('abp.thingModelInfos.StandardFieldName'), }), }, { 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'), }, }, { 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, allowClear: 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: '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: 'key', optionsPropName: 'options', immediate: true, disabled: 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: { // disabled: true, // 编辑时禁用 placeholder: $t('common.pleaseInput') + $t('abp.thingModelInfos.IoTPlatformRawFieldName'), }, }, { component: 'StandardThingModelCodeSelect', fieldName: 'standardFieldDisplayName', label: $t('abp.thingModelInfos.StandardFieldDisplayName'), rules: z.preprocess( (v) => (v == null ? '' : v), z.string().min(1, $t('common.required')), ), componentProps: (formValues: any) => ({ typeCode: formValues?.filedType ?? null, disabled: true, // 编辑时禁用 onResolve: (item: any | null) => { formValues.standardFieldDisplayName = item?.code ?? ''; formValues.standardFieldValueType = (item?.extendedAttribute ?? '') .toString() .toUpperCase(); }, placeholder: $t('common.pleaseInput') + $t('abp.thingModelInfos.StandardFieldDisplayName'), }), }, { 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'), }, }, { 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', }, }, optionsPropName: 'options', immediate: true, allowClear: true, disabled: true, // 编辑时禁用 placeholder: $t('common.pleaseSelect') + $t('abp.thingModelInfos.StandardFieldValueType'), afterFetch: (res: any) => { 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 || item.value, label: item.value, // 显示文本 })); }, }, }, { component: 'Switch', fieldName: 'isValueNeedConvert', label: $t('abp.thingModelInfos.IsValueNeedConvert'), componentProps: { style: { width: 'auto' }, }, }, ]); // 复制已有模型表单schema export const copyThingModelFormSchema = computed(() => [ { component: 'ApiSelect', fieldName: 'ioTPlatformProductId', label: '选择要复制的产品', rules: z.preprocess( (v) => (v == null ? '' : v), z.string().min(1, '请选择要复制的产品'), ), componentProps: { api: postOneNetProductListAsync, params: { query: { pageIndex: 1, pageSize: 1000, }, }, labelField: 'productName', valueField: 'ioTPlatformProductId', 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; } if (res && Array.isArray(res.data.items)) { return res.data.items; } return []; }, }, }, ]);