完善物模型管理

This commit is contained in:
ChenYi 2025-10-23 09:37:23 +08:00
parent 3f1dc4c6e3
commit 7f3328c8db
3 changed files with 130 additions and 104 deletions

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, watch, computed } from 'vue';
import { ref, watch, computed, h } from 'vue';
import { Select, Divider, Row } from 'ant-design-vue';
import { ChevronLeft, ChevronRight } from '@vben/icons';
import { postDataDictionarySelectDetail } from '#/api-client';
@ -27,7 +27,9 @@ const emit = defineEmits<{
'item-change': [any | null];
}>();
const VNodes = (_: any, { attrs }: any) => attrs.vnodes;
const VNodes = (props: any) => {
return props.vnodes;
};
const options = ref<any[]>([]);
const total = ref(0);
@ -57,11 +59,24 @@ const fetchData = async () => {
} as any,
});
const items = Array.isArray(data?.items) ? data!.items : [];
options.value = items.map((item: any) => ({
label: item.displayText,
const mappedItems = items.map((item: any) => ({
label: `${item.displayText}`,
value: item.code,
...item,
}));
//
if (props.value && props.value.trim() !== '' && !mappedItems.find(item => item.value === props.value)) {
//
mappedItems.unshift({
label: `当前值: ${props.value}`,
value: props.value,
displayText: props.value,
code: props.value,
});
}
options.value = mappedItems;
total.value = (data as any)?.totalCount || 0;
} catch (err) {
console.error('获取标准物模型编码失败:', err);
@ -114,6 +129,18 @@ watch(
},
{ immediate: true },
);
//
watch(
() => props.value,
(newValue) => {
if (newValue && newValue.trim() !== '' && props.typeCode && !options.value.find(item => item.value === newValue)) {
//
fetchData();
}
},
{ immediate: true },
);
</script>
<template>

View File

@ -2,20 +2,20 @@
import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed, h, nextTick, ref, watch } from 'vue';
import { h, nextTick, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message as Message, Tag, Modal } from 'ant-design-vue';
import { message as Message, Modal, Tag } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
postThingModelInfoPageAsync,
postThingModelInfoDeleteAsync,
postThingModelInfoCreateAsync,
postThingModelInfoUpdateAsync,
postThingModelInfoCopyStandardThingModel,
postThingModelInfoCreateAsync,
postThingModelInfoDeleteAsync,
postThingModelInfoPageAsync,
postThingModelInfoUpdateAsync,
} from '#/api-client';
import { TableAction } from '#/components/table-action';
import { $t } from '#/locales';
@ -31,14 +31,6 @@ defineOptions({
name: 'ThingModelInfoModal',
});
// props
interface Props {
visible?: boolean;
productId?: string;
productName?: string;
ioTPlatform?: string;
}
const props = withDefaults(defineProps<Props>(), {
visible: false,
productId: '',
@ -48,10 +40,18 @@ const props = withDefaults(defineProps<Props>(), {
// emits
const emit = defineEmits<{
close: [];
'update:visible': [value: boolean];
'close': [];
}>();
// props
interface Props {
visible?: boolean;
productId?: string;
productName?: string;
ioTPlatform?: string;
}
const formOptions: VbenFormProps = {
schema: querySchema.value,
};
@ -177,7 +177,7 @@ watch(
}, 100);
}
},
{ immediate: true }
{ immediate: true },
);
//
@ -193,16 +193,12 @@ async function submit() {
const formValues = await formApi.getValues();
const fetchParams: any = {
query: {
input: {
...formValues,
//
ioTPlatform: parseInt(props.ioTPlatform) as 1 | 2,
ioTPlatformProductId: props.productId,
// ID
...(isEdit && { id: editRow.value.id }),
},
},
...formValues,
//
ioTPlatform: Number.parseInt(props.ioTPlatform) as 1 | 2,
ioTPlatformProductId: props.productId,
// ID
...(isEdit && { id: editRow.value.id }),
};
try {
@ -284,17 +280,11 @@ function closeModal() {
</script>
<template>
<Modal
:open="visible"
:title="`物模型管理 - ${productName || '产品'}`"
width="90%"
:footer="null"
@cancel="closeModal"
@ok="closeModal"
:body-style="{ height: '70vh', overflow: 'hidden' }"
>
<div style="height: 100%; display: flex; flex-direction: column;">
<Grid style="flex: 1; overflow: hidden;">
<Modal :open="visible" :title="`${props.ioTPlatform === 1 ? 'CTWing' : 'OneNET'}物模型管理 - ${productName || '产品'}`"
width="90%" :footer="null" @cancel="closeModal" @ok="closeModal"
:body-style="{ height: '70vh', overflow: 'hidden' }">
<div style="display: flex; flex-direction: column; height: 100%">
<Grid style="flex: 1; overflow: hidden">
<template #toolbar-actions>
<TableAction :actions="[
{
@ -315,8 +305,10 @@ function closeModal() {
</template>
<template #isValueNeedConvert="{ row }">
<component :is="h(Tag, { color: row.isValueNeedConvert ? 'blue' : 'default' }, () =>
row.isValueNeedConvert ? '是' : '否',
<component :is="h(
Tag,
{ color: row.isValueNeedConvert ? 'blue' : 'default' },
() => (row.isValueNeedConvert ? '是' : '否'),
)
" />
</template>
@ -330,11 +322,12 @@ function closeModal() {
auth: ['AbpIdentity.Users.Update'],
onClick: onEdit.bind(null, row),
},
]" :drop-down-actions="[
{
label: $t('common.delete'),
icon: 'ant-design:delete-outlined',
type: 'primary',
type: 'link',
size: 'small',
auth: ['AbpIdentity.Users.Delete'],
popConfirm: {
title: $t('common.askConfirmDelete'),
confirm: onDel.bind(null, row),

View File

@ -146,24 +146,18 @@ export const addThingModelFormSchema = computed(() => [
},
{
component: 'StandardThingModelCodeSelect',
fieldName: 'standardFieldName',
label: $t('abp.thingModelInfos.StandardFieldName'),
fieldName: 'standardFieldDisplayName',
label: $t('abp.thingModelInfos.StandardFieldDisplayName'),
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, $t('common.required')),
),
dependencies: {
show(values: any) {
return !!values?.filedType;
},
triggerFields: ['filedType'],
},
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();
@ -172,6 +166,20 @@ export const addThingModelFormSchema = computed(() => [
$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',
@ -210,20 +218,6 @@ export const addThingModelFormSchema = computed(() => [
},
},
},
{
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',
@ -253,10 +247,11 @@ export const editThingModelFormSchema = computed(() => [
},
},
labelField: 'value',
valueField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
placeholder: $t('abp.thingModelInfos.PleaseSelectFiledType'),
disabled: true, // 编辑时禁用
placeholder: $t('common.pleaseSelect') + $t('abp.thingModelInfos.FiledType'),
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
@ -281,39 +276,49 @@ export const editThingModelFormSchema = computed(() => [
z.string().min(1, $t('common.required')),
),
componentProps: {
placeholder: $t('abp.thingModelInfos.PleaseInputIoTPlatformRawFieldName'),
// disabled: true, // 编辑时禁用
placeholder: $t('common.pleaseInput') +
$t('abp.thingModelInfos.IoTPlatformRawFieldName'),
},
},
{
component: 'StandardThingModelCodeSelect',
fieldName: 'standardFieldName',
label: $t('abp.thingModelInfos.StandardFieldName'),
fieldName: 'standardFieldDisplayName',
label: $t('abp.thingModelInfos.StandardFieldDisplayName'),
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, $t('common.required')),
),
dependencies: {
show(values: any) {
return !!values?.filedType;
},
triggerFields: ['filedType'],
},
componentProps: (formValues: any) => ({
typeCode: formValues?.filedType ?? null,
disabled: true, // 编辑时禁用
onResolve: (item: any | null) => {
formValues.standardFieldDisplayName = item?.displayText ?? '';
formValues.standardFieldDisplayName = item?.code ?? '';
formValues.standardFieldValueType = (item?.extendedAttribute ?? '')
.toString()
.toUpperCase();
},
placeholder: $t('abp.thingModelInfos.PleaseSelectStandardFieldName'),
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.string().min(1, $t('common.required')),
rules: z.preprocess(
(v) => (v == null ? '' : v),
z.string().min(1, $t('common.required')),
),
componentProps: {
api: getCommonGetSelectList,
params: {
@ -321,30 +326,31 @@ export const editThingModelFormSchema = computed(() => [
typeName: 'StandardThingModelDataTypeEnum',
},
},
labelField: 'value',
valueField: 'value',
optionsPropName: 'options',
immediate: true,
placeholder: $t('abp.thingModelInfos.PleaseSelectStandardFieldValueType'),
allowClear: true,
disabled: 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 [];
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?.toLowerCase() || item.value?.toLowerCase(),
label: item.value, // 显示文本
}));
},
},
},
{
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',