fix: 修改场景联动

This commit is contained in:
100011797 2023-03-29 18:56:23 +08:00
parent ad64371a04
commit d4dbc450ea
11 changed files with 99 additions and 38 deletions

View File

@ -73,15 +73,21 @@
style="margin-top: 50px"
>
<template #description>
<template v-if="!isPermission"
>暂无权限, 请联系管理员</template
>
<template v-else>
暂无数据请先
<PermissionButton
<j-button
type="link"
style="padding: 0"
hasPermission="link/AccessConfig:add"
@click="handleAdd"
>
添加{{ providerType[props.channel] }}接入网关
</PermissionButton>
添加{{
providerType[props.channel]
}}接入网关
</j-button>
</template>
</template>
</j-empty>
<div
@ -166,9 +172,11 @@ import DeviceApi from '@/api/media/device';
import { getImage } from '@/utils/comm';
import { gatewayType } from '@/views/media/Device/typings';
import { providerType } from '../const';
import { useMenuStore } from '@/store/menu';
import { usePermissionStore } from '@/store/permission';
const menuStory = useMenuStore();
const isPermission = usePermissionStore().hasPermission(
'link/AccessConfig:add',
);
type Emits = {
(e: 'update:visible', data: boolean): void;

View File

@ -1,6 +1,5 @@
<template>
<ParamsDropdown
placeholder="请选择"
:options="handleOptions"
:tabsOptions="tabOptions"
:metricOptions="upperOptions"
@ -10,7 +9,7 @@
valueName="id"
>
<template v-slot="{ label }">
<j-input :value="label" readonly />
<j-input :value="label" readonly placeholder="请选择" />
</template>
</ParamsDropdown>
</template>

View File

@ -113,9 +113,10 @@ const deleteItem = (_index: number) => {
};
const onTypeSelect = (key: any, _index: number) => {
const indexItem = tagList[_index];
const indexItem = tagList.value[_index];
indexItem.type = key;
tagList.value[_index] = indexItem;
onValueChange()
};
const onTagSelect = (_data: any, _index: number) => {
@ -127,6 +128,7 @@ const onTagSelect = (_data: any, _index: number) => {
handleItem({ ..._data, value: undefined, type: indexType }),
);
tagList.value = newList;
onValueChange()
};
watch(
@ -173,7 +175,7 @@ const onValueChange = () => {
const newValue = _data.map((item: any) => {
return {
column: item.id,
type: item?.valueType,
type: item?.type,
value: item?.value,
};
});
@ -181,10 +183,21 @@ const onValueChange = () => {
emits('change', [{ value: newValue, name: '标签' }], _data);
};
// onMounted(() => {
// // console.log(tagList.value, props.tagData, props.value)
// // emits('change', props.value, _data);
// })
onMounted(() => {
if(props.value?.[0]?.value){
const arr: any[] = []
props.value?.[0]?.value.map((item: any) => {
const _item = props.tagData.find(i => i.id === item.column)
if(_item){
arr.push({
..._item,
...item,
})
}
})
emits('change', props.value, arr);
}
})
</script>
<style lang="less" scoped>

View File

@ -31,7 +31,7 @@
/>
</j-form-item>
<j-form-item
v-else-if="modelRef.selector === 'tag'"
v-else-if="modelRef.selector === 'tag' && isTags"
name="selectorValues"
:rules="[{ required: true, message: '请选择标签' }]"
>
@ -80,6 +80,7 @@ import Tag from './Tag.vue';
import RelationSelect from './RelationSelect.vue';
import { getParams } from '../../../util';
import { handleParamsData } from '../../../components/Terms/util';
import _ from 'lodash';
const props = defineProps({
values: {
@ -107,6 +108,11 @@ const props = defineProps({
},
});
// option
const isTags = computed(() => {
return _.map(list.value, 'value').includes('tag');
});
// savedeviceDetail
const emits = defineEmits(['save', 'cancel']);
@ -281,17 +287,10 @@ const onTagChange = (val: any[], arr: any[]) => {
modelRef.source = 'fixed';
}
const tagName = arr.map((i, _index) => {
return `${_index !== 0 && _index !== (arr || []).length && i.type}${
i.name
}为${i.value}`;
const _type = (_index !== 0 && _index !== (arr || []).length && i.type) ? (i.type === 'and' ? '并且' : '或者') : '';
return `${_type}${i.name}${i.value}`;
});
console.log(tagName)
emits(
'save',
unref(modelRef),
{},
arr ? { tagName: tagName.join('') } : {},
);
emits('save', unref(modelRef), { tagName: tagName.join('') });
};
const onVariableChange = (val: any, node: any) => {
@ -315,7 +314,7 @@ watch(
() => props.productDetail,
async (newVal) => {
await sourceChangeEvent();
if (newVal) {
if (newVal?.id) {
filterType(newVal);
}
},

View File

@ -72,6 +72,7 @@ import { onlyMessage } from '@/utils/comm';
import { useSceneStore } from '@/store/scene';
import { storeToRefs } from 'pinia';
import { isActionChange } from '../../util';
const sceneStore = useSceneStore();
const { data } = storeToRefs(sceneStore);
@ -173,11 +174,17 @@ const onSave = (_data: any) => {
const onProductChange = (_val: any, bol: boolean) => {
if (!bol) {
DeviceModel.selectorValues = undefined;
const flag = isActionChange(
JSON.parse(_val.metadata || '{}'),
DeviceModel?.message,
);
if (!flag) {
DeviceModel.message = {
messageType: 'INVOKE_FUNCTION',
};
}
productDetail.value = _val
}
productDetail.value = _val;
DeviceOptions.value.productName = _val?.name;
};

View File

@ -12,7 +12,8 @@ type DeviceModelType = {
message: {
properties?: any;
messageType: string;
inputs?: any[]
inputs?: any[];
functionId?: string;
}
}

View File

@ -16,6 +16,7 @@
}"
:params="params"
:gridColumn="2"
:noPagination="true"
:rowSelection="{
selectedRowKeys: _selectedRowKeys,
onChange: onSelectChange,

View File

@ -52,6 +52,7 @@
/>
</j-form-item>
</j-form>
<j-empty v-else style="margin: 20px 0" description="暂无模板变量" />
</template>
<script lang="ts" setup>

View File

@ -203,11 +203,11 @@ const onCancel = () => {
emit('cancel');
};
const onOk = async () => {
let _data = undefined
let _data = null
if(variable.value.length){
_data = await variableRef.value.onSave()
}
formModel.variables = _data || [];
formModel.variables = _data;
const { options, ...extra } = formModel;
emit('save', { ...extra }, { ...options });
};

View File

@ -66,7 +66,9 @@ const save = async () => {
if (formData) {
loading.value = true
const branches = data.value.branches?.filter(item => item)
const resp = await modify(data.value.id!, { ...data.value, branches }).then(res => res)
const resp: any = await modify(data.value.id!, { ...data.value, branches }).then(res => res).catch(() => {
loading.value = false
})
loading.value = false
if (resp.success) {
menuStore.jumpPage('rule-engine/Scene')

View File

@ -121,3 +121,33 @@ export const EventEmitter = {
return this
}
}
export const isActionChange = (_metadata: any, _message: any) => {
const _properties = _metadata?.properties || [];
const _functions = _metadata?.functions || [];
if (
_message?.messageType === 'READ_PROPERTY' &&
_message?.properties?.[0]
) {
const _item = _properties.find(
(i: any) => i.id === _message?.properties?.[0],
);
return _item?.id;
} else if (
_message?.messageType === 'INVOKE_FUNCTION' &&
_message?.functionId
) {
const _item = _functions.find(
(i: any) => i.id === _message?.functionId,
);
return _item?.id;
} else if (_message?.messageType === 'WRITE_PROPERTY') {
const _data = Object.keys(_message?.properties)?.[0]
if (_data) {
const _item = _functions.find((i: any) => i.id === _data);
return _item?.id;
}
return false;
}
return false;
};