设备绑定设备端物模型

This commit is contained in:
ChenYi 2025-12-22 17:28:38 +08:00
parent ba5a5ee8f4
commit e860a539fa
8 changed files with 651 additions and 28 deletions

View File

@ -464,6 +464,29 @@ export const BatchCreateDeviceAggregationInputSchema = {
description: '批量创建设备信息'
} as const;
export const BindingDeviceThingModelInputSchema = {
type: 'object',
properties: {
devieDataId: {
type: 'string',
description: '设备数据Id',
format: 'uuid'
},
isNeedConfigDevicMdoel: {
type: 'boolean',
description: '是否需要配置设备模型默认false'
},
deviceThingModelDataId: {
type: 'string',
description: '设备物模型数据Id',
format: 'uuid',
nullable: true
}
},
additionalProperties: false,
description: '绑定设备物模型输入'
} as const;
export const BuildAnalysisScriptInputSchema = {
type: 'object',
properties: {
@ -5390,6 +5413,11 @@ export const IoTPlatformThingModelInfoDtoSchema = {
description: '物联网平台中对应的产品物模型属性或者事件名称',
nullable: true
},
ioTPlatformRawFieldDataType: {
type: 'string',
description: '物联网平台中对应的产品物模型属性或者事件数据类型int等JiShe.ServicePro.Core.OneNETAllThingModel',
nullable: true
},
standardFieldName: {
type: 'string',
description: '管理后台产品标准的物模型属性或者事件名称',

File diff suppressed because one or more lines are too long

View File

@ -172,6 +172,24 @@ export type BatchCreateDeviceAggregationInput = {
deviceSourceTypeEnum?: DeviceSourceTypeEnum;
};
/**
*
*/
export type BindingDeviceThingModelInput = {
/**
* Id
*/
devieDataId?: string;
/**
* false
*/
isNeedConfigDevicMdoel?: boolean;
/**
* Id
*/
deviceThingModelDataId?: (string) | null;
};
/**
*
*/
@ -2706,6 +2724,10 @@ export type IoTPlatformThingModelInfoDto = {
*
*/
ioTPlatformRawFieldName?: (string) | null;
/**
* int等JiShe.ServicePro.Core.OneNETAllThingModel
*/
ioTPlatformRawFieldDataType?: (string) | null;
/**
*
*/
@ -5947,6 +5969,16 @@ export type PostDeviceInfoCacheDeviceDataToRedisResponse = (boolean);
export type PostDeviceInfoCacheDeviceDataToRedisError = unknown;
export type PostDeviceInfoBindingDeviceThingModelData = {
query?: {
input?: BindingDeviceThingModelInput;
};
};
export type PostDeviceInfoBindingDeviceThingModelResponse = (boolean);
export type PostDeviceInfoBindingDeviceThingModelError = unknown;
export type PostDeviceThingModelManagementCreateAsyncData = {
query?: {
input?: DeviceThingModelCreateInput;

View File

@ -25,6 +25,7 @@ import {
postAggregationDeviceDeviceCommandForApiAsync,
postAggregationDeviceRepushDeviceInfoToIoTplatform,
postDeviceInfoCacheDeviceDataToRedis,
postDeviceInfoBindingDeviceThingModel,
postDeviceInfoPage,
} from '#/api-client';
import { Icon } from '#/components/icon';
@ -38,6 +39,7 @@ import {
batchAddDeviceFormSchema,
commandFormSchema,
editDeviceFormSchemaEdit,
bindDeviceThingModelFormSchema,
querySchema,
tableSchema,
} from './schema';
@ -162,6 +164,9 @@ const pageLoading = ref(false);
const loadingTip = ref('缓存刷新中...');
const commandRow: Record<string, any> = ref({});
//
const bindRow: Record<string, any> = ref({});
// -
interface CommandProperty {
id: string; //
@ -264,6 +269,16 @@ const [CommandModal, commandModalApi] = useVbenModal({
},
});
//
const [BindModal, bindModalApi] = useVbenModal({
draggable: true,
onConfirm: submitBindDeviceThingModel,
onBeforeClose: () => {
bindRow.value = {};
return true;
},
});
const [AddForm, addFormApi] = useVbenForm({
//
collapsed: false,
@ -315,6 +330,21 @@ const [CommandForm, commandFormApi] = useVbenForm({
showDefaultActions: false,
});
const [BindForm, bindFormApi] = useVbenForm({
collapsed: false,
commonConfig: {
labelWidth: 160,
componentProps: {
class: 'w-full',
},
},
layout: 'horizontal',
schema: bindDeviceThingModelFormSchema.value,
showCollapseButton: false,
showDefaultActions: false,
wrapperClass: 'grid-cols-1',
});
const [BatchAddForm, batchAddFormApi] = useVbenForm({
//
collapsed: false,
@ -555,6 +585,19 @@ const openCommandModal = (row: Record<string, any>) => {
commandModalApi.open();
};
//
const openBindModal = async (row: Record<string, any>) => {
bindRow.value = row;
bindModalApi.open();
// 使ID
await nextTick();
await bindFormApi.setValues({
isNeedConfigDevicMdoel: false,
deviceThingModelDataId: undefined,
_ioTPlatformProductId: row.ioTPlatformProductId,
});
};
//
async function submitCommand() {
// -
@ -629,6 +672,54 @@ async function submitCommand() {
}
}
//
async function submitBindDeviceThingModel() {
const formValues = await bindFormApi.getValues();
//
const isNeedConfig = !!formValues.isNeedConfigDevicMdoel;
const deviceThingModelDataId = formValues.deviceThingModelDataId as
| string
| undefined;
if (isNeedConfig && !deviceThingModelDataId) {
Message.error('请先选择设备端物模型');
return;
}
if (!bindRow.value?.id) {
Message.error('设备信息缺失,无法绑定设备端物模型');
return;
}
try {
bindModalApi.setState({ loading: true, confirmLoading: true });
const result = await postDeviceInfoBindingDeviceThingModel({
query: {
input: {
devieDataId: bindRow.value.id,
isNeedConfigDevicMdoel: isNeedConfig,
deviceThingModelDataId: isNeedConfig ? deviceThingModelDataId : null,
},
},
});
if (result) {
Message.success('绑定设备端物模型成功');
bindModalApi.close();
bindRow.value = {};
gridApi.reload();
} else {
Message.error('绑定设备端物模型失败');
}
} catch (error) {
console.error('绑定设备端物模型失败:', error);
Message.error('绑定设备端物模型失败');
} finally {
bindModalApi.setState({ loading: false, confirmLoading: false });
}
}
//
async function submitBatchAdd() {
const { valid } = await batchAddFormApi.validate();
@ -958,6 +1049,9 @@ const toolbarActions = computed(() => [
<Button size="small" type="link" @click="openCommandModal.bind(null, row)()">
{{ $t('abp.IoTDBBase.Command') }}
</Button>
<Button size="small" type="link" @click="openBindModal.bind(null, row)()">
绑定设备端物模型
</Button>
<Popover trigger="hover" placement="bottomRight" :overlay-style="{ minWidth: '120px' }">
<template #content>
<div style="display: flex; flex-direction: column; gap: 4px">
@ -1067,6 +1161,9 @@ const toolbarActions = computed(() => [
</div>
</div>
</CommandModal>
<BindModal title="绑定设备端物模型" class="w-[600px]">
<BindForm />
</BindModal>
<BatchAddModal title="批量添加设备" class="w-[800px]">
<BatchAddForm />
<template #footer>

View File

@ -10,6 +10,7 @@ import {
getCommonGetSelectList,
postCtWingAccountListAsync,
postCtWingProductListAsync,
postIoTplatformThingModelInfoFindByPlatformProductIdAsync,
postOneNetAccountListAsync,
postOneNetProductListAsync,
} from '#/api-client';
@ -39,7 +40,7 @@ export const querySchema = computed(() => [
allowClear: true,
placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatform')}`,
afterFetch: (res: any) => {
console.log('产品选择器API调用 - 平台类型:',res);
console.log('产品选择器API调用 - 平台类型:', res);
// 确保返回的是数组格式
if (Array.isArray(res)) {
@ -64,8 +65,14 @@ export const querySchema = computed(() => [
label: $t('common.BelongingProductName'),
dependencies: {
show(values: any) {
const shouldShow = values.ioTPlatform === 2 || values.ioTPlatform === '2';
console.log('OneNET产品选择器显示检查 - 平台类型:', values.ioTPlatform, '是否显示:', shouldShow);
const shouldShow =
values.ioTPlatform === 2 || values.ioTPlatform === '2';
console.log(
'OneNET产品选择器显示检查 - 平台类型:',
values.ioTPlatform,
'是否显示:',
shouldShow,
);
return shouldShow; // OneNET平台
},
triggerFields: ['ioTPlatform'],
@ -113,8 +120,14 @@ export const querySchema = computed(() => [
label: $t('common.BelongingProductName'),
dependencies: {
show(values: any) {
const shouldShow = values.ioTPlatform === 1 || values.ioTPlatform === '1';
console.log('CTWing产品选择器显示检查 - 平台类型:', values.ioTPlatform, '是否显示:', shouldShow);
const shouldShow =
values.ioTPlatform === 1 || values.ioTPlatform === '1';
console.log(
'CTWing产品选择器显示检查 - 平台类型:',
values.ioTPlatform,
'是否显示:',
shouldShow,
);
return shouldShow; // CTWing平台
},
triggerFields: ['ioTPlatform'],
@ -226,7 +239,7 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
title: $t('common.action'),
field: 'action',
fixed: 'right',
width: '180',
width: '280',
slots: { default: 'action' },
},
]);
@ -514,6 +527,76 @@ export const addDeviceFormSchema: any = computed(() => [
},
]);
// 设备绑定设备端物模型表单
export const bindDeviceThingModelFormSchema: any = computed(() => [
{
component: 'Switch',
fieldName: 'isNeedConfigDevicMdoel',
label: '是否需要配置设备模型',
defaultValue: false,
componentProps: {
style: { width: 'auto' },
},
},
{
component: 'ApiSelect',
fieldName: 'deviceThingModelDataId',
label: '设备物模型',
// 仅在需要配置设备模型时显示
dependencies: {
show(values: any) {
return !!values.isNeedConfigDevicMdoel;
},
triggerFields: ['isNeedConfigDevicMdoel', '_ioTPlatformProductId'],
},
// 选择设备端物模型
componentProps: (formValues: any) => {
const productId =
formValues?._ioTPlatformProductId || formValues?.ioTPlatformProductId;
return {
api: productId
? postIoTplatformThingModelInfoFindByPlatformProductIdAsync
: null,
params: productId
? {
query: {
input: {
id: String(productId),
},
},
}
: {},
// 平台物模型信息里的显示字段(优先显示标准字段显示名)
labelField: 'standardFieldDisplayName',
valueField: 'id',
optionsPropName: 'options',
immediate: !!productId,
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 && res.data && Array.isArray(res.data.items)) {
return res.data.items;
}
return [];
},
};
},
// 规则在提交中按开关手动校验,这里设为可选
rules: z.string().optional(),
},
]);
export const editDeviceFormSchemaEdit: any = computed(() => [
{
component: 'ApiSelect',

View File

@ -175,7 +175,7 @@ async function loadPropertyOptions() {
const items = data?.items || [];
propertyOptions.value = items.map((item: any) => ({
label: `${item.standardFieldDisplayName || item.standardFieldName} (${item.standardFieldName})`,
value: item.standardFieldName || '',
value: item.ioTPlatformRawFieldName
}));
} catch (error) {
console.error('加载属性列表失败:', error);

View File

@ -23,9 +23,9 @@ import { TableAction } from '#/components/table-action';
import { $t } from '#/locales';
import {
addThingModelFormSchema,
getAddThingModelFormSchema,
copyThingModelFormSchema,
editThingModelFormSchema,
getEditThingModelFormSchema,
querySchema,
tableSchema,
} from './schema';
@ -178,12 +178,69 @@ const [ThingModelModal, thingModelModalApi] = useVbenModal({
onBeforeClose: () => {
return true;
},
onOpenChange: (isOpen: boolean) => {
if (isOpen && editRow.value.id) {
//
nextTick(() => {
editFormApi.setValues({ ...editRow.value });
onOpenChange: async (isOpen: boolean) => {
if (isOpen) {
// ID
await nextTick();
const formApi = editRow.value.id ? editFormApi : addFormApi;
const isEdit = !!editRow.value.id;
//
let platformValue: 1 | 2;
let productIdValue: string;
if (isEdit) {
// editRow.value
platformValue = editRow.value.ioTPlatform
? (typeof editRow.value.ioTPlatform === 'string'
? Number.parseInt(editRow.value.ioTPlatform)
: editRow.value.ioTPlatform) as 1 | 2
: Number.parseInt(ioTPlatform.value) as 1 | 2;
productIdValue = editRow.value.ioTPlatformProductId || productId.value;
} else {
//
const formValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
platformValue = formValues.ioTPlatform
? (typeof formValues.ioTPlatform === 'string'
? Number.parseInt(formValues.ioTPlatform)
: formValues.ioTPlatform) as 1 | 2
: Number.parseInt(ioTPlatform.value) as 1 | 2;
productIdValue = formValues.ioTPlatformProductId || productId.value;
//
if (formValues.ioTPlatform) {
ioTPlatform.value = String(formValues.ioTPlatform);
}
if (formValues.ioTPlatformProductId) {
productId.value = String(formValues.ioTPlatformProductId);
}
}
console.log('设置表单值:', {
isEdit,
platformValue,
productIdValue,
editRowValue: isEdit ? editRow.value : null,
});
await formApi.setValues({
...(isEdit ? editRow.value : {}),
_ioTPlatform: platformValue,
_ioTPlatformProductId: productIdValue,
});
//
setTimeout(() => {
const fieldRef = formApi.getFieldComponentRef('ioTPlatformRawFieldName');
if (fieldRef && typeof fieldRef.updateParam === 'function') {
fieldRef.updateParam({
body: {
ioTPlatformType: platformValue,
ioTPlatformProductId: productIdValue,
},
});
}
}, 100);
}
},
onCancel: () => {
@ -205,6 +262,19 @@ const [CopyModal, copyModalApi] = useVbenModal({
},
});
// schemaID
// 使 _ioTPlatform _ioTPlatformProductId
const addThingModelFormSchema = getAddThingModelFormSchema(
() => {
//
return ioTPlatform.value ? Number.parseInt(ioTPlatform.value) as 1 | 2 : undefined;
},
() => {
//
return productId.value || undefined;
},
);
const [AddForm, addFormApi] = useVbenForm({
collapsed: false,
commonConfig: {
@ -221,6 +291,24 @@ const [AddForm, addFormApi] = useVbenForm({
wrapperClass: 'grid-cols-2',
});
// schemaID editRow
const editThingModelFormSchema = getEditThingModelFormSchema(
() => {
// editRow
if (editRow.value?.ioTPlatform) {
return typeof editRow.value.ioTPlatform === 'string'
? Number.parseInt(editRow.value.ioTPlatform)
: editRow.value.ioTPlatform;
}
// 使
return ioTPlatform.value ? Number.parseInt(ioTPlatform.value) as 1 | 2 : undefined;
},
() => {
// editRow
return editRow.value?.ioTPlatformProductId || productId.value || undefined;
},
);
const [EditForm, editFormApi] = useVbenForm({
collapsed: false,
commonConfig: {
@ -371,12 +459,75 @@ async function submit() {
async function onEdit(record: any) {
editRow.value = record;
// ID
const platformValue = record.ioTPlatform
? (typeof record.ioTPlatform === 'string'
? Number.parseInt(record.ioTPlatform)
: record.ioTPlatform) as 1 | 2
: Number.parseInt(ioTPlatform.value) as 1 | 2;
const productIdValue = record.ioTPlatformProductId || productId.value;
thingModelModalApi.open();
await nextTick();
setTimeout(async () => {
await editFormApi.setValues({
...record,
_ioTPlatform: platformValue,
_ioTPlatformProductId: productIdValue,
});
//
const fieldRef = editFormApi.getFieldComponentRef('ioTPlatformRawFieldName');
if (fieldRef && typeof fieldRef.updateParam === 'function') {
fieldRef.updateParam({
body: {
ioTPlatformType: platformValue,
ioTPlatformProductId: productIdValue,
},
});
}
}, 100);
}
const openAddModal = async () => {
editRow.value = {};
// ID
const formValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
const platformValue = formValues.ioTPlatform
? (typeof formValues.ioTPlatform === 'string'
? Number.parseInt(formValues.ioTPlatform)
: formValues.ioTPlatform) as 1 | 2
: Number.parseInt(ioTPlatform.value) as 1 | 2;
const productIdValue = formValues.ioTPlatformProductId || productId.value;
//
if (formValues.ioTPlatform) {
ioTPlatform.value = String(formValues.ioTPlatform);
}
if (formValues.ioTPlatformProductId) {
productId.value = String(formValues.ioTPlatformProductId);
}
thingModelModalApi.open();
//
await nextTick();
setTimeout(async () => {
await addFormApi.setValues({
_ioTPlatform: platformValue,
_ioTPlatformProductId: productIdValue,
});
//
const fieldRef = addFormApi.getFieldComponentRef('ioTPlatformRawFieldName');
if (fieldRef && typeof fieldRef.updateParam === 'function') {
fieldRef.updateParam({
body: {
ioTPlatformType: platformValue,
ioTPlatformProductId: productIdValue,
},
});
}
}, 100);
};
//

View File

@ -7,6 +7,7 @@ import dayjs from 'dayjs';
import {
getCommonGetSelectList,
postAggregationIoTplatformGetIoTplatformProductInfoAsync,
postAggregationIoTplatformGetIoTplatformProductPropertyInfoAsync,
postOneNetProductListAsync,
} from '#/api-client';
import { $t } from '#/locales';
@ -179,7 +180,7 @@ export const tableSchema = computed(() => [
]);
// 添加物模型表单schema
export const addThingModelFormSchema = computed(() => [
export const getAddThingModelFormSchema = (getPlatform: () => number | string | undefined, getProductId: () => string | undefined) => computed(() => [
{
component: 'ApiSelect',
fieldName: 'filedType',
@ -293,17 +294,128 @@ export const addThingModelFormSchema = computed(() => [
},
},
{
component: 'Input',
component: 'ApiSelect',
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'),
dependencies: {
triggerFields: ['_ioTPlatform', '_ioTPlatformProductId'],
componentProps: (formValues: any) => {
// 优先从表单值获取(这是最可靠的方式,因为值是在打开弹窗时设置的)
let platform = formValues?._ioTPlatform;
let productId = formValues?._ioTPlatformProductId;
// 如果表单值中没有,尝试从其他字段获取
if (!platform && formValues?.ioTPlatform) {
platform = typeof formValues.ioTPlatform === 'string'
? Number.parseInt(formValues.ioTPlatform)
: formValues.ioTPlatform;
}
if (!productId && formValues?.ioTPlatformProductId) {
productId = formValues.ioTPlatformProductId;
}
// 如果还是没有,尝试从外部函数获取(作为后备方案)
if (!platform) {
const externalPlatform = getPlatform();
if (externalPlatform) {
platform = typeof externalPlatform === 'string'
? Number.parseInt(externalPlatform)
: externalPlatform;
}
}
if (!productId) {
const externalProductId = getProductId();
if (externalProductId) {
productId = String(externalProductId);
}
}
// 确保平台类型是数字
if (platform && typeof platform === 'string') {
platform = Number.parseInt(platform);
}
// 调试信息
console.log('平台物模型编码下拉框配置:', {
platform,
productId,
hasApi: !!(platform && productId),
fromForm: {
_ioTPlatform: formValues?._ioTPlatform,
_ioTPlatformProductId: formValues?._ioTPlatformProductId,
ioTPlatform: formValues?.ioTPlatform,
ioTPlatformProductId: formValues?.ioTPlatformProductId,
},
});
return {
api:
platform && productId
? postAggregationIoTplatformGetIoTplatformProductPropertyInfoAsync
: null,
params:
platform && productId
? {
body: {
ioTPlatformType:
typeof platform === 'string'
? Number.parseInt(platform)
: platform,
ioTPlatformProductId: String(productId),
},
}
: {},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: !!(platform && productId), // 当有平台和产品ID时立即加载
allowClear: true,
placeholder:
$t('common.pleaseSelect') +
$t('abp.thingModelInfos.IoTPlatformRawFieldName'),
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;
}
// 存储原始数据映射,用于后续查找 secondValue
const optionMap = new Map();
items.forEach((item: any) => {
if (item.key) {
optionMap.set(item.key, item.secondValue);
}
});
(formValues as any)._platformPropertyMap = optionMap;
return items;
},
onChange: (value: string) => {
// 选择后自动设置平台物模型数值类型为选中项的 secondValue
const optionMap = (formValues as any)._platformPropertyMap;
if (optionMap && value) {
let secondValue = optionMap.get(value);
if (secondValue) {
// 兼容 BOOL / BOOLEAN 差异,统一转换为后端 / 枚举使用的 BOOLEAN
if (
typeof secondValue === 'string' &&
secondValue.toUpperCase() === 'BOOL'
) {
secondValue = 'BOOLEAN';
}
formValues.ioTPlatformRawFieldDataType = secondValue;
}
}
},
};
},
},
},
{
@ -368,7 +480,7 @@ export const addThingModelFormSchema = computed(() => [
]);
// 编辑物模型表单schema
export const editThingModelFormSchema = computed(() => [
export const getEditThingModelFormSchema = (getPlatform: () => number | string | undefined, getProductId: () => string | undefined) => computed(() => [
{
component: 'ApiSelect',
fieldName: 'filedType',
@ -481,18 +593,128 @@ export const editThingModelFormSchema = computed(() => [
},
},
{
component: 'Input',
component: 'ApiSelect',
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'),
dependencies: {
triggerFields: ['_ioTPlatform', '_ioTPlatformProductId'],
componentProps: (formValues: any) => {
// 优先从表单值获取(这是最可靠的方式,因为值是在打开弹窗时设置的)
let platform = formValues?._ioTPlatform;
let productId = formValues?._ioTPlatformProductId;
// 如果表单值中没有,尝试从其他字段获取
if (!platform && formValues?.ioTPlatform) {
platform = typeof formValues.ioTPlatform === 'string'
? Number.parseInt(formValues.ioTPlatform)
: formValues.ioTPlatform;
}
if (!productId && formValues?.ioTPlatformProductId) {
productId = formValues.ioTPlatformProductId;
}
// 如果还是没有,尝试从外部函数获取(作为后备方案)
if (!platform) {
const externalPlatform = getPlatform();
if (externalPlatform) {
platform = typeof externalPlatform === 'string'
? Number.parseInt(externalPlatform)
: externalPlatform;
}
}
if (!productId) {
const externalProductId = getProductId();
if (externalProductId) {
productId = String(externalProductId);
}
}
// 确保平台类型是数字
if (platform && typeof platform === 'string') {
platform = Number.parseInt(platform);
}
// 调试信息
console.log('平台物模型编码下拉框配置:', {
platform,
productId,
hasApi: !!(platform && productId),
fromForm: {
_ioTPlatform: formValues?._ioTPlatform,
_ioTPlatformProductId: formValues?._ioTPlatformProductId,
ioTPlatform: formValues?.ioTPlatform,
ioTPlatformProductId: formValues?.ioTPlatformProductId,
},
});
return {
api:
platform && productId
? postAggregationIoTplatformGetIoTplatformProductPropertyInfoAsync
: null,
params:
platform && productId
? {
body: {
ioTPlatformType:
typeof platform === 'string'
? Number.parseInt(platform)
: platform,
ioTPlatformProductId: String(productId),
},
}
: {},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: !!(platform && productId), // 当有平台和产品ID时立即加载
allowClear: true,
placeholder:
$t('common.pleaseSelect') +
$t('abp.thingModelInfos.IoTPlatformRawFieldName'),
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;
}
// 存储原始数据映射,用于后续查找 secondValue
const optionMap = new Map();
items.forEach((item: any) => {
if (item.key) {
optionMap.set(item.key, item.secondValue);
}
});
(formValues as any)._platformPropertyMap = optionMap;
return items;
},
onChange: (value: string) => {
// 选择后自动设置平台物模型数值类型为选中项的 secondValue
const optionMap = (formValues as any)._platformPropertyMap;
if (optionMap && value) {
let secondValue = optionMap.get(value);
if (secondValue) {
// 兼容 BOOL / BOOLEAN 差异,统一转换为后端 / 枚举使用的 BOOLEAN
if (
typeof secondValue === 'string' &&
secondValue.toUpperCase() === 'BOOL'
) {
secondValue = 'BOOLEAN';
}
formValues.ioTPlatformRawFieldDataType = secondValue;
}
}
},
};
},
},
},
{