feat: 新增子设备绑定
This commit is contained in:
parent
a8fd7232eb
commit
02cb643d8c
|
@ -178,6 +178,8 @@ const handleClick = async () => {
|
|||
_emits('save');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
message.error('暂无对应属性的映射');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<a-spin :spinning="loading" v-if="_metadata">
|
||||
<a-spin :spinning="loading" v-if="_metadata.length">
|
||||
<a-card :bordered="false">
|
||||
<template #title>
|
||||
<TitleComponent data="点位映射"></TitleComponent>
|
||||
|
@ -7,7 +7,7 @@
|
|||
<template #extra>
|
||||
<a-space>
|
||||
<a-button @click="showModal">批量映射</a-button>
|
||||
<a-button type="primary" @click="onSave">保存</a-button>
|
||||
<a-button type="primary" @click="onSave">保存并应用</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
<a-form ref="formRef" :model="modelRef">
|
||||
|
@ -114,7 +114,7 @@
|
|||
/>
|
||||
</a-spin>
|
||||
<a-card v-else>
|
||||
<JEmpty description="暂无数据,请配置物模型" style="margin: 10% 0" />
|
||||
<JEmpty description="暂无数据,请配置物模型" style="margin: 10% 0" />
|
||||
</a-card>
|
||||
</template>
|
||||
|
||||
|
@ -174,7 +174,7 @@ const form = ref();
|
|||
const filterOption = (input: string, option: any) => {
|
||||
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
|
||||
};
|
||||
const props = defineProps(['productList']);
|
||||
const props = defineProps(['productList']);
|
||||
const _emit = defineEmits(['close']);
|
||||
const instanceStore = useInstanceStore();
|
||||
let _metadata = ref();
|
||||
|
@ -203,31 +203,33 @@ const getChannel = async () => {
|
|||
|
||||
const handleSearch = async () => {
|
||||
loading.value = true;
|
||||
modelRef.dataSource = _metadata;
|
||||
getChannel();
|
||||
if (_metadata && _metadata.length) {
|
||||
const resp: any = await getEdgeMap(instanceStore.current?.orgId || '', {
|
||||
deviceId: instanceStore.current.id,
|
||||
query: {},
|
||||
}).catch(() => {
|
||||
modelRef.dataSource = _metadata;
|
||||
loading.value = false;
|
||||
});
|
||||
if (resp.status === 200) {
|
||||
const array = resp.result?.[0].reduce((x: any, y: any) => {
|
||||
const metadataId = _metadata.find(
|
||||
(item: any) => item.metadataId === y.metadataId,
|
||||
);
|
||||
if (metadataId) {
|
||||
Object.assign(metadataId, y);
|
||||
} else {
|
||||
x.push(y);
|
||||
}
|
||||
return x;
|
||||
}, _metadata);
|
||||
modelRef.dataSource = array;
|
||||
}
|
||||
}
|
||||
modelRef.dataSource = _metadata.value;
|
||||
console.log(modelRef.dataSource);
|
||||
// if (_metadata.value && _metadata.value.length) {
|
||||
// console.log(1234);
|
||||
// const resp: any = await getEdgeMap(instanceStore.current?.orgId || '', {
|
||||
// deviceId: instanceStore.current.id,
|
||||
// query: {},
|
||||
// }).catch(() => {
|
||||
// modelRef.dataSource = _metadata;
|
||||
// loading.value = false;
|
||||
// });
|
||||
// if (resp.status === 200) {
|
||||
// const array = resp.result?.[0].reduce((x: any, y: any) => {
|
||||
// const metadataId = _metadata.find(
|
||||
// (item: any) => item.metadataId === y.metadataId,
|
||||
// );
|
||||
// if (metadataId) {
|
||||
// Object.assign(metadataId, y);
|
||||
// } else {
|
||||
// x.push(y);
|
||||
// }
|
||||
// return x;
|
||||
// }, _metadata);
|
||||
// modelRef.dataSource = array;
|
||||
// }
|
||||
// }
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
|
@ -251,17 +253,13 @@ const onPatchBind = () => {
|
|||
visible.value = false;
|
||||
_emit('close');
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
handleSearch();
|
||||
});
|
||||
|
||||
watchEffect(() => {
|
||||
if (instanceStore.current?.metadata) {
|
||||
_metadata.value = instanceStore.current?.metadata;
|
||||
} else {
|
||||
_metadata.value = {};
|
||||
}
|
||||
handleSearch();
|
||||
});
|
||||
const onSave = async () => {
|
||||
form.value = await validate();
|
||||
|
|
|
@ -70,9 +70,61 @@ const getProductList = async () => {
|
|||
});
|
||||
if (res.status === 200) {
|
||||
productList.value = res.result;
|
||||
if (props.childData?.id) {
|
||||
current.value.parentId = props.childData.id;
|
||||
form.name = props.childData?.name;
|
||||
form.productId = props.childData?.productId;
|
||||
selectChange(form.productId);
|
||||
if (current.value.metadata) {
|
||||
const metadata = current.value.metadata;
|
||||
if (metadata && metadata.length !== 0) {
|
||||
getEdgeMap(current.value.id, {
|
||||
deviceId: props.childData.id,
|
||||
query: {},
|
||||
}).then((res) => {
|
||||
if (res.status === 200) {
|
||||
// console.log(res.result)
|
||||
//合并物模型
|
||||
const array = res.result[0]?.reduce(
|
||||
(x: any, y: any) => {
|
||||
const metadataId = metadata.find(
|
||||
(item: any) =>
|
||||
item.metadataId === y.metadataId,
|
||||
);
|
||||
if (metadataId) {
|
||||
Object.assign(metadataId, y);
|
||||
} else {
|
||||
x.push(y);
|
||||
}
|
||||
return x;
|
||||
},
|
||||
metadata,
|
||||
);
|
||||
//删除物模型
|
||||
const items = array.filter(
|
||||
(item: any) => item.metadataName,
|
||||
);
|
||||
current.value.metadata = items;
|
||||
const delList = array
|
||||
.filter((a: any) => !a.metadataName)
|
||||
.map((b: any) => b.id);
|
||||
//删除后解绑
|
||||
if (delList && delList.length !== 0) {
|
||||
removeEdgeMap(current.value.id, {
|
||||
deviceId: props.childData.id,
|
||||
idList: [...delList],
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
visible.value = true;
|
||||
} else {
|
||||
current.value.parentId = '';
|
||||
}
|
||||
}
|
||||
};
|
||||
getProductList();
|
||||
const selectChange = (e: any) => {
|
||||
if (e) {
|
||||
visible.value = true;
|
||||
|
@ -88,64 +140,8 @@ const selectChange = (e: any) => {
|
|||
);
|
||||
current.value.metadata = array;
|
||||
};
|
||||
watchEffect(() => {
|
||||
if (props.childData?.id) {
|
||||
current.value.parentId = props.childData.id;
|
||||
form.name = props.childData?.name;
|
||||
form.productId = props.childData?.productId;
|
||||
if (props.childData.deriveMetadata) {
|
||||
const metadata = JSON.parse(
|
||||
props.childData?.deriveMetadata || {},
|
||||
)?.properties?.map((item: any) => ({
|
||||
metadataId: item.id,
|
||||
metadataName: `${item.name}(${item.id})`,
|
||||
metadataType: 'property',
|
||||
name: item.name,
|
||||
}));
|
||||
if (metadata && metadata.length !== 0) {
|
||||
getEdgeMap(current.value.id, {
|
||||
deviceId: props.childData.id,
|
||||
query: {},
|
||||
}).then((res) => {
|
||||
if (res.status === 200) {
|
||||
// console.log(res.result)
|
||||
//合并物模型
|
||||
const array = res.result[0]?.reduce(
|
||||
(x: any, y: any) => {
|
||||
const metadataId = metadata.find(
|
||||
(item: any) =>
|
||||
item.metadataId === y.metadataId,
|
||||
);
|
||||
if (metadataId) {
|
||||
Object.assign(metadataId, y);
|
||||
} else {
|
||||
x.push(y);
|
||||
}
|
||||
return x;
|
||||
},
|
||||
metadata,
|
||||
);
|
||||
//删除物模型
|
||||
const items = array.filter(
|
||||
(item: any) => item.metadataName,
|
||||
);
|
||||
current.value.metadata = items;
|
||||
const delList = array
|
||||
.filter((a: any) => !a.metadataName)
|
||||
.map((b: any) => b.id);
|
||||
//删除后解绑
|
||||
if (delList && delList.length !== 0) {
|
||||
removeEdgeMap(current.value.id, {
|
||||
deviceId: props.childData.id,
|
||||
idList: [...delList],
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
visible.value = true;
|
||||
}
|
||||
onMounted(() => {
|
||||
getProductList();
|
||||
});
|
||||
|
||||
const validate = async () => {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<SaveChild
|
||||
v-if="childVisible"
|
||||
@close-child-save="closeChildSave"
|
||||
:childData="current"
|
||||
:childData="_current"
|
||||
/>
|
||||
<div v-else>
|
||||
<Search
|
||||
|
@ -43,7 +43,7 @@
|
|||
"
|
||||
hasPermission="device/Instance:update"
|
||||
@click="
|
||||
current = {};
|
||||
_current = {};
|
||||
childVisible = true;
|
||||
"
|
||||
>新增并绑定</PermissionButton
|
||||
|
@ -123,7 +123,7 @@ import { usePermissionStore } from '@/store/permission';
|
|||
import SaveChild from './SaveChild/index.vue';
|
||||
|
||||
const instanceStore = useInstanceStore();
|
||||
const { detail } = storeToRefs(instanceStore);
|
||||
const { detail } = storeToRefs(instanceStore);
|
||||
const router = useRouter();
|
||||
const childVisible = ref(false);
|
||||
const permissionStore = usePermissionStore();
|
||||
|
@ -139,7 +139,7 @@ const childDeviceRef = ref<Record<string, any>>({});
|
|||
const params = ref<Record<string, any>>({});
|
||||
const _selectedRowKeys = ref<string[]>([]);
|
||||
const visible = ref<boolean>(false);
|
||||
const current = ref({});
|
||||
const _current = ref({});
|
||||
|
||||
const columns = [
|
||||
{
|
||||
|
@ -252,7 +252,7 @@ const getActions = (data: Partial<Record<string, any>>): ActionsType[] => {
|
|||
},
|
||||
icon: 'EditOutlined',
|
||||
onClick: () => {
|
||||
current.value = data;
|
||||
_current.value = data;
|
||||
childVisible.value = true;
|
||||
},
|
||||
},
|
||||
|
|
|
@ -202,6 +202,7 @@ const handleSearch = async () => {
|
|||
metadataType: 'property',
|
||||
name: item.name,
|
||||
}));
|
||||
console.log(metadata);
|
||||
if (_metadata && _metadata.length) {
|
||||
const resp: any = await getEdgeMap(instanceStore.current?.parentId || '', {
|
||||
deviceId: instanceStore.current.id,
|
||||
|
|
|
@ -80,10 +80,6 @@
|
|||
</template>
|
||||
<template #actions="item">
|
||||
<PermissionButton
|
||||
v-if="
|
||||
item.key != 'tigger' ||
|
||||
slotProps.sceneTriggerType == 'manual'
|
||||
"
|
||||
:disabled="item.disabled"
|
||||
:popConfirm="item.popConfirm"
|
||||
:tooltip="{ ...item.tootip }"
|
||||
|
@ -146,10 +142,6 @@
|
|||
:key="i.key"
|
||||
>
|
||||
<PermissionButton
|
||||
v-if="
|
||||
i.key != 'tigger' ||
|
||||
slotProps.sceneTriggerType == 'manual'
|
||||
"
|
||||
:disabled="i.disabled"
|
||||
:popConfirm="i.popConfirm"
|
||||
:tooltip="{
|
||||
|
@ -439,7 +431,9 @@ const getActions = (
|
|||
icon: 'DeleteOutlined',
|
||||
},
|
||||
];
|
||||
return actions;
|
||||
return actions.filter((item)=>
|
||||
item.key != 'tigger' || data.sceneTriggerType == 'manual'
|
||||
);
|
||||
};
|
||||
const add = () => {
|
||||
menuStory.jumpPage('rule-engine/Alarm/Configuration/Save');
|
||||
|
|
Loading…
Reference in New Issue