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 @@
>
@@ -21,7 +29,8 @@
\ 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 @@
+
+
+
+
+
+
+
+ {{ item?.name }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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 @@
@@ -21,7 +22,7 @@
showSearch
placeholder="请选择功能"
v-model:value="modelRef.message.functionId"
- @change="onFunctionChange"
+ @change="(val) => onFunctionChange(val, [])"
>
-
+
@@ -60,44 +61,11 @@
-
-
-
-
- {{ item?.name }}
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -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 @@
-
+ />
@@ -108,6 +109,7 @@ const props = defineProps({
},
});
+// save保存deviceDetail
const emits = defineEmits(['save', 'cancel']);
const sceneStore = useSceneStore();
@@ -122,6 +124,7 @@ const modelRef = reactive({
source: '',
relationName: '',
upperKey: '',
+ message: undefined,
});
const list = ref([]);
@@ -160,7 +163,7 @@ const filterTree = (nodes: any[]) => {
if (!nodes?.length) {
return nodes;
}
- return nodes.filter((it) => {
+ const arr = nodes.filter((it) => {
if (
it.children.find(
(item: any) =>
@@ -173,43 +176,16 @@ const filterTree = (nodes: any[]) => {
}
return false;
});
-};
-
-const treeDataFilter = (arr: any[]) => {
- if (Array.isArray(arr) && arr.length) {
- const list: any[] = [];
- arr.map((item: any) => {
- if (item.children) {
- const children = treeDataFilter(item.children);
- if (children.length) {
- list.push({
- ...item,
- title: item.name,
- value: item.id,
- disabled: true,
- children,
- });
- }
- } else {
- if (
- item.children.find(
- (item: any) =>
- item.id.indexOf(
- 'deviceId' || 'device_id' || 'device_Id',
- ) > -1,
- ) &&
- !item.children.find(
- (item: any) => item.id.indexOf('bolaen') > -1,
- )
- ) {
- list.push(item);
- }
- }
- });
- return list;
- } else {
- return [];
- }
+ return arr.map((item) => {
+ if (item.children) {
+ }
+ return {
+ ...item,
+ title: item.name,
+ value: item.id,
+ disabled: !!item.children,
+ };
+ });
};
const sourceChangeEvent = async () => {
@@ -220,11 +196,9 @@ const sourceChangeEvent = async () => {
};
const resp = await queryBuiltInParams(unref(data), _params);
if (resp.status === 200) {
- // const array = filterTree(resp.result as any[]);
+ const array = filterTree(resp.result as any[]);
//判断相同产品才有按变量
// if (props.formProductId === DeviceModel.productId)// TODO
- console.log(array);
- const arr = treeDataFilter(resp.result as any[]);
builtInList.value = array;
}
};
@@ -293,6 +267,7 @@ const filterType = async () => {
};
const onSelectorChange = (val: string) => {
+ modelRef.selectorValues = undefined;
if (val === 'relation') {
queryRelationList();
}
@@ -300,7 +275,17 @@ const onSelectorChange = (val: string) => {
const onDeviceChange = (_detail: any) => {
if (_detail) {
- emits('save', modelRef, _detail);
+ if (_detail.id) {
+ modelRef.deviceId = _detail.id;
+ modelRef.selectorValues = [
+ { value: _detail.id, name: _detail.name },
+ ] as any;
+ modelRef.message = {} as any;
+ } else {
+ modelRef.deviceId = '';
+ modelRef.selectorValues = [] as any;
+ }
+ emits('save', unref(modelRef), _detail);
}
};
@@ -310,7 +295,7 @@ const onRelationChange = (val: any, options: any) => {
modelRef.selectorValues = val;
modelRef.upperKey = 'scene.deviceId';
modelRef.relationName = options.label;
- emits('save', modelRef, {});
+ emits('save', unref(modelRef), {});
};
const onTagChange = (val: any[], arr: any[]) => {
@@ -321,11 +306,12 @@ const onTagChange = (val: any[], arr: any[]) => {
if (arr) {
tagList.value = arr;
}
+ emits('save', unref(modelRef), {});
};
const onVariableChange = (val: any, node: any) => {
modelRef.deviceId = val;
- // modelRef.deviceDetail = node;
+ emits('save', unref(modelRef), node);
modelRef.selectorValues = [{ value: val, name: node.description }] as any;
};
@@ -348,6 +334,21 @@ watch(
deep: true,
},
);
+
+const onFormSave = () => {
+ return new Promise((resolve, reject) => {
+ formRef.value
+ .validate()
+ .then(async (_data: any) => {
+ resolve(_data);
+ })
+ .catch((err: any) => {
+ reject(err);
+ });
+ });
+};
+
+defineExpose({ onFormSave });