1013 lines
32 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 13:54:19 +08:00
import {
getCommonGetSelectList,
2025-12-17 15:51:26 +08:00
postAggregationIoTplatformGetIoTplatformProductInfoAsync,
2026-01-05 17:30:43 +08:00
postAggregationIoTplatformGetIoTplatformProductThingModelInfoAsync,
2025-10-23 13:54:19 +08:00
postOneNetProductListAsync,
} from '#/api-client';
2025-10-22 15:09:56 +08:00
import { $t } from '#/locales';
export const querySchema = computed(() => [
2025-12-17 15:51:26 +08:00
{
component: 'ApiSelect',
fieldName: 'ioTPlatform',
label: $t('abp.deviceInfos.ioTPlatform'),
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'IoTPlatformTypeEnum',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatform')}`,
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: 'ioTPlatformProductId',
label: $t('common.BelongingProductName'),
dependencies: {
show(values: any) {
return !!values.ioTPlatform;
},
triggerFields: ['ioTPlatform'],
},
componentProps: (formValues: any) => {
const platform = formValues?.ioTPlatform;
return {
api: platform
? postAggregationIoTplatformGetIoTplatformProductInfoAsync
: null,
params: {
body: {
// 聚合服务要求 JSON Body 格式参数
ioTPlatformType:
typeof platform === 'string'
? Number.parseInt(platform)
: platform,
},
},
labelField: 'productName',
valueField: 'ioTPlatformProductId',
optionsPropName: 'options',
immediate: false,
allowClear: true,
placeholder: `${$t('common.pleaseSelect')}${$t('common.BelongingProductName')}`,
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 [];
},
};
},
},
2025-10-22 15:09:56 +08:00
{
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(() => [
{
2025-12-24 11:51:37 +08:00
field: 'filedTypeName',
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: '数组',
Struct: '结构体',
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: 'accessMode',
title: $t('abp.thingModelInfos.AccessMode'),
minWidth: 120,
formatter: ({ cellValue }: { cellValue: any }) => {
return cellValue === 'rw'
? '读写模式'
: cellValue === 'r'
? '只读模式'
: '只写模式';
},
},
{
field: 'isOperableIdentifier',
title: $t('abp.thingModelInfos.IsOperableIdentifier'),
minWidth: 150,
formatter: ({ cellValue }: { cellValue: any }) => {
return cellValue === true ? '是' : '否';
},
},
2025-10-22 15:09:56 +08:00
{
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
2025-12-24 11:51:37 +08:00
export const getAddThingModelFormSchema = (
getPlatform: () => number | string | undefined,
getProductId: () => string | undefined,
) =>
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 [];
2025-10-22 17:06:15 +08:00
},
},
2025-10-22 15:09:56 +08:00
},
2025-12-24 11:51:37 +08:00
{
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 [];
2025-12-22 14:21:38 +08:00
},
},
2025-10-22 15:09:56 +08:00
},
2025-12-24 11:51:37 +08:00
{
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.standardFieldDisplayName = item?.displayText ?? '';
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'),
2025-10-22 17:29:07 +08:00
},
2025-10-23 09:37:23 +08:00
},
2025-12-24 11:51:37 +08:00
{
component: 'ApiSelect',
fieldName: 'ioTPlatformRawFieldName',
label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'),
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, $t('common.required')),
),
dependencies: {
2026-01-04 15:40:14 +08:00
triggerFields: ['_ioTPlatform', '_ioTPlatformProductId', 'filedType'],
2026-01-05 17:30:43 +08:00
trigger: async (_formValues: any, formApi: any) => {
// 当 filedType 变化时,清空字段值,强制组件重新加载
if (formApi && typeof formApi.setFieldValue === 'function') {
await formApi.setFieldValue('ioTPlatformRawFieldName', undefined);
}
},
2025-12-24 11:51:37 +08:00
componentProps: (formValues: any) => {
// 优先从表单值获取(这是最可靠的方式,因为值是在打开弹窗时设置的)
let platform = formValues?._ioTPlatform;
let productId = formValues?._ioTPlatformProductId;
const filedType = formValues?.filedType;
2025-12-24 11:51:37 +08:00
// 如果表单值中没有,尝试从其他字段获取
if (!platform && formValues?.ioTPlatform) {
platform =
typeof formValues.ioTPlatform === 'string'
? Number.parseInt(formValues.ioTPlatform)
: formValues.ioTPlatform;
2025-12-22 17:28:38 +08:00
}
2025-12-24 11:51:37 +08:00
if (!productId && formValues?.ioTPlatformProductId) {
productId = formValues.ioTPlatformProductId;
2025-12-22 17:28:38 +08:00
}
2025-12-24 11:51:37 +08:00
// 如果还是没有,尝试从外部函数获取(作为后备方案)
if (!platform) {
const externalPlatform = getPlatform();
if (externalPlatform) {
platform =
typeof externalPlatform === 'string'
? Number.parseInt(externalPlatform)
: externalPlatform;
2025-12-22 17:28:38 +08:00
}
}
2025-12-24 11:51:37 +08:00
if (!productId) {
const externalProductId = getProductId();
if (externalProductId) {
productId = String(externalProductId);
2025-12-22 17:28:38 +08:00
}
2025-12-24 11:51:37 +08:00
}
// 确保平台类型是数字
if (platform && typeof platform === 'string') {
platform = Number.parseInt(platform);
}
// 调试信息
console.log('平台物模型编码下拉框配置:', {
platform,
productId,
2026-01-04 15:40:14 +08:00
filedType,
2025-12-24 11:51:37 +08:00
hasApi: !!(platform && productId),
fromForm: {
_ioTPlatform: formValues?._ioTPlatform,
_ioTPlatformProductId: formValues?._ioTPlatformProductId,
ioTPlatform: formValues?.ioTPlatform,
ioTPlatformProductId: formValues?.ioTPlatformProductId,
2026-01-04 15:40:14 +08:00
filedType: formValues?.filedType,
2025-12-24 11:51:37 +08:00
},
});
return {
api:
platform && productId
2026-01-05 17:30:43 +08:00
? postAggregationIoTplatformGetIoTplatformProductThingModelInfoAsync
2025-12-24 11:51:37 +08:00
: null,
params:
platform && productId
? {
body: {
ioTPlatformType:
typeof platform === 'string'
? Number.parseInt(platform)
: platform,
ioTPlatformProductId: String(productId),
2026-01-05 17:30:43 +08:00
// 确保 FiledType 参数始终存在(即使为空),以便触发接口重新请求
FiledType: filedType ? String(filedType) : undefined,
2025-12-24 11:51:37 +08:00
},
}
: {},
2026-01-05 17:30:43 +08:00
// 添加 key 确保 filedType 变化时组件重新渲染
key: `platform-${platform}-product-${productId}-type-${filedType || 'none'}`,
2025-12-24 11:51:37 +08:00
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: !!(platform && productId), // 当有平台和产品ID时立即加载
allowClear: true,
2026-01-04 15:40:14 +08:00
showSearch: true,
2025-12-24 11:51:37 +08:00
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;
}
}
},
};
},
2025-12-22 17:28:38 +08:00
},
2025-12-22 14:21:38 +08:00
},
2025-12-24 11:51:37 +08:00
{
component: 'Switch',
fieldName: 'isValueNeedConvert',
label: $t('abp.thingModelInfos.IsValueNeedConvert'),
defaultValue: false,
componentProps: {
style: { width: 'auto' },
},
2025-12-22 14:21:38 +08:00
},
{
component: 'ApiSelect',
fieldName: 'accessMode',
label: $t('abp.thingModelInfos.AccessMode'),
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'DevicePropertyAccessMode',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder:
$t('common.pleaseSelect') + $t('abp.thingModelInfos.AccessMode'),
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: 'isOperableIdentifier',
label: $t('abp.thingModelInfos.IsOperableIdentifier'),
defaultValue: false,
componentProps: {
style: { width: 'auto' },
},
},
2025-12-24 11:51:37 +08:00
{
component: 'ApiSelect',
fieldName: 'ioTPlatformRawFieldDataType',
label: '平台物模型值类型',
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'StandardThingModelDataTypeEnum',
},
},
labelField: 'value',
valueField: 'secondValue',
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 [];
2025-10-22 17:06:15 +08:00
},
},
2025-10-22 15:09:56 +08:00
},
2025-12-24 11:51:37 +08:00
{
component: 'Switch',
fieldName: 'isSpecialIdentifier',
label: '是否特殊物模型标识符',
defaultValue: false,
componentProps: {
style: { width: 'auto' },
},
2025-10-22 17:06:15 +08:00
},
2025-12-24 11:51:37 +08:00
{
component: 'Textarea',
fieldName: 'ioTPlatformRawFieldExtension',
label: '平台物模型值类型扩展',
componentProps: {
rows: 4,
placeholder:
'请输入平台原始字段扩展信息用于扩展结构体类型JSON格式',
},
2025-12-22 14:21:38 +08:00
},
2025-12-24 11:51:37 +08:00
]);
2025-10-22 15:09:56 +08:00
// 编辑物模型表单schema
2025-12-24 11:51:37 +08:00
export const getEditThingModelFormSchema = (
getPlatform: () => number | string | undefined,
getProductId: () => string | undefined,
) =>
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 [];
2025-10-22 17:06:15 +08:00
},
},
2025-10-22 15:09:56 +08:00
},
2025-12-24 11:51:37 +08:00
{
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, // 显示文本
}));
2025-12-22 14:21:38 +08:00
},
},
2025-10-22 15:09:56 +08:00
},
2025-12-24 11:51:37 +08:00
{
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?.displayText ?? '';
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'),
2025-10-22 17:29:07 +08:00
},
2025-10-23 09:37:23 +08:00
},
2025-12-24 11:51:37 +08:00
{
component: 'ApiSelect',
fieldName: 'ioTPlatformRawFieldName',
label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'),
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, $t('common.required')),
),
dependencies: {
2026-01-04 15:40:14 +08:00
triggerFields: ['_ioTPlatform', '_ioTPlatformProductId', 'filedType'],
2026-01-05 17:30:43 +08:00
trigger: async (_formValues: any, formApi: any) => {
// 当 filedType 变化时,清空字段值,强制组件重新加载
if (formApi && typeof formApi.setFieldValue === 'function') {
await formApi.setFieldValue('ioTPlatformRawFieldName', undefined);
}
},
2025-12-24 11:51:37 +08:00
componentProps: (formValues: any) => {
// 优先从表单值获取(这是最可靠的方式,因为值是在打开弹窗时设置的)
let platform = formValues?._ioTPlatform;
let productId = formValues?._ioTPlatformProductId;
const filedType = formValues?.filedType;
2025-12-24 11:51:37 +08:00
// 如果表单值中没有,尝试从其他字段获取
if (!platform && formValues?.ioTPlatform) {
platform =
typeof formValues.ioTPlatform === 'string'
? Number.parseInt(formValues.ioTPlatform)
: formValues.ioTPlatform;
2025-12-22 17:28:38 +08:00
}
2025-12-24 11:51:37 +08:00
if (!productId && formValues?.ioTPlatformProductId) {
productId = formValues.ioTPlatformProductId;
2025-12-22 17:28:38 +08:00
}
2025-12-24 11:51:37 +08:00
// 如果还是没有,尝试从外部函数获取(作为后备方案)
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,
2026-01-04 15:40:14 +08:00
filedType,
2025-12-24 11:51:37 +08:00
hasApi: !!(platform && productId),
fromForm: {
_ioTPlatform: formValues?._ioTPlatform,
_ioTPlatformProductId: formValues?._ioTPlatformProductId,
ioTPlatform: formValues?.ioTPlatform,
ioTPlatformProductId: formValues?.ioTPlatformProductId,
2026-01-04 15:40:14 +08:00
filedType: formValues?.filedType,
2025-12-24 11:51:37 +08:00
},
});
2025-12-22 17:28:38 +08:00
2025-12-24 11:51:37 +08:00
return {
api:
platform && productId
2026-01-05 17:30:43 +08:00
? postAggregationIoTplatformGetIoTplatformProductThingModelInfoAsync
2025-12-24 11:51:37 +08:00
: null,
params:
platform && productId
? {
body: {
ioTPlatformType:
typeof platform === 'string'
? Number.parseInt(platform)
: platform,
ioTPlatformProductId: String(productId),
2026-01-05 17:30:43 +08:00
// 确保 FiledType 参数始终存在(即使为空),以便触发接口重新请求
FiledType: filedType ? String(filedType) : undefined,
2025-12-24 11:51:37 +08:00
},
}
: {},
2026-01-05 17:30:43 +08:00
// 添加 key 确保 filedType 变化时组件重新渲染
key: `platform-${platform}-product-${productId}-type-${filedType || 'none'}`,
2025-12-24 11:51:37 +08:00
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: !!(platform && productId), // 当有平台和产品ID时立即加载
allowClear: true,
2026-01-04 15:40:14 +08:00
showSearch: true,
2025-12-24 11:51:37 +08:00
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;
2025-12-22 17:28:38 +08:00
}
}
2025-12-24 11:51:37 +08:00
},
};
},
},
},
{
component: 'Switch',
fieldName: 'isValueNeedConvert',
label: $t('abp.thingModelInfos.IsValueNeedConvert'),
componentProps: {
style: { width: 'auto' },
},
},
{
component: 'ApiSelect',
fieldName: 'accessMode',
label: $t('abp.thingModelInfos.AccessMode'),
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'DevicePropertyAccessMode',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder:
$t('common.pleaseSelect') + $t('abp.thingModelInfos.AccessMode'),
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: 'isOperableIdentifier',
label: $t('abp.thingModelInfos.IsOperableIdentifier'),
componentProps: {
style: { width: 'auto' },
},
},
2025-12-24 11:51:37 +08:00
{
component: 'ApiSelect',
fieldName: 'ioTPlatformRawFieldDataType',
label: '平台物模型值类型',
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'StandardThingModelDataTypeEnum',
2025-12-22 17:28:38 +08:00
},
2025-12-24 11:51:37 +08:00
},
labelField: 'value',
valueField: 'secondValue',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: '请选择平台原始字段数据类型',
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
2025-12-22 17:28:38 +08:00
}
2025-12-24 11:51:37 +08:00
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
return [];
},
2025-12-22 17:28:38 +08:00
},
2025-12-22 14:21:38 +08:00
},
2025-12-24 11:51:37 +08:00
{
component: 'Switch',
fieldName: 'isSpecialIdentifier',
label: '是否特殊物模型标识符',
componentProps: {
style: { width: 'auto' },
},
2025-12-22 14:21:38 +08:00
},
2025-12-24 11:51:37 +08:00
{
component: 'Textarea',
fieldName: 'ioTPlatformRawFieldExtension',
label: '平台物模型值类型扩展',
componentProps: {
rows: 4,
placeholder:
'请输入平台原始字段扩展信息用于扩展结构体类型JSON格式',
},
},
]);
// 复制已有模型表单schema
export const copyThingModelFormSchema = computed(() => [
2025-12-22 14:21:38 +08:00
{
component: 'ApiSelect',
2025-12-24 11:51:37 +08:00
fieldName: 'ioTPlatformProductId',
label: '选择要复制的产品',
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, '请选择要复制的产品'),
),
2025-10-22 15:09:56 +08:00
componentProps: {
2025-12-24 11:51:37 +08:00
api: postOneNetProductListAsync,
2025-10-22 17:06:15 +08:00
params: {
query: {
2025-12-24 11:51:37 +08:00
pageIndex: 1,
pageSize: 1000,
2025-10-22 17:06:15 +08:00
},
},
2025-12-24 11:51:37 +08:00
labelField: 'productName',
valueField: 'ioTPlatformProductId',
2025-10-22 17:06:15 +08:00
optionsPropName: 'options',
immediate: true,
2025-10-23 09:37:23 +08:00
allowClear: true,
2025-12-24 11:51:37 +08:00
placeholder: '请选择产品',
2025-10-22 17:06:15 +08:00
afterFetch: (res: any) => {
2025-12-22 14:21:38 +08:00
// 确保返回的是数组格式
2025-10-23 09:37:23 +08:00
if (Array.isArray(res)) {
2025-12-22 14:21:38 +08:00
return res;
2025-10-23 09:37:23 +08:00
}
2025-12-22 14:21:38 +08:00
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
2025-12-24 11:51:37 +08:00
if (res && Array.isArray(res.data.items)) {
return res.data.items;
}
2025-12-22 14:21:38 +08:00
return [];
2025-10-22 17:06:15 +08:00
},
2025-10-22 15:09:56 +08:00
},
2025-10-23 13:54:19 +08:00
},
2025-10-22 15:09:56 +08:00
]);
2025-10-23 11:48:10 +08:00
2025-12-24 11:51:37 +08:00
// 复制标准模型(按物模型类型多选)表单 schema
export const copyStandardThingModelFormSchema = computed(() => [
2025-10-23 11:48:10 +08:00
{
component: 'ApiSelect',
2025-12-24 11:51:37 +08:00
fieldName: 'filedTypes',
label: '选择要复制的物模型类型',
2025-10-23 11:48:10 +08:00
rules: z.preprocess(
2025-12-24 11:51:37 +08:00
(v) => (v == null ? [] : v),
z.array(z.string()).min(1, '请至少选择一个物模型类型'),
2025-10-23 11:48:10 +08:00
),
componentProps: {
2025-12-24 11:51:37 +08:00
api: getCommonGetSelectList,
2025-10-23 11:48:10 +08:00
params: {
query: {
2025-12-24 11:51:37 +08:00
// 与物模型字段类型相同的数据字典Property / Service / Event
typeName: 'DataDictionaryTypeConst',
2025-10-23 11:48:10 +08:00
},
},
2025-12-24 11:51:37 +08:00
labelField: 'value',
valueField: 'key',
2025-10-23 13:54:19 +08:00
optionsPropName: 'options',
2025-10-23 11:48:10 +08:00
immediate: true,
allowClear: true,
2025-12-24 11:51:37 +08:00
mode: 'multiple',
placeholder: '请选择要复制的物模型类型(可多选)',
maxTagCount: 'responsive',
2025-10-23 11:48:10 +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 [];
},
},
},
]);