fix: 优化设备物模型属性保存

This commit is contained in:
XieYongHong 2023-07-12 11:23:33 +08:00
parent 4da460a703
commit 29b6f02b73
4 changed files with 49 additions and 38 deletions

View File

@ -59,9 +59,9 @@ const formData = reactive<{
value: ValueType;
rangeValue: ValueType;
}>({
value: props.value.range === false ? props.value.value : undefined,
rangeValue: props.value.range === true
? props.value.value || [undefined, undefined]
value: props.value?.range === false ? props.value?.value : undefined,
rangeValue: props.value?.range === true
? props.value?.value || [undefined, undefined]
: [undefined, undefined],
});
@ -69,9 +69,9 @@ const formRef = ref()
const showText = computed(() => {
if (props.value.range === false) {
return props.value.value || ''
return props.value?.value || ''
} else {
return props.value.value?.[0] ? props.value.value.join('-') : ''
return props.value?.value?.[0] ? props.value.value.join('-') : ''
}
})

View File

@ -35,6 +35,7 @@ const useMetadata = (type: 'device' | 'product', key?: MetadataType, ): {
const productMetadata: any = JSON.parse(instanceStore.current.productMetadata)
const metaArray = key ? productMetadata[key] : []
const productIndexKeys = metaArray?.map((item:any, index: number) => index) || []
productNoEdit.value.ids = metaArray?.map((item: any) => item.id) || []
productNoEdit.value.id = productIndexKeys
productNoEdit.value.name = productIndexKeys
if (key === 'properties') {

View File

@ -1,19 +1,19 @@
<template>
<div class='device-detail-metadata' style="position: relative;">
<div class="tips">
<j-tooltip :title="instanceStore.detail?.independentMetadata && type === 'device'
? '该设备已脱离产品物模型,修改产品物模型对该设备无影响'
: '设备会默认继承产品的物模型,修改设备物模型后将脱离产品物模型'">
<div class="ellipsis" style='color: #999;'>
<AIcon type="InfoCircleOutlined" style="margin-right: 3px" />
{{
instanceStore.detail?.independentMetadata && type === 'device'
? '该设备已脱离产品物模型,修改产品物模型对该设备无影响'
: '设备会默认继承产品的物模型,修改设备物模型后将脱离产品物模型'
}}
</div>
</j-tooltip>
</div>
<!-- <div class="tips">-->
<!-- <j-tooltip :title="instanceStore.detail?.independentMetadata && type === 'device'-->
<!-- ? '该设备已脱离产品物模型,修改产品物模型对该设备无影响'-->
<!-- : '设备会默认继承产品的物模型,修改设备物模型后将脱离产品物模型'">-->
<!-- <div class="ellipsis" style='color: #999;'>-->
<!-- <AIcon type="InfoCircleOutlined" style="margin-right: 3px" />-->
<!-- {{-->
<!-- instanceStore.detail?.independentMetadata && type === 'device'-->
<!-- ? '该设备已脱离产品物模型,修改产品物模型对该设备无影响'-->
<!-- : '设备会默认继承产品的物模型,修改设备物模型后将脱离产品物模型'-->
<!-- }}-->
<!-- </div>-->
<!-- </j-tooltip>-->
<!-- </div>-->
<j-tabs class="metadataNav" destroyInactiveTabPane type="card">
<template #rightExtra>
<j-space>

View File

@ -2,10 +2,16 @@ import { saveProductMetadata } from "@/api/device/product";
import { saveMetadata } from "@/api/device/instance";
import type { DeviceInstance } from "../../Instance/typings";
import type { DeviceMetadata, MetadataItem, MetadataType, ProductItem } from "../../Product/typings";
import { differenceBy } from "lodash-es";
const filterProductMetadata = (data: any[], productMetaData: any[]) => {
const ids = productMetaData.map((item: any) => item.id)
const idsSet = new Set(ids)
return data.filter((a) => !idsSet.has(a.id))
}
/**
*
* @param type events
* @param type "events" | "functions" | "properties" | "tags"
* @param item {a},{b},{c}
// * @param target product、device
* @param data product device [{event:[1,2,3]]
@ -21,25 +27,29 @@ import type { DeviceMetadata, MetadataItem, MetadataType, ProductItem } from "..
): ProductItem | DeviceInstance => {
if (!data) return data;
const metadata = JSON.parse(data.metadata || '{}') as DeviceMetadata;
const config = (metadata[type] || []) as MetadataItem[];
if (item.length > 0) {
item.forEach((i) => {
const index = config.findIndex((c) => c.id === i.id);
if (index > -1) {
config[index] = i;
// onEvent?.('update', i);
} else {
config.push(i);
// onEvent?.('add', i);
}
});
} else {
console.warn('未触发物模型修改');
let productMetaData
if ((data as DeviceInstance).productMetadata) {
productMetaData = JSON.parse((data as DeviceInstance).productMetadata)
}
console.log('updateMetadata', config, type)
// @ts-ignore
// metadata[type] = config.sort((a, b) => b?.sortsIndex - a?.sortsIndex);
metadata[type] = item.sort((a, b) => b?.sortsIndex - a?.sortsIndex);
if (productMetaData) {
if (productMetaData.properties && productMetaData.properties.length) {
metadata.properties = filterProductMetadata(metadata.properties, productMetaData.properties)
}
if (productMetaData.functions && productMetaData.functions.length) {
metadata.functions = filterProductMetadata(metadata.functions, productMetaData.functions)
}
if (productMetaData.events && productMetaData.events.length) {
metadata.events = filterProductMetadata(metadata.events, productMetaData.events)
}
if (productMetaData.tags && productMetaData.tags.length) {
metadata.tags = filterProductMetadata(metadata.tags, productMetaData.tags)
}
}
console.log(metadata)
metadata[type] = metadata[type].sort((a, b) => b?.sortsIndex - a?.sortsIndex) as any[]
console.log('updateMetadata',metadata)
data.metadata = JSON.stringify(metadata);
onEvent?.(data.metadata)