fix: 修改执行动作设备输出-内置参数

This commit is contained in:
100011797 2023-03-16 17:53:26 +08:00
parent 51fa8e6b5e
commit 6e5817a27e
12 changed files with 209 additions and 141 deletions

View File

@ -7,7 +7,7 @@
:pagination="false"
>
<template #bodyCell="{ column, text, record }">
<div style="width: 280px">
<div>
<template v-if="['valueType', 'name'].includes(column.dataIndex)">
<span>{{ text }}</span>
</template>

View File

@ -214,7 +214,7 @@ defineExpose({ saveBtn });
<style lang="less" scoped>
.function {
padding: 15px;
padding: 24px 15px 0 15px;
background-color: #e7eaec;
}
</style>

View File

@ -30,7 +30,7 @@
<j-col :span="8">
<div class="right-log">
<TitleComponent data="日志" />
<div :style="{ marginTop: '10px' }">
<div class="right-log-box">
<template v-if="logList.length">
<Log
v-for="item in logList"
@ -38,7 +38,9 @@
:key="item.key"
/>
</template>
<j-empty v-else />
<div v-else class="right-log-box-empty">
<j-empty />
</div>
</div>
</div>
</j-col>
@ -187,8 +189,21 @@ onUnmounted(() => {
padding-left: 20px;
border-left: 1px solid rgba(0, 0, 0, 0.09);
overflow: hidden;
max-height: 600px;
height: 100%;
overflow-y: auto;
min-height: 400px;
.right-log-box {
padding-top: 10px;
height: calc(100% - 40px);
width: 100%;
.right-log-box-empty {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
}
}
</style>

View File

@ -36,10 +36,10 @@
placeholder="请选择"
:options="handleOptions"
:tabsOptions="tabOptions"
:metricOption="upperOptions"
:metricOptions="upperOptions"
v-model:value="propertyModelRef.propertiesValue"
v-model:source="propertyModelRef.source"
@change="onValueChange"
@select="onValueChange"
>
<template v-slot="{ label }">
<j-input :value="label" />

View File

@ -52,7 +52,7 @@
<j-select
showSearch
placeholder="请选择属性"
v-model:value="modelRef.message.properties"
v-model:value="modelRef.message.properties[0]"
>
<j-select-option
v-for="item in metadata?.properties || []"
@ -80,9 +80,9 @@ 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';
import { getParams } from '../../../util'
const sceneStore = useSceneStore();
const { data } = storeToRefs(sceneStore);
@ -121,7 +121,7 @@ const props = defineProps({
type: Number,
default: 0,
},
branchGroup: {
branchesName: {
type: Number,
default: 0,
},
@ -131,7 +131,7 @@ const formRef = ref();
const modelRef = reactive({
message: {
messageType: undefined,
messageType: 'INVOKE_FUNCTION',
functionId: undefined,
properties: undefined,
inputs: [],
@ -166,7 +166,7 @@ const _property = computed(() => {
Object.keys(modelRef.message.properties || {})?.[0] === item.id
);
}
return modelRef.message?.properties === item.id;
return modelRef.message?.properties?.[0] === item.id;
});
return _item;
});
@ -178,18 +178,26 @@ const _function = computed(() => {
return _item;
});
const onMessageTypeChange = (val: string) => {
if (['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(val)) {
const queryBuiltIn = async () => {
const _params = {
branch: props.thenName,
branchGroup: props.branchGroup,
branchGroup: props.branchesName,
action: props.name - 1,
};
queryBuiltInParams(unref(data), _params).then((res: any) => {
if (res.status === 200) {
builtInList.value = res.result;
}
});
const _data = await getParams(_params, unref(data));
builtInList.value = _data
};
const onMessageTypeChange = (val: string) => {
const flag = ['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(val)
modelRef.message = {
messageType: val,
functionId: undefined,
properties:(flag ? undefined : []) as any,
inputs: [],
};
if (flag) {
queryBuiltIn();
}
};
@ -223,10 +231,9 @@ watch(
(newVal) => {
if (newVal?.messageType) {
modelRef.message = newVal;
if (newVal.messageType === 'READ_PROPERTY') {
modelRef.message.properties = newVal.properties?.[0];
if (['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(newVal.messageType)) {
queryBuiltIn();
}
onMessageTypeChange(newVal.messageType);
}
},
{ immediate: true },
@ -238,18 +245,16 @@ const onFormSave = () => {
.validate()
.then((_data: any) => {
//
const _properties = _data.message.properties || modelRef.message.properties
const obj = {
message: {
...modelRef.message,
..._data.message,
properties: _data.message.messageType === 'READ_PROPERTY' ? [_properties] : _properties,
propertiesName:
deviceMessageType.value === 'INVOKE_FUNCTION'
? _function.value?.name
: _property.value?.name,
},
}
};
resolve(obj);
})
.catch((err: any) => {

View File

@ -61,7 +61,7 @@
</j-button>
<j-button
danger
v-if="tagData.length > 1"
v-if="tagList.length > 1"
style="padding: 0 8px"
@click="deleteItem(index)"
>
@ -109,6 +109,7 @@ const addItem = () => {
const deleteItem = (_index: number) => {
tagList.value.splice(_index, 1);
onValueChange();
};
const onTypeSelect = (key: any, _index: number) => {
@ -168,18 +169,15 @@ watch(
);
const onValueChange = () => {
const newValue = tagList.value
.filter((item) => !!item.value)
.map((item: any) => {
const _data = tagList.value.filter((item) => !!item.value);
const newValue = _data.map((item: any) => {
return {
column: item.id,
type: item.type,
value: item.value,
};
});
const arr = newValue
.filter((item) => !!item.value)
.map((item: any) => {
const arr = _data.map((item: any) => {
return {
column: item.name,
type: item.type,
@ -187,7 +185,7 @@ const onValueChange = () => {
};
});
emits('update:value', [{ value: newValue, name: '标签' }]);
emits('change', [{ value: newValue, name: '标签' }], undefined);
emits('change', [{ value: newValue, name: '标签' }], arr);
};
</script>

View File

@ -30,7 +30,10 @@
name="selectorValues"
:rules="[{ required: true, message: '请选择关系' }]"
>
<RelationSelect @change="onRelationChange" v-model:value="modelRef.selectorValues" />
<RelationSelect
@change="onRelationChange"
v-model:value="modelRef.selectorValues"
/>
</j-form-item>
<j-form-item
v-else-if="modelRef.selector === 'tag'"
@ -75,12 +78,13 @@
import { useSceneStore } from '@/store/scene';
import TopCard from './TopCard.vue';
import { storeToRefs } from 'pinia';
import { queryBuiltInParams } from '@/api/rule-engine/scene';
import { getImage } from '@/utils/comm';
import NoticeApi from '@/api/notice/config';
import Device from './Device.vue';
import Tag from './Tag.vue';
import RelationSelect from './RelationSelect.vue'
import RelationSelect from './RelationSelect.vue';
import { getParams } from '../../../util';
import { handleParamsData } from '../../../components/Terms/util';
const props = defineProps({
values: {
@ -95,7 +99,7 @@ const props = defineProps({
type: Number,
default: 0,
},
branchGroup: {
branchesName: {
type: Number,
default: 0,
},
@ -185,15 +189,18 @@ const filterTree = (nodes: any[]) => {
const sourceChangeEvent = async () => {
const _params = {
branch: props.thenName,
branchGroup: props.branchGroup,
branchGroup: props.branchesName,
action: props.name - 1,
};
const resp = await queryBuiltInParams(unref(data), _params);
if (resp.status === 200) {
const array = filterTree(resp.result as any[]);
//
// if (props.formProductId === DeviceModel.productId)// TODO
builtInList.value = [] // array;
const productId =
data.value?.branches?.[props.branchesName].then?.[props.thenName]
?.actions?.[props.name > 0 ? props.name - 1 : 0]?.device?.productId;
if (productId === props.values?.productDetail?.id) {
const _data = await getParams(_params, unref(data));
builtInList.value = handleParamsData(filterTree(_data), 'id');
} else {
builtInList.value = [];
}
};
@ -277,16 +284,13 @@ const onTagChange = (val: any[], arr: any[]) => {
modelRef.deviceId = 'deviceId';
modelRef.source = 'fixed';
}
if (arr) {
tagList.value = arr;
}
emits('save', unref(modelRef), {}, {tagList: tagList.value});
emits('save', unref(modelRef), {}, arr ? { tagList: arr } : {});
};
const onVariableChange = (val: any, node: any) => {
modelRef.deviceId = val;
emits('save', unref(modelRef), node);
modelRef.selectorValues = [{ value: val, name: node.description }] as any;
emits('save', unref(modelRef), node);
};
watchEffect(() => {

View File

@ -29,7 +29,7 @@
v-else-if="current === 1"
:name="name"
:parallel="parallel"
:branchGroup="branchGroup"
:branchesName="branchesName"
:thenName="thenName"
:values="DeviceModel"
@save="onDeviceSave"
@ -38,7 +38,7 @@
<Action
v-else-if="current === 2"
:name="name"
:branchGroup="branchGroup"
:branchesName="branchesName"
:thenName="thenName"
:values="DeviceModel"
ref="actionRef"
@ -91,7 +91,7 @@ const props = defineProps({
type: Number,
default: 0,
},
branchGroup: {
branchesName: {
type: Number,
default: 0,
},
@ -158,7 +158,8 @@ const onSave = (_data: any) => {
columns: [],
otherColumns: [],
};
_options.name = DeviceModel.deviceDetail?.name || DeviceModel.selectorValues?.[0]?.name;
_options.name =
DeviceModel.deviceDetail?.name || DeviceModel.selectorValues?.[0]?.name;
const _type = _data.message.messageType;
if (_type === 'INVOKE_FUNCTION') {
_options.type = '执行';
@ -183,7 +184,14 @@ const onSave = (_data: any) => {
}
}
if (_options.selector === 'tag') {
_options.tagList = DeviceModel.tagList.map((it) => ({
// const arr = _data.map((item: any) => {
// return {
// column: item.name,
// type: item.type,
// value: item.value,
// };
// });
_options.taglist = DeviceModel.tagList.map((it) => ({
name: it.column || it.name,
type: it.type ? (it.type === 'and' ? '并且' : '或者') : '',
value: it.value,
@ -205,11 +213,9 @@ const save = async (step?: number) => {
if (deviceRef.value) {
await deviceRef.value?.onFormSave();
current.value = 2;
} else {
if(DeviceModel.selector === 'fixed' && DeviceModel.selectorValues?.length){
} else if (DeviceModel.selectorValues.length) {
current.value = 2;
}
}
} else {
if (actionRef.value) {
const _data = await actionRef.value?.onFormSave();
@ -233,7 +239,7 @@ const prev = () => {
const saveClick = () => save();
const onDeviceSave = (_data: any, _detail: any, obj?: any) => {
Object.assign(DeviceModel, {..._data, ...obj});
Object.assign(DeviceModel, { ..._data, ...obj });
DeviceModel.deviceDetail = _detail;
};
@ -245,6 +251,28 @@ watch(
detail(newValue.productId).then((resp) => {
if (resp.status === 200) {
DeviceModel.productDetail = resp.result;
if (
DeviceModel.selector === 'tag' &&
DeviceModel.selectorValues[0]?.value
) {
const metadata = JSON.parse(
DeviceModel.productDetail?.metadata || '{}',
);
const tags = metadata.tags || [];
const arr = DeviceModel.selectorValues[0]?.value
.filter((item: any) => !!item.value)
.map((item: any) => {
return {
column:
tags.find(
(i: any) => i.id === item.column,
)?.name || item.column,
type: item.type,
value: item.value,
};
});
DeviceModel.tagList = arr;
}
}
});
}

View File

@ -19,14 +19,16 @@
v-if="data?.executor === 'alarm'"
>
<template v-if="data?.alarm?.mode === 'trigger'">
满足条件后将触发<j-button style="padding: 0;"
满足条件后将触发<j-button
style="padding: 0"
type="link"
@click.stop="triggerVisible = true"
>关联此场景的告警</j-button
>
</template>
<template v-else>
满足条件后将解除<j-button style="padding: 0;"
满足条件后将解除<j-button
style="padding: 0"
type="link"
@click.stop="triggerVisible = true"
>关联此场景的告警</j-button
@ -278,10 +280,16 @@
/>
{{ data?.options?.type }}
<span
v-for="i in data?.options?.taglist || []"
v-for="(i, _index) in data?.options?.taglist ||
[]"
:key="i.value"
>
{{ i.type }}
{{
_index !== 0 &&
_index !==
(data?.options?.taglist || []).length &&
i.type
}}
{{ i.name }}{{ i.value }}
</span>
{{ data?.options?.productName }}
@ -318,26 +326,31 @@
</j-popconfirm>
</div>
<template v-if="!isLast && type === 'serial'">
<div :class='["actions-item-filter-warp", termsOptions.length ? "filter-border" : ""]'>
<template v-if='termsOptions.length'>
<div class='actions-item-filter-warp-tip'>
<div
:class="[
'actions-item-filter-warp',
termsOptions.length ? 'filter-border' : '',
]"
>
<template v-if="termsOptions.length">
<div class="actions-item-filter-warp-tip">
满足此条件后执行后续动作
</div>
<div class='actions-item-filter-overflow'>
<div class="actions-item-filter-overflow">
<FilterGroup
v-for='(item, index) in termsOptions'
:key='item.key'
:branchName='branchesName'
:thenName='thenName'
:actionName='name'
:name='index'
:isLast='index === termsOptions.length - 1'
:isFirst='index === 0'
v-for="(item, index) in termsOptions"
:key="item.key"
:branchName="branchesName"
:thenName="thenName"
:actionName="name"
:name="index"
:isLast="index === termsOptions.length - 1"
:isFirst="index === 0"
/>
</div>
</template>
<div v-else class='filter-add-button'>
<AIcon type='PlusOutlined' style='padding-right: 4px;' />
<div v-else class="filter-add-button">
<AIcon type="PlusOutlined" style="padding-right: 4px" />
<span>添加过滤条件</span>
</div>
</div>
@ -379,8 +392,8 @@ import ActionTypeComponent from '../Modal/ActionTypeComponent.vue';
import TriggerAlarm from '../TriggerAlarm/index.vue';
import { useSceneStore } from '@/store/scene';
import { storeToRefs } from 'pinia';
import { iconMap, itemNotifyIconMap, typeIconMap } from './util'
import FilterGroup from './FilterGroup.vue'
import { iconMap, itemNotifyIconMap, typeIconMap } from './util';
import FilterGroup from './FilterGroup.vue';
const sceneStore = useSceneStore();
const { data: _data } = storeToRefs(sceneStore);
@ -422,11 +435,15 @@ const triggerVisible = ref<boolean>(false);
const actionType = ref('');
const termsOptions = computed(() => {
if (!props.parallel) { //
return _data.value.branches![props.branchesName].then?.[props.thenName].actions?.[props.name].terms || []
if (!props.parallel) {
//
return (
_data.value.branches![props.branchesName].then?.[props.thenName]
.actions?.[props.name].terms || []
);
}
return []
})
return [];
});
const onDelete = () => {
emit('delete');
@ -464,12 +481,14 @@ const onPropsCancel = () => {
actionType.value = '';
};
watch(() => props.data, () => {
watch(
() => props.data,
() => {
if (props.data) {
}
}, { immediate: true, deep: true})
},
{ immediate: true, deep: true },
);
</script>
<style lang="less" scoped>
@ -610,7 +629,7 @@ watch(() => props.data, () => {
row-gap: 16px;
}
.filter-add-button{
.filter-add-button {
width: 100%;
color: rgba(0, 0, 0, 0.3);
text-align: center;

View File

@ -1,7 +1,7 @@
<template>
<div>
<template v-if="actionType === 'device'">
<Device v-bind="props" :value="data?.device" @cancel="onCancel" @save="onPropsOk" :thenName="branchesName" />
<Device v-bind="props" :value="data?.device" @cancel="onCancel" @save="onPropsOk" />
</template>
<template v-else-if="actionType === 'notify'">
<Notify :options="data?.options" :value="data?.notify" @cancel="onCancel" @save="onPropsOk" />
@ -24,7 +24,7 @@ const props = defineProps({
type: Number,
default: 0,
},
branchGroup: {
thenName: {
type: Number,
default: 0,
},

View File

@ -47,7 +47,7 @@ const props = defineProps({
type: Number,
default: 0,
},
branchGroup: {
thenName: {
type: Number,
default: 0,
},

View File

@ -279,7 +279,6 @@ const onChange = (
} else {
_values = getObj(_source, _value, isRelation);
}
console.log(_values, '_values')
emit('update:value', _values);
emit('change', { sendTo: _names.filter((item) => !!item).join(',') });
};