From 0330a7702f9a84c18a56f1e3d44242f3e0b40f74 Mon Sep 17 00:00:00 2001 From: 100011797 <2642441182@qq.com> Date: Thu, 9 Mar 2023 18:25:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9C=BA=E6=99=AF=E8=81=94=E5=8A=A8-?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=8A=A8=E4=BD=9C-=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rule-engine/Scene/Save/Timer/index.vue | 29 +++- .../Save/action/Device/actions/EditTable.vue | 65 ++++++-- .../action/Device/actions/WriteProperty.vue | 140 +++++++++++++++++ .../Save/action/Device/actions/index.vue | 142 ++++++++++-------- .../Save/action/Device/device/Device.vue | 4 +- .../Scene/Save/action/Device/device/index.vue | 89 +++++------ .../Scene/Save/action/Device/index.vue | 112 ++++++++++++-- .../Scene/Save/action/Modal/index.vue | 34 +++-- .../Scene/Save/action/Notify/NotifyConfig.vue | 2 +- .../Save/action/Notify/NotifyTemplate.vue | 2 +- .../Scene/Save/action/Notify/NotifyWay.vue | 13 +- .../Scene/Save/action/Notify/index.vue | 1 - .../rule-engine/Scene/Save/action/index.vue | 59 ++++++-- 13 files changed, 527 insertions(+), 165 deletions(-) create mode 100644 src/views/rule-engine/Scene/Save/action/Device/actions/WriteProperty.vue diff --git a/src/views/rule-engine/Scene/Save/Timer/index.vue b/src/views/rule-engine/Scene/Save/Timer/index.vue index e43a7f45..55646c35 100644 --- a/src/views/rule-engine/Scene/Save/Timer/index.vue +++ b/src/views/rule-engine/Scene/Save/Timer/index.vue @@ -1,18 +1,35 @@ \ No newline at end of file diff --git a/src/views/rule-engine/Scene/Save/action/Device/actions/EditTable.vue b/src/views/rule-engine/Scene/Save/action/Device/actions/EditTable.vue index 6ba31ca4..e0774a9b 100644 --- a/src/views/rule-engine/Scene/Save/action/Device/actions/EditTable.vue +++ b/src/views/rule-engine/Scene/Save/action/Device/actions/EditTable.vue @@ -8,12 +8,20 @@ > \ No newline at end of file diff --git a/src/views/rule-engine/Scene/Save/action/Device/actions/WriteProperty.vue b/src/views/rule-engine/Scene/Save/action/Device/actions/WriteProperty.vue new file mode 100644 index 00000000..b1ed87ed --- /dev/null +++ b/src/views/rule-engine/Scene/Save/action/Device/actions/WriteProperty.vue @@ -0,0 +1,140 @@ + + + \ No newline at end of file diff --git a/src/views/rule-engine/Scene/Save/action/Device/actions/index.vue b/src/views/rule-engine/Scene/Save/action/Device/actions/index.vue index df605d47..5697da00 100644 --- a/src/views/rule-engine/Scene/Save/action/Device/actions/index.vue +++ b/src/views/rule-engine/Scene/Save/action/Device/actions/index.vue @@ -9,6 +9,7 @@ @@ -108,6 +76,13 @@ import { getImage } from '@/utils/comm'; import TopCard from '../device/TopCard.vue'; import { detail } from '@/api/device/instance'; import EditTable from './EditTable.vue'; +import WriteProperty from './WriteProperty.vue'; +import { queryBuiltInParams } from '@/api/rule-engine/scene'; +import { useSceneStore } from '@/store/scene'; +import { storeToRefs } from 'pinia' + +const sceneStore = useSceneStore(); +const { data } = storeToRefs(sceneStore); const TypeList = [ { @@ -172,44 +147,93 @@ const deviceMessageType = computed(() => { return modelRef.message.messageType; }); -const onFunctionChange = (val: string) => { +const builtInList = ref([]); + +const onFunctionChange = (val: string, values?: any[]) => { const _item = (metadata.value?.functions || []).find((item: any) => { return val === item.id; }); const list = (_item?.inputs || []).map((item: any) => { + const _a = values?.find((i) => i.name === item.id); return { id: item.id, - name: item.name, - value: undefined, + value: _a?.value, valueType: item?.valueType?.type, + ..._a, + name: item.name, }; }); modelRef.message.inputs = list; }; -watchEffect(() => { - // console.log(props.values) - // console.log(metadata.value) - // Object.assign() -}); +const onMessageTypeChange = (val: string) => { + if (['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(val)) { + const _params = { + branch: props.thenName, + branchGroup: props.branchGroup, + action: props.name - 1, + }; + queryBuiltInParams(unref(data), _params).then((res: any) => { + if (res.status === 200) { + builtInList.value = res.result + } + }); + } +}; watch( - () => [props.values?.productDetail, props.values.deviceDetail], - ([newVal1, newVal2]) => { - if (newVal1) { - if (props.values?.selector === 'fixed') { - detail(newVal2.id).then((resp) => { - if (resp.status === 200) { - metadata.value = JSON.parse( - resp.result?.metadata || '{}', - ); - } - }); + () => [ + props.values?.productDetail, + props.values.selectorValues, + props.values?.selector, + ], + ([newVal1, newVal2, newVal3]) => { + if (newVal1?.id) { + if (newVal3?.selector === 'fixed') { + const id = newVal2?.[0]?.value; + if (id) { + detail(id).then((resp) => { + if (resp.status === 200) { + metadata.value = JSON.parse( + resp.result?.metadata || '{}', + ); + } + }); + } } else { metadata.value = JSON.parse(newVal1?.metadata || '{}'); } } }, + { immediate: true, deep: true }, +); + +watch( + () => props.values?.message, + (newVal) => { + if (newVal?.messageType) { + modelRef.message = newVal; + if (newVal.messageType === 'INVOKE_FUNCTION' && newVal.functionId) { + onFunctionChange(newVal.functionId, newVal?.inputs); + } + onMessageTypeChange(newVal.messageType) + } + }, { deep: true, immediate: true }, ); + +const onFormSave = () => { + return new Promise((resolve, reject) => { + formRef.value + .validate() + .then(async (_data: any) => { + resolve(_data); + }) + .catch((err: any) => { + reject(err); + }); + }); +}; + +defineExpose({ onFormSave }); \ No newline at end of file diff --git a/src/views/rule-engine/Scene/Save/action/Device/device/Device.vue b/src/views/rule-engine/Scene/Save/action/Device/device/Device.vue index ef3237fb..0dd67d5a 100644 --- a/src/views/rule-engine/Scene/Save/action/Device/device/Device.vue +++ b/src/views/rule-engine/Scene/Save/action/Device/device/Device.vue @@ -1,11 +1,11 @@