完善物模型管理
This commit is contained in:
parent
3f1dc4c6e3
commit
7f3328c8db
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<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 { Select, Divider, Row } from 'ant-design-vue';
|
||||||
import { ChevronLeft, ChevronRight } from '@vben/icons';
|
import { ChevronLeft, ChevronRight } from '@vben/icons';
|
||||||
import { postDataDictionarySelectDetail } from '#/api-client';
|
import { postDataDictionarySelectDetail } from '#/api-client';
|
||||||
@ -27,7 +27,9 @@ const emit = defineEmits<{
|
|||||||
'item-change': [any | null];
|
'item-change': [any | null];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const VNodes = (_: any, { attrs }: any) => attrs.vnodes;
|
const VNodes = (props: any) => {
|
||||||
|
return props.vnodes;
|
||||||
|
};
|
||||||
|
|
||||||
const options = ref<any[]>([]);
|
const options = ref<any[]>([]);
|
||||||
const total = ref(0);
|
const total = ref(0);
|
||||||
@ -57,11 +59,24 @@ const fetchData = async () => {
|
|||||||
} as any,
|
} as any,
|
||||||
});
|
});
|
||||||
const items = Array.isArray(data?.items) ? data!.items : [];
|
const items = Array.isArray(data?.items) ? data!.items : [];
|
||||||
options.value = items.map((item: any) => ({
|
const mappedItems = items.map((item: any) => ({
|
||||||
label: item.displayText,
|
label: `${item.displayText}`,
|
||||||
value: item.code,
|
value: item.code,
|
||||||
...item,
|
...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;
|
total.value = (data as any)?.totalCount || 0;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('获取标准物模型编码失败:', err);
|
console.error('获取标准物模型编码失败:', err);
|
||||||
@ -114,6 +129,18 @@ watch(
|
|||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 监听初始值变化,确保编辑时能正确显示
|
||||||
|
watch(
|
||||||
|
() => props.value,
|
||||||
|
(newValue) => {
|
||||||
|
if (newValue && newValue.trim() !== '' && props.typeCode && !options.value.find(item => item.value === newValue)) {
|
||||||
|
// 如果有值但不在当前选项中,重新获取数据
|
||||||
|
fetchData();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@ -2,20 +2,20 @@
|
|||||||
import type { VbenFormProps } from '#/adapter/form';
|
import type { VbenFormProps } from '#/adapter/form';
|
||||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
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 { 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 { useVbenForm } from '#/adapter/form';
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import {
|
import {
|
||||||
postThingModelInfoPageAsync,
|
|
||||||
postThingModelInfoDeleteAsync,
|
|
||||||
postThingModelInfoCreateAsync,
|
|
||||||
postThingModelInfoUpdateAsync,
|
|
||||||
postThingModelInfoCopyStandardThingModel,
|
postThingModelInfoCopyStandardThingModel,
|
||||||
|
postThingModelInfoCreateAsync,
|
||||||
|
postThingModelInfoDeleteAsync,
|
||||||
|
postThingModelInfoPageAsync,
|
||||||
|
postThingModelInfoUpdateAsync,
|
||||||
} from '#/api-client';
|
} from '#/api-client';
|
||||||
import { TableAction } from '#/components/table-action';
|
import { TableAction } from '#/components/table-action';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
@ -31,14 +31,6 @@ defineOptions({
|
|||||||
name: 'ThingModelInfoModal',
|
name: 'ThingModelInfoModal',
|
||||||
});
|
});
|
||||||
|
|
||||||
// 定义props
|
|
||||||
interface Props {
|
|
||||||
visible?: boolean;
|
|
||||||
productId?: string;
|
|
||||||
productName?: string;
|
|
||||||
ioTPlatform?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
visible: false,
|
visible: false,
|
||||||
productId: '',
|
productId: '',
|
||||||
@ -48,10 +40,18 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
|
|
||||||
// 定义emits
|
// 定义emits
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
close: [];
|
||||||
'update:visible': [value: boolean];
|
'update:visible': [value: boolean];
|
||||||
'close': [];
|
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
// 定义props
|
||||||
|
interface Props {
|
||||||
|
visible?: boolean;
|
||||||
|
productId?: string;
|
||||||
|
productName?: string;
|
||||||
|
ioTPlatform?: string;
|
||||||
|
}
|
||||||
|
|
||||||
const formOptions: VbenFormProps = {
|
const formOptions: VbenFormProps = {
|
||||||
schema: querySchema.value,
|
schema: querySchema.value,
|
||||||
};
|
};
|
||||||
@ -154,11 +154,11 @@ watch(
|
|||||||
try {
|
try {
|
||||||
// 设置表单筛选条件
|
// 设置表单筛选条件
|
||||||
const filterValues: any = {};
|
const filterValues: any = {};
|
||||||
|
|
||||||
if (ioTPlatform) {
|
if (ioTPlatform) {
|
||||||
filterValues.ioTPlatform = ioTPlatform;
|
filterValues.ioTPlatform = ioTPlatform;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (productId) {
|
if (productId) {
|
||||||
filterValues.oneNETProductId = productId;
|
filterValues.oneNETProductId = productId;
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ watch(
|
|||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
// 新增和编辑提交的逻辑
|
// 新增和编辑提交的逻辑
|
||||||
@ -193,16 +193,12 @@ async function submit() {
|
|||||||
const formValues = await formApi.getValues();
|
const formValues = await formApi.getValues();
|
||||||
|
|
||||||
const fetchParams: any = {
|
const fetchParams: any = {
|
||||||
query: {
|
...formValues,
|
||||||
input: {
|
// 自动添加平台和产品信息
|
||||||
...formValues,
|
ioTPlatform: Number.parseInt(props.ioTPlatform) as 1 | 2,
|
||||||
// 自动添加平台和产品信息
|
ioTPlatformProductId: props.productId,
|
||||||
ioTPlatform: parseInt(props.ioTPlatform) as 1 | 2,
|
// 编辑时需要添加ID
|
||||||
ioTPlatformProductId: props.productId,
|
...(isEdit && { id: editRow.value.id }),
|
||||||
// 编辑时需要添加ID
|
|
||||||
...(isEdit && { id: editRow.value.id }),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -284,17 +280,11 @@ function closeModal() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Modal
|
<Modal :open="visible" :title="`${props.ioTPlatform === 1 ? 'CTWing' : 'OneNET'}物模型管理 - ${productName || '产品'}`"
|
||||||
:open="visible"
|
width="90%" :footer="null" @cancel="closeModal" @ok="closeModal"
|
||||||
:title="`物模型管理 - ${productName || '产品'}`"
|
:body-style="{ height: '70vh', overflow: 'hidden' }">
|
||||||
width="90%"
|
<div style="display: flex; flex-direction: column; height: 100%">
|
||||||
:footer="null"
|
<Grid style="flex: 1; overflow: hidden">
|
||||||
@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;">
|
|
||||||
<template #toolbar-actions>
|
<template #toolbar-actions>
|
||||||
<TableAction :actions="[
|
<TableAction :actions="[
|
||||||
{
|
{
|
||||||
@ -315,8 +305,10 @@ function closeModal() {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #isValueNeedConvert="{ row }">
|
<template #isValueNeedConvert="{ row }">
|
||||||
<component :is="h(Tag, { color: row.isValueNeedConvert ? 'blue' : 'default' }, () =>
|
<component :is="h(
|
||||||
row.isValueNeedConvert ? '是' : '否',
|
Tag,
|
||||||
|
{ color: row.isValueNeedConvert ? 'blue' : 'default' },
|
||||||
|
() => (row.isValueNeedConvert ? '是' : '否'),
|
||||||
)
|
)
|
||||||
" />
|
" />
|
||||||
</template>
|
</template>
|
||||||
@ -330,11 +322,12 @@ function closeModal() {
|
|||||||
auth: ['AbpIdentity.Users.Update'],
|
auth: ['AbpIdentity.Users.Update'],
|
||||||
onClick: onEdit.bind(null, row),
|
onClick: onEdit.bind(null, row),
|
||||||
},
|
},
|
||||||
]" :drop-down-actions="[
|
|
||||||
{
|
{
|
||||||
label: $t('common.delete'),
|
label: $t('common.delete'),
|
||||||
icon: 'ant-design:delete-outlined',
|
icon: 'ant-design:delete-outlined',
|
||||||
type: 'primary',
|
type: 'link',
|
||||||
|
size: 'small',
|
||||||
|
auth: ['AbpIdentity.Users.Delete'],
|
||||||
popConfirm: {
|
popConfirm: {
|
||||||
title: $t('common.askConfirmDelete'),
|
title: $t('common.askConfirmDelete'),
|
||||||
confirm: onDel.bind(null, row),
|
confirm: onDel.bind(null, row),
|
||||||
|
|||||||
@ -146,24 +146,18 @@ export const addThingModelFormSchema = computed(() => [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'StandardThingModelCodeSelect',
|
component: 'StandardThingModelCodeSelect',
|
||||||
fieldName: 'standardFieldName',
|
fieldName: 'standardFieldDisplayName',
|
||||||
label: $t('abp.thingModelInfos.StandardFieldName'),
|
label: $t('abp.thingModelInfos.StandardFieldDisplayName'),
|
||||||
rules: z.preprocess(
|
rules: z.preprocess(
|
||||||
(v) => (v == null ? '' : v),
|
(v) => (v == null ? '' : v),
|
||||||
z.string().min(1, $t('common.required')),
|
z.string().min(1, $t('common.required')),
|
||||||
),
|
),
|
||||||
dependencies: {
|
|
||||||
show(values: any) {
|
|
||||||
return !!values?.filedType;
|
|
||||||
},
|
|
||||||
triggerFields: ['filedType'],
|
|
||||||
},
|
|
||||||
componentProps: (formValues: any) => ({
|
componentProps: (formValues: any) => ({
|
||||||
// 传入联动的类型编码(运行时具体值)
|
// 传入联动的类型编码(运行时具体值)
|
||||||
typeCode: formValues?.filedType ?? null,
|
typeCode: formValues?.filedType ?? null,
|
||||||
onResolve: (item: any | null) => {
|
onResolve: (item: any | null) => {
|
||||||
// 选择后自动回填:名称=displayText,值类型=extendedAttribute(转大写)
|
// 选择后自动回填:名称=displayText,值类型=extendedAttribute(转大写)
|
||||||
formValues.standardFieldDisplayName = item?.displayText ?? '';
|
formValues.standardFieldName = item?.code ?? '';
|
||||||
formValues.standardFieldValueType = (item?.extendedAttribute ?? '')
|
formValues.standardFieldValueType = (item?.extendedAttribute ?? '')
|
||||||
.toString()
|
.toString()
|
||||||
.toUpperCase();
|
.toUpperCase();
|
||||||
@ -172,6 +166,20 @@ export const addThingModelFormSchema = computed(() => [
|
|||||||
$t('common.pleaseSelect') + $t('abp.thingModelInfos.StandardFieldName'),
|
$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',
|
component: 'ApiSelect',
|
||||||
fieldName: 'standardFieldValueType',
|
fieldName: 'standardFieldValueType',
|
||||||
@ -209,21 +217,7 @@ export const addThingModelFormSchema = computed(() => [
|
|||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
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',
|
component: 'Switch',
|
||||||
fieldName: 'isValueNeedConvert',
|
fieldName: 'isValueNeedConvert',
|
||||||
@ -253,10 +247,11 @@ export const editThingModelFormSchema = computed(() => [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
labelField: 'value',
|
labelField: 'value',
|
||||||
valueField: 'value',
|
valueField: 'key',
|
||||||
optionsPropName: 'options',
|
optionsPropName: 'options',
|
||||||
immediate: true,
|
immediate: true,
|
||||||
placeholder: $t('abp.thingModelInfos.PleaseSelectFiledType'),
|
disabled: true, // 编辑时禁用
|
||||||
|
placeholder: $t('common.pleaseSelect') + $t('abp.thingModelInfos.FiledType'),
|
||||||
afterFetch: (res: any) => {
|
afterFetch: (res: any) => {
|
||||||
// 确保返回的是数组格式
|
// 确保返回的是数组格式
|
||||||
if (Array.isArray(res)) {
|
if (Array.isArray(res)) {
|
||||||
@ -281,39 +276,49 @@ export const editThingModelFormSchema = computed(() => [
|
|||||||
z.string().min(1, $t('common.required')),
|
z.string().min(1, $t('common.required')),
|
||||||
),
|
),
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: $t('abp.thingModelInfos.PleaseInputIoTPlatformRawFieldName'),
|
// disabled: true, // 编辑时禁用
|
||||||
|
placeholder: $t('common.pleaseInput') +
|
||||||
|
$t('abp.thingModelInfos.IoTPlatformRawFieldName'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'StandardThingModelCodeSelect',
|
component: 'StandardThingModelCodeSelect',
|
||||||
fieldName: 'standardFieldName',
|
fieldName: 'standardFieldDisplayName',
|
||||||
label: $t('abp.thingModelInfos.StandardFieldName'),
|
label: $t('abp.thingModelInfos.StandardFieldDisplayName'),
|
||||||
rules: z.preprocess(
|
rules: z.preprocess(
|
||||||
(v) => (v == null ? '' : v),
|
(v) => (v == null ? '' : v),
|
||||||
z.string().min(1, $t('common.required')),
|
z.string().min(1, $t('common.required')),
|
||||||
),
|
),
|
||||||
dependencies: {
|
|
||||||
show(values: any) {
|
|
||||||
return !!values?.filedType;
|
|
||||||
},
|
|
||||||
triggerFields: ['filedType'],
|
|
||||||
},
|
|
||||||
componentProps: (formValues: any) => ({
|
componentProps: (formValues: any) => ({
|
||||||
typeCode: formValues?.filedType ?? null,
|
typeCode: formValues?.filedType ?? null,
|
||||||
|
disabled: true, // 编辑时禁用
|
||||||
onResolve: (item: any | null) => {
|
onResolve: (item: any | null) => {
|
||||||
formValues.standardFieldDisplayName = item?.displayText ?? '';
|
formValues.standardFieldDisplayName = item?.code ?? '';
|
||||||
formValues.standardFieldValueType = (item?.extendedAttribute ?? '')
|
formValues.standardFieldValueType = (item?.extendedAttribute ?? '')
|
||||||
.toString()
|
.toString()
|
||||||
.toUpperCase();
|
.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',
|
component: 'ApiSelect',
|
||||||
fieldName: 'standardFieldValueType',
|
fieldName: 'standardFieldValueType',
|
||||||
label: $t('abp.thingModelInfos.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: {
|
componentProps: {
|
||||||
api: getCommonGetSelectList,
|
api: getCommonGetSelectList,
|
||||||
params: {
|
params: {
|
||||||
@ -321,30 +326,31 @@ export const editThingModelFormSchema = computed(() => [
|
|||||||
typeName: 'StandardThingModelDataTypeEnum',
|
typeName: 'StandardThingModelDataTypeEnum',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
labelField: 'value',
|
|
||||||
valueField: 'value',
|
|
||||||
optionsPropName: 'options',
|
optionsPropName: 'options',
|
||||||
immediate: true,
|
immediate: true,
|
||||||
placeholder: $t('abp.thingModelInfos.PleaseSelectStandardFieldValueType'),
|
allowClear: true,
|
||||||
|
disabled: true, // 编辑时禁用
|
||||||
|
placeholder: $t('common.pleaseSelect') +
|
||||||
|
$t('abp.thingModelInfos.StandardFieldValueType'),
|
||||||
afterFetch: (res: any) => {
|
afterFetch: (res: any) => {
|
||||||
if (Array.isArray(res)) return res;
|
let items = [];
|
||||||
if (res && Array.isArray(res.items)) return res.items;
|
if (Array.isArray(res)) {
|
||||||
if (res && Array.isArray(res.data)) return res.data;
|
items = res;
|
||||||
return [];
|
} 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',
|
component: 'Switch',
|
||||||
fieldName: 'isValueNeedConvert',
|
fieldName: 'isValueNeedConvert',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user