import { DirectionEnum, DirectionNameEnum, RelationTypeEnum, RelationTypeNameEnum, } from '../../../enum/form'; import { RelatedDeviceAttributeFieldsEnum, RelatedDeviceAttributeFieldsNameEnum, } from '../../../enum/formField/enrichment'; import { getDeviceTypes } from '/@/api/ruleChainDesigner'; import { FormSchema } from '/@/components/Form'; import { useI18n } from '/@/hooks/web/useI18n'; const { t } = useI18n(); export interface ValueType { deviceRelationsQuery: DeviceRelationsQuery; tellFailureIfAbsent: boolean; clientAttributeNames: string[]; sharedAttributeNames: string[]; serverAttributeNames: string[]; latestTsKeyNames: string[]; getLatestValueWithTs: boolean; } export interface DeviceRelationsQuery { fetchLastLevelOnly: boolean; direction: string; maxLevel: number; relationType: string; deviceTypes: string[]; } export const formSchemas: FormSchema[] = [ { field: RelatedDeviceAttributeFieldsEnum.FETCH_LAST_LEVEL_ONLY, component: 'Checkbox', label: '', renderComponentContent: () => ({ default: () => t(RelatedDeviceAttributeFieldsNameEnum.FETCH_LAST_LEVEL_ONLY), }), }, { field: RelatedDeviceAttributeFieldsEnum.DIRECTION, component: 'Select', label: t(RelatedDeviceAttributeFieldsNameEnum.DIRECTION), colProps: { span: 12 }, rules: [ { required: true, message: `请选择${t(RelatedDeviceAttributeFieldsNameEnum.FETCH_LAST_LEVEL_ONLY)}`, }, ], componentProps: { options: Object.keys(DirectionEnum).map((value) => ({ label: DirectionNameEnum[value], value, })), placeholder: `请选择${t(RelatedDeviceAttributeFieldsNameEnum.DIRECTION)}`, getPopupContainer: () => document.body, }, }, { field: RelatedDeviceAttributeFieldsEnum.MAX_LEVEL, component: 'InputNumber', label: t(RelatedDeviceAttributeFieldsNameEnum.MAX_LEVEL), colProps: { span: 12 }, componentProps: { min: 1, placeholder: `请输入${t(RelatedDeviceAttributeFieldsNameEnum.MAX_LEVEL)}`, }, }, { field: RelatedDeviceAttributeFieldsEnum.RELATION_TYPE, component: 'Select', label: t(RelatedDeviceAttributeFieldsNameEnum.RELATION_TYPE), componentProps: { options: Object.keys(RelationTypeEnum).map((value) => ({ label: RelationTypeNameEnum[value], value, })), placeholder: `请选择${t(RelatedDeviceAttributeFieldsNameEnum.RELATION_TYPE)}`, getPopupContainer: () => document.body, }, }, { field: RelatedDeviceAttributeFieldsEnum.DEVICE_TYPES, component: 'ApiSelect', label: t(RelatedDeviceAttributeFieldsNameEnum.DEVICE_TYPES), componentProps: { mode: 'multiple', api: getDeviceTypes, labelField: 'type', valueField: 'type', getPopupContainer: () => document.body, placeholder: `请选择${t(RelatedDeviceAttributeFieldsNameEnum.DEVICE_TYPES)}`, }, }, { field: RelatedDeviceAttributeFieldsEnum.TELL_FAILURE_IF_ABSENT, component: 'Checkbox', label: '', renderComponentContent: () => ({ default: () => t(RelatedDeviceAttributeFieldsNameEnum.TELL_FAILURE_IF_ABSENT), }), }, { field: RelatedDeviceAttributeFieldsEnum.CLIENT_ATTRIBUTE_NAMES, component: 'Select', label: t(RelatedDeviceAttributeFieldsNameEnum.CLIENT_ATTRIBUTE_NAMES), componentProps: { open: false, mode: 'tags', placeholder: t(RelatedDeviceAttributeFieldsNameEnum.CLIENT_ATTRIBUTE_NAMES), }, }, { field: RelatedDeviceAttributeFieldsEnum.SHARED_ATTRIBUTE_NAMES, component: 'Select', label: t(RelatedDeviceAttributeFieldsNameEnum.SHARED_ATTRIBUTE_NAMES), componentProps: { open: false, mode: 'tags', placeholder: t(RelatedDeviceAttributeFieldsNameEnum.SHARED_ATTRIBUTE_NAMES), }, }, { field: RelatedDeviceAttributeFieldsEnum.SERVER_ATTRIBUTE_NAMES, component: 'Select', label: t(RelatedDeviceAttributeFieldsNameEnum.SERVER_ATTRIBUTE_NAMES), componentProps: { open: false, mode: 'tags', placeholder: t(RelatedDeviceAttributeFieldsNameEnum.SERVER_ATTRIBUTE_NAMES), }, }, { field: RelatedDeviceAttributeFieldsEnum.LATEST_TS_KEY_NAMES, component: 'Select', label: t(RelatedDeviceAttributeFieldsNameEnum.LATEST_TS_KEY_NAMES) + '123', componentProps: { open: false, mode: 'tags', placeholder: t(RelatedDeviceAttributeFieldsNameEnum.LATEST_TS_KEY_NAMES), }, }, { field: RelatedDeviceAttributeFieldsEnum.GET_LATEST_VALUE_WITH_TS, component: 'Checkbox', label: '', renderComponentContent: () => ({ default: () => t(RelatedDeviceAttributeFieldsNameEnum.GET_LATEST_VALUE_WITH_TS), }), }, ];