fix: 边缘端映射组件替换

This commit is contained in:
100011797 2023-03-16 11:00:04 +08:00
parent 7d10dc3e6e
commit 60751783c2
12 changed files with 493 additions and 282 deletions

View File

@ -1,14 +1,14 @@
<template> <template>
<a-select allowClear v-model:value="_value" @change="onChange" placeholder="请选择" style="width: 100%"> <j-select allowClear v-model:value="_value" @change="onChange" placeholder="请选择" style="width: 100%">
<a-select-option <j-select-option
v-for="item in list" v-for="item in list"
:key="item.id" :key="item.id"
:value="item.id" :value="item.id"
:label="item.name" :label="item.name"
:filter-option="filterOption" :filter-option="filterOption"
>{{ item.name }}</a-select-option >{{ item.name }}</j-select-option
> >
</a-select> </j-select>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>

View File

@ -1,5 +1,5 @@
<template> <template>
<a-modal <j-modal
width="900px" width="900px"
title="批量映射" title="批量映射"
visible visible
@ -10,49 +10,49 @@
<div class="map-tree-top"> <div class="map-tree-top">
采集器的点位名称与属性名称一致时将自动映射绑定有多个采集器点位名称与属性名称一致时以第1个采集器的点位数据进行绑定 采集器的点位名称与属性名称一致时将自动映射绑定有多个采集器点位名称与属性名称一致时以第1个采集器的点位数据进行绑定
</div> </div>
<a-spin :spinning="loading"> <j-spin :spinning="loading">
<div class="map-tree-content"> <div class="map-tree-content">
<a-card class="map-tree-content-card" title="源数据"> <j-card class="map-tree-content-card" title="源数据">
<a-tree <j-tree
checkable checkable
:height="300" :height="300"
:tree-data="dataSource" :tree-data="dataSource"
:checkedKeys="checkedKeys" :checkedKeys="checkedKeys"
@check="onCheck" @check="onCheck"
/> />
</a-card> </j-card>
<div style="width: 100px"> <div style="width: 100px">
<a-button <j-button
:disabled="rightList.length >= leftList.length" :disabled="rightList.length >= leftList.length"
@click="onRight" @click="onRight"
>加入右侧</a-button >加入右侧</j-button
> >
</div> </div>
<a-card class="map-tree-content-card" title="采集器"> <j-card class="map-tree-content-card" title="采集器">
<a-list <j-list
size="small" size="small"
:data-source="rightList" :data-source="rightList"
class="map-tree-content-card-list" class="map-tree-content-card-list"
> >
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <j-list-item>
{{ item.title }} {{ item.title }}
<template #actions> <template #actions>
<a-popconfirm <j-popconfirm
title="确定删除?" title="确定删除?"
@confirm="_delete(item.key)" @confirm="_delete(item.key)"
> >
<AIcon type="DeleteOutlined" /> <AIcon type="DeleteOutlined" />
</a-popconfirm> </j-popconfirm>
</template> </template>
</a-list-item> </j-list-item>
</template> </template>
</a-list> </j-list>
</a-card> </j-card>
</div> </div>
</a-spin> </j-spin>
</div> </div>
</a-modal> </j-modal>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>

View File

@ -1,46 +1,46 @@
<template> <template>
<a-spin :spinning="loading" v-if="metadata.properties.length"> <j-spin :spinning="loading" v-if="metadata.properties.length">
<a-card> <j-card>
<template #extra> <template #extra>
<a-space> <j-space>
<a-button @click="visible = true">批量映射</a-button> <j-button @click="visible = true">批量映射</j-button>
<a-button type="primary" @click="onSave">保存</a-button> <j-button type="primary" @click="onSave">保存</j-button>
</a-space> </j-space>
</template> </template>
<a-form ref="formRef" :model="modelRef"> <j-form ref="formRef" :model="modelRef">
<a-table :dataSource="modelRef.dataSource" :columns="columns"> <j-table :dataSource="modelRef.dataSource" :columns="columns">
<template #headerCell="{ column }"> <template #headerCell="{ column }">
<template v-if="column.key === 'collectorId'"> <template v-if="column.key === 'collectorId'">
采集器 采集器
<a-tooltip title="边缘网关代理的真实物理设备"> <j-tooltip title="边缘网关代理的真实物理设备">
<AIcon type="QuestionCircleOutlined" /> <AIcon type="QuestionCircleOutlined" />
</a-tooltip> </j-tooltip>
</template> </template>
</template> </template>
<template #bodyCell="{ column, record, index }"> <template #bodyCell="{ column, record, index }">
<template v-if="column.dataIndex === 'channelId'"> <template v-if="column.dataIndex === 'channelId'">
<a-form-item <j-form-item
:name="['dataSource', index, 'channelId']" :name="['dataSource', index, 'channelId']"
> >
<a-select <j-select
style="width: 100%" style="width: 100%"
v-model:value="record[column.dataIndex]" v-model:value="record[column.dataIndex]"
placeholder="请选择" placeholder="请选择"
allowClear allowClear
:filter-option="filterOption" :filter-option="filterOption"
> >
<a-select-option <j-select-option
v-for="item in channelList" v-for="item in channelList"
:key="item.value" :key="item.value"
:value="item.value" :value="item.value"
:label="item.label" :label="item.label"
>{{ item.label }}</a-select-option >{{ item.label }}</j-select-option
> >
</a-select> </j-select>
</a-form-item> </j-form-item>
</template> </template>
<template v-if="column.dataIndex === 'collectorId'"> <template v-if="column.dataIndex === 'collectorId'">
<a-form-item <j-form-item
:name="['dataSource', index, 'collectorId']" :name="['dataSource', index, 'collectorId']"
:rules="[ :rules="[
{ {
@ -55,10 +55,10 @@
type="COLLECTOR" type="COLLECTOR"
:edgeId="instanceStore.current.parentId" :edgeId="instanceStore.current.parentId"
/> />
</a-form-item> </j-form-item>
</template> </template>
<template v-if="column.dataIndex === 'pointId'"> <template v-if="column.dataIndex === 'pointId'">
<a-form-item <j-form-item
:name="['dataSource', index, 'pointId']" :name="['dataSource', index, 'pointId']"
:rules="[ :rules="[
{ {
@ -73,33 +73,33 @@
type="POINT" type="POINT"
:edgeId="instanceStore.current.parentId" :edgeId="instanceStore.current.parentId"
/> />
</a-form-item> </j-form-item>
</template> </template>
<template v-if="column.dataIndex === 'id'"> <template v-if="column.dataIndex === 'id'">
<a-badge <j-badge
v-if="record[column.dataIndex]" v-if="record[column.dataIndex]"
status="success" status="success"
text="已绑定" text="已绑定"
/> />
<a-badge v-else status="error" text="未绑定" /> <j-badge v-else status="error" text="未绑定" />
</template> </template>
<template v-if="column.key === 'action'"> <template v-if="column.key === 'action'">
<a-tooltip title="解绑"> <j-tooltip title="解绑">
<a-popconfirm <j-popconfirm
title="确认解绑" title="确认解绑"
:disabled="!record.id" :disabled="!record.id"
@confirm="unbind(record.id)" @confirm="unbind(record.id)"
> >
<a-button type="link" :disabled="!record.id" <j-button type="link" :disabled="!record.id"
><AIcon type="icon-jiebang" ><AIcon type="icon-jiebang"
/></a-button> /></j-button>
</a-popconfirm> </j-popconfirm>
</a-tooltip> </j-tooltip>
</template> </template>
</template> </template>
</a-table> </j-table>
</a-form> </j-form>
</a-card> </j-card>
<PatchMapping <PatchMapping
:deviceId="instanceStore.current.id" :deviceId="instanceStore.current.id"
v-if="visible" v-if="visible"
@ -108,10 +108,10 @@
:metaData="modelRef.dataSource" :metaData="modelRef.dataSource"
:edgeId="instanceStore.current.parentId" :edgeId="instanceStore.current.parentId"
/> />
</a-spin> </j-spin>
<a-card v-else> <j-card v-else>
<JEmpty description='暂无数据,请配置物模型' style="margin: 10% 0" /> <JEmpty description='暂无数据,请配置物模型' style="margin: 10% 0" />
</a-card> </j-card>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>

View File

@ -7,41 +7,31 @@
:pagination="false" :pagination="false"
> >
<template #bodyCell="{ column, text, record }"> <template #bodyCell="{ column, text, record }">
<div> <template v-if="column.dataIndex === 'name'">
<template <span>{{ text }}</span>
v-if="['valueType', 'name'].includes(column.dataIndex)" </template>
> <template v-else-if="column.dataIndex === 'valueType'">
<span>{{ text }}</span> <span>{{ record.valueType.type }}</span>
</template> </template>
<template v-else> <template v-else>
<ParamsDropdown <FunctionItem
placeholder="请选择" :builtInList="builtInList"
:options="[]" @change="onChange"
:tabsOptions="tabOptions" :source="record.source"
:metricOption="upperOptions(record.valueType)" :data="record"
v-model:value="record.value" v-model:value="record.value"
> />
<template v-slot="{label}"> </template>
<j-input :value="label" />
</template>
</ParamsDropdown>
</template>
</div>
</template> </template>
</j-table> </j-table>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { PropType } from 'vue'; import { PropType } from 'vue';
import ParamsDropdown from '../../../components/ParamsDropdown'; import FunctionItem from './FunctionItem.vue';
type Emits = {
(e: 'update:modelValue', data: Record<string, any>[]): void;
};
const _emit = defineEmits<Emits>();
const _props = defineProps({ const _props = defineProps({
modelValue: { value: {
type: Array as PropType<Record<string, any>[]>, type: Array as PropType<Record<string, any>[]>,
default: () => undefined, default: () => undefined,
}, },
@ -49,20 +39,13 @@ const _props = defineProps({
type: Array, type: Array,
default: () => [], default: () => [],
}, },
functions: {
type: Array,
default: () => [],
},
}); });
const tabOptions = [ const emit = defineEmits(['update:value']);
{
label: '手动输入',
component: 'string',
key: 'fixed',
},
{
label: '内置参数',
component: 'tree',
key: 'upper',
},
];
const columns = [ const columns = [
{ {
@ -82,33 +65,29 @@ const columns = [
}, },
]; ];
const dataSource = computed({ const dataSource = ref<any[]>([]);
get: () => {
return _props.modelValue || []; watchEffect(() => {
}, const list = (_props.functions || []).map((item: any) => {
set: (val: any) => { const _item = _props.value?.find((i) => i.name === item?.id) || {};
_emit('update:modelValue', val); return {
}, ...item,
..._item,
name: item.name,
};
});
dataSource.value = list;
}); });
const filterParamsData = (type?: string, data?: any[]): any[] => { const onChange = () => {
if (type && data) { const arr = [...dataSource.value].map((item) => {
return data.filter((item) => { return {
if (item.children) { name: item.id,
const _children = filterParamsData(type, item.children); source: item.source,
item.children = _children; upperKey: item.upperKey || item.value,
return _children.length ? true : false; value: item.value,
} else if (item.type === type) { };
// optionMap.current.set(item.id, item); });
return true; emit('update:value', arr);
}
return false;
});
}
return data || [];
};
const upperOptions = (_type: string) => {
return filterParamsData(_type, _props?.builtInList) || [];
}; };
</script> </script>

View File

@ -0,0 +1,117 @@
<template>
<ParamsDropdown
placeholder="请选择"
:options="handleOptions"
:tabsOptions="tabOptions"
:metricOptions="upperOptions"
v-model:value="_value"
v-model:source="_source"
@select="onChange"
>
<template v-slot="{ label }">
<j-input :value="label" />
</template>
</ParamsDropdown>
</template>
<script lang="ts" setup>
import ParamsDropdown from '../../../components/ParamsDropdown';
import { handleParamsData } from './index';
const props = defineProps({
data: {
type: Object,
default: () => {},
},
builtInList: {
type: Array,
default: () => [],
},
value: {
type: String,
},
source: {
type: String,
default: 'fixed',
},
});
const emit = defineEmits(['update:value', 'update:source', 'change']);
const _value = ref();
const _source = ref();
const tabOptions = computed(() => {
return [
{
label: '手动输入',
component: props.data?.valueType?.type,
key: 'fixed',
},
{
label: '内置参数',
component: 'tree',
key: 'upper',
},
];
});
const handleOptions = computed(() => {
const _item = props.data?.valueType || 'int';
const _type = _item?.type;
if (_type === 'boolean') {
return [
{
label: _item.trueText || true,
value: _item.trueValue || true,
},
{
label: _item.falseText || false,
value: _item.falseValue || false,
},
];
}
if (_type === 'enum') {
return _item?.elements.map((i: any) => {
return {
label: i.text,
value: i.value,
};
});
}
return [];
});
const filterParamsData = (type?: string, data?: any[]): any[] => {
if (type && data) {
const list = data.filter((item) => {
if (item.children) {
const _children = filterParamsData(type, item.children);
item.children = _children;
return _children.length ? true : false;
} else if (item.type === type) {
// optionMap.current.set(item.id, item);
return true;
}
return false;
});
return handleParamsData(list);
}
return data || [];
};
const upperOptions = computed(() => {
return filterParamsData(props.data.valueType?.type, props?.builtInList);
});
const onChange = () => {
emit('update:value', _value.value);
emit('update:source', _source.value);
emit('change', { source: _source.value, value: _value.value });
};
watchEffect(() => {
_value.value = props.value;
_source.value = props.source || 'fixed';
});
</script>

View File

@ -1,50 +1,59 @@
<template> <template>
<div> <j-form
<j-form :layout="'vertical'" ref="formRef" :model="modelRef"> :layout="'vertical'"
<j-row> ref="propertyFormRef"
<j-col :span="11"> :model="propertyModelRef"
<j-form-item >
:name="['message', 'properties']" <j-row :gutter="24">
label="读取属性" <j-col :span="12">
:rules="[{ required: true, message: '请选择读取属性' }]" <j-form-item
name="properties"
label="读取属性"
:rules="[{ required: true, message: '请选择读取属性' }]"
>
<j-select
showSearch
placeholder="请选择属性"
v-model:value="propertyModelRef.properties"
@change="onChange"
> >
<j-select <j-select-option
showSearch v-for="item in metadata?.properties || []"
placeholder="请选择属性" :value="item?.id"
v-model:value="modelRef.properties" :key="item?.id"
>{{ item?.name }}</j-select-option
> >
<j-select-option </j-select>
v-for="item in metadata?.properties || []" </j-form-item>
:value="item?.id" </j-col>
:key="item?.id" <j-col :span="12" v-if="propertyModelRef.properties">
>{{ item?.name }}</j-select-option <j-form-item
> name="propertiesValue"
</j-select> label="属性值"
</j-form-item> :rules="[{ required: true, message: '请选择' }]"
</j-col> >
<j-col :span="2"></j-col> <ParamsDropdown
<j-col :span="11"> placeholder="请选择"
<j-form-item :options="handleOptions"
:name="['message', 'propertiesValue']" :tabsOptions="tabOptions"
label="属性值" :metricOption="upperOptions"
:rules="[{ required: true, message: '请选择' }]" v-model:value="propertyModelRef.propertiesValue"
v-model:source="propertyModelRef.source"
@change="onValueChange"
> >
<ParamsDropdown <template v-slot="{ label }">
icon="icon-canshu" <j-input :value="label" />
placeholder="请选择" </template>
:options="[]" </ParamsDropdown>
:tabsOptions="tabOptions" </j-form-item>
:metricOption="upperOptions(getType)" </j-col>
v-model:value="modelRef.propertiesValue" </j-row>
/> </j-form>
</j-form-item>
</j-col>
</j-row>
</j-form>
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import ParamsDropdown from '../../../components/ParamsDropdown';
import { handleParamsData } from './index';
const props = defineProps({ const props = defineProps({
value: { value: {
type: Object, type: Object,
@ -60,37 +69,44 @@ const props = defineProps({
}, },
builtInList: { builtInList: {
type: Array, type: Array,
default: () => [] default: () => [],
}, },
}); });
const formRef = ref(); const emit = defineEmits(['update:value']);
const modelRef = reactive({ const propertyFormRef = ref();
properties: '',
propertiesValue: '', const propertyModelRef = reactive({
source: '', properties: undefined,
propertiesValue: undefined,
source: 'fixed',
}); });
const tabOptions = [
{
label: '手动输入',
component: 'string',
key: 'fixed',
},
{
label: '内置参数',
component: 'tree',
key: 'upper',
},
];
const getType = computed(() => { const getType = computed(() => {
return props.metadata.properties.find((item: any) => item.id === modelRef.properties)?.valueType?.type return props.metadata.properties.find(
}) (item: any) => item.id === propertyModelRef.properties,
);
});
const tabOptions = computed(() => {
return [
{
label: '手动输入',
component: getType.value?.valueType?.type,
key: 'fixed',
},
{
label: '内置参数',
component: 'tree',
key: 'upper',
},
];
});
const filterParamsData = (type?: string, data?: any[]): any[] => { const filterParamsData = (type?: string, data?: any[]): any[] => {
if (type && data) { if (type && data) {
return data.filter((item) => { const list = data.filter((item) => {
if (item.children) { if (item.children) {
const _children = filterParamsData(type, item.children); const _children = filterParamsData(type, item.children);
item.children = _children; item.children = _children;
@ -101,40 +117,74 @@ const filterParamsData = (type?: string, data?: any[]): any[] => {
} }
return false; return false;
}); });
return handleParamsData(list);
} }
return data || []; return data || [];
}; };
const upperOptions = (type: string) => { const upperOptions = computed(() => {
return filterParamsData(type, props?.builtInList) || [] return filterParamsData(getType.value?.valueType?.type, props?.builtInList);
} });
const handleOptions = computed(() => {
const _item = getType.value?.valueType;
const _type = _item?.type;
if (_type === 'boolean') {
return [
{
label: _item.trueText,
value: _item.trueValue,
},
{
label: _item.falseText,
value: _item.falseValue,
},
];
}
if (_type === 'enum') {
return _item?.elements.map((i: any) => {
return {
label: i.text,
value: i.value,
};
});
}
return [];
});
const onChange = () => {
propertyModelRef.propertiesValue = undefined;
propertyModelRef.source = 'fixed'
emit('update:value', {
[`${propertyModelRef.properties}`]: {
value: propertyModelRef?.propertiesValue,
source: propertyModelRef?.source,
},
});
};
const onValueChange = () => {
const obj = {
[`${propertyModelRef.properties}`]: {
value: propertyModelRef?.propertiesValue,
source: propertyModelRef?.source,
},
}
emit('update:value', obj);
};
watch( watch(
() => props.value, () => props.value,
(newVal) => { (newVal) => {
const _keys = Object.keys(newVal)?.[0]; if (newVal) {
if (_keys) { const _keys = Object.keys(newVal)?.[0];
(modelRef.properties = _keys), if (_keys) {
(modelRef.propertiesValue = newVal[_keys]?.value); propertyModelRef.properties = _keys as any;
modelRef.source = newVal[_keys]?.source; propertyModelRef.propertiesValue = newVal[_keys]?.value;
propertyModelRef.source = newVal[_keys]?.source;
}
} }
}, },
{ deep: true, immediate: true }, { 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 });
</script> </script>

View File

@ -0,0 +1,10 @@
export const handleParamsData = (data: any[]): any[] => {
return data?.map(item => {
return {
...item,
key: item.column,
disabled: !!item.children?.length,
children: handleParamsData(item.children)
}
}) || []
}

View File

@ -22,7 +22,6 @@
showSearch showSearch
placeholder="请选择功能" placeholder="请选择功能"
v-model:value="modelRef.message.functionId" v-model:value="modelRef.message.functionId"
@change="(val) => onFunctionChange(val, [])"
> >
<j-select-option <j-select-option
v-for="item in metadata?.functions || []" v-for="item in metadata?.functions || []"
@ -37,7 +36,11 @@
:name="['message', 'inputs']" :name="['message', 'inputs']"
:rules="[{ required: true, message: '请输入功能值' }]" :rules="[{ required: true, message: '请输入功能值' }]"
> >
<EditTable v-model:modelValue="modelRef.message.inputs" :builtInList="builtInList" /> <EditTable
:functions="functions"
v-model:value="modelRef.message.inputs"
:builtInList="builtInList"
/>
</j-form-item> </j-form-item>
</template> </template>
<template v-else-if="deviceMessageType === 'READ_PROPERTY'"> <template v-else-if="deviceMessageType === 'READ_PROPERTY'">
@ -79,7 +82,7 @@ import EditTable from './EditTable.vue';
import WriteProperty from './WriteProperty.vue'; import WriteProperty from './WriteProperty.vue';
import { queryBuiltInParams } from '@/api/rule-engine/scene'; import { queryBuiltInParams } from '@/api/rule-engine/scene';
import { useSceneStore } from '@/store/scene'; import { useSceneStore } from '@/store/scene';
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia';
const sceneStore = useSceneStore(); const sceneStore = useSceneStore();
const { data } = storeToRefs(sceneStore); const { data } = storeToRefs(sceneStore);
@ -149,22 +152,31 @@ const deviceMessageType = computed(() => {
const builtInList = ref<any[]>([]); const builtInList = ref<any[]>([]);
const onFunctionChange = (val: string, values?: any[]) => { const functions = computed(() => {
const _item = (metadata.value?.functions || []).find((item: any) => { const _item = (metadata.value?.functions || []).find((item: any) => {
return val === item.id; return modelRef.message?.functionId === item.id;
}); });
const list = (_item?.inputs || []).map((item: any) => { return _item?.inputs || [];
const _a = values?.find((i) => i.name === item.id); });
return {
id: item.id, const _property = computed(() => {
value: _a?.value, const _item = (metadata.value?.properties || []).find((item: any) => {
valueType: item?.valueType?.type, if (deviceMessageType.value === 'WRITE_PROPERTY') {
..._a, return (
name: item.name, Object.keys(modelRef.message.properties || {})?.[0] === item.id
}; );
}
return modelRef.message?.properties === item.id;
}); });
modelRef.message.inputs = list; return _item;
}; });
const _function = computed(() => {
const _item = (metadata.value?.functions || []).find((item: any) => {
return modelRef.message?.functionId === item.id;
});
return _item;
});
const onMessageTypeChange = (val: string) => { const onMessageTypeChange = (val: string) => {
if (['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(val)) { if (['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(val)) {
@ -175,22 +187,18 @@ const onMessageTypeChange = (val: string) => {
}; };
queryBuiltInParams(unref(data), _params).then((res: any) => { queryBuiltInParams(unref(data), _params).then((res: any) => {
if (res.status === 200) { if (res.status === 200) {
builtInList.value = res.result builtInList.value = res.result;
} }
}); });
} }
}; };
watch( watch(
() => [ () => props.values,
props.values?.productDetail, (newVal) => {
props.values.selectorValues, if (newVal?.productDetail?.id) {
props.values?.selector, if (newVal?.selector === 'fixed') {
], const id = newVal?.selectorValues?.[0]?.value;
([newVal1, newVal2, newVal3]) => {
if (newVal1?.id) {
if (newVal3?.selector === 'fixed') {
const id = newVal2?.[0]?.value;
if (id) { if (id) {
detail(id).then((resp) => { detail(id).then((resp) => {
if (resp.status === 200) { if (resp.status === 200) {
@ -201,7 +209,9 @@ watch(
}); });
} }
} else { } else {
metadata.value = JSON.parse(newVal1?.metadata || '{}'); metadata.value = JSON.parse(
newVal?.productDetail?.metadata || '{}',
);
} }
} }
}, },
@ -211,24 +221,36 @@ watch(
watch( watch(
() => props.values?.message, () => props.values?.message,
(newVal) => { (newVal) => {
console.log(newVal)
if (newVal?.messageType) { if (newVal?.messageType) {
modelRef.message = newVal; modelRef.message = newVal;
if (newVal.messageType === 'INVOKE_FUNCTION' && newVal.functionId) { if (newVal.messageType === 'READ_PROPERTY') {
onFunctionChange(newVal.functionId, newVal?.inputs); modelRef.message.properties = newVal.properties?.[0];
} }
onMessageTypeChange(newVal.messageType) onMessageTypeChange(newVal.messageType);
} }
}, },
{ deep: true, immediate: true }, { immediate: true },
); );
const onFormSave = () => { const onFormSave = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
formRef.value formRef.value
.validate() .validate()
.then(async (_data: any) => { .then((_data: any) => {
resolve(_data); //
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) => { .catch((err: any) => {
reject(err); reject(err);

View File

@ -7,7 +7,7 @@
target="scene-trigger-device-device" target="scene-trigger-device-device"
/> />
<j-divider style="margin: 0" /> <j-divider style="margin: 0" />
<j-pro-table <JProTable
ref="actionRef" ref="actionRef"
model="CARD" model="CARD"
:columns="columns" :columns="columns"
@ -62,7 +62,7 @@
</template> </template>
</CardBox> </CardBox>
</template> </template>
</j-pro-table> </JProTable>
</template> </template>
<script setup lang='ts' name='Product'> <script setup lang='ts' name='Product'>
@ -180,7 +180,6 @@ watchEffect(() => {
<style scoped lang='less'> <style scoped lang='less'>
.search { .search {
margin-bottom: 0; margin-bottom: 0;
padding-right: 0px; padding: 0 0 24px 0;
padding-left: 0px;
} }
</style> </style>

View File

@ -0,0 +1,56 @@
<template>
<j-select
placeholder="请选择关系"
:options="relationList"
show-search
:value="value ? value[0]?.value?.relation : undefined"
@change="onRelationChange"
/>
</template>
<script lang="ts" setup>
import NoticeApi from '@/api/notice/config';
const props = defineProps({
value: {
type: Array,
default: () => [{value: {}}]
},
});
const emit = defineEmits(['update:value', 'change']);
const relationList = ref<any[]>([]);
onMounted(() => {
queryRelationList()
})
const queryRelationList = () => {
NoticeApi.getRelationUsers({
paging: false,
sorts: [{ name: 'createTime', order: 'desc' }],
terms: [{ termType: 'eq', column: 'objectTypeName', value: '设备' }],
}).then((resp) => {
if (resp.status === 200) {
relationList.value = (resp.result as any[]).map((item) => {
return {
label: item.name,
value: item.relation,
};
});
}
});
};
const onRelationChange = (val: any, options: any) => {
const _values = [
{
value: {
objectType: 'user',
relation: val,
},
},
];
emit('update:value', _values);
emit('change', _values, options);
};
</script>

View File

@ -30,13 +30,7 @@
name="selectorValues" name="selectorValues"
:rules="[{ required: true, message: '请选择关系' }]" :rules="[{ required: true, message: '请选择关系' }]"
> >
<j-select <RelationSelect @change="onRelationChange" v-model:value="modelRef.selectorValues" />
placeholder="请选择关系"
v-model:value="modelRef.selectorValues"
:options="relationList"
show-search
@change="onRelationChange"
/>
</j-form-item> </j-form-item>
<j-form-item <j-form-item
v-else-if="modelRef.selector === 'tag'" v-else-if="modelRef.selector === 'tag'"
@ -86,6 +80,7 @@ import { getImage } from '@/utils/comm';
import NoticeApi from '@/api/notice/config'; import NoticeApi from '@/api/notice/config';
import Device from './Device.vue'; import Device from './Device.vue';
import Tag from './Tag.vue'; import Tag from './Tag.vue';
import RelationSelect from './RelationSelect.vue'
const props = defineProps({ const props = defineProps({
values: { values: {
@ -130,7 +125,6 @@ const modelRef = reactive({
const list = ref<any[]>([]); const list = ref<any[]>([]);
const builtInList = ref<any[]>([]); const builtInList = ref<any[]>([]);
const tagList = ref<any[]>([]); const tagList = ref<any[]>([]);
const relationList = ref<any[]>([]);
const TypeList = [ const TypeList = [
{ {
@ -199,27 +193,10 @@ const sourceChangeEvent = async () => {
const array = filterTree(resp.result as any[]); const array = filterTree(resp.result as any[]);
// //
// if (props.formProductId === DeviceModel.productId)// TODO // if (props.formProductId === DeviceModel.productId)// TODO
builtInList.value = array; builtInList.value = [] // array;
} }
}; };
const queryRelationList = () => {
NoticeApi.getRelationUsers({
paging: false,
sorts: [{ name: 'createTime', order: 'desc' }],
terms: [{ termType: 'eq', column: 'objectTypeName', value: '设备' }],
}).then((resp) => {
if (resp.status === 200) {
relationList.value = (resp.result as any[]).map((item) => {
return {
label: item.name,
value: item.relation,
};
});
}
});
};
const filterType = async () => { const filterType = async () => {
const _list = TypeList.filter((item) => item.value === 'fixed'); const _list = TypeList.filter((item) => item.value === 'fixed');
if (unref(data)?.trigger?.type === 'device') { if (unref(data)?.trigger?.type === 'device') {
@ -266,11 +243,8 @@ const filterType = async () => {
} }
}; };
const onSelectorChange = (val: string) => { const onSelectorChange = () => {
modelRef.selectorValues = undefined; modelRef.selectorValues = undefined;
if (val === 'relation') {
queryRelationList();
}
}; };
const onDeviceChange = (_detail: any) => { const onDeviceChange = (_detail: any) => {
@ -306,7 +280,7 @@ const onTagChange = (val: any[], arr: any[]) => {
if (arr) { if (arr) {
tagList.value = arr; tagList.value = arr;
} }
emits('save', unref(modelRef), {}); emits('save', unref(modelRef), {}, {tagList: tagList.value});
}; };
const onVariableChange = (val: any, node: any) => { const onVariableChange = (val: any, node: any) => {

View File

@ -154,23 +154,23 @@ const onSave = (_data: any) => {
productName: DeviceModel.productDetail.name, productName: DeviceModel.productDetail.name,
relationName: DeviceModel.relationName, relationName: DeviceModel.relationName,
triggerName: data.value.options?.trigger?.name || '触发设备', triggerName: data.value.options?.trigger?.name || '触发设备',
taglist: [], tagList: [],
columns: [], columns: [],
otherColumns: [], otherColumns: [],
}; };
_options.name = DeviceModel.deviceDetail?.name; _options.name = DeviceModel.deviceDetail?.name || DeviceModel.selectorValues?.[0]?.name;
const _type = _data.message.messageType; const _type = _data.message.messageType;
if (_type === 'INVOKE_FUNCTION') { if (_type === 'INVOKE_FUNCTION') {
_options.type = '执行'; _options.type = '执行';
_options.properties = DeviceModel.propertiesName; _options.properties = _data.message.propertiesName;
} }
if (_type === 'READ_PROPERTY') { if (_type === 'READ_PROPERTY') {
_options.type = '读取'; _options.type = '读取';
_options.properties = DeviceModel.propertiesName; _options.properties = _data.message.propertiesName;
} }
if (_type === 'WRITE_PROPERTY') { if (_type === 'WRITE_PROPERTY') {
_options.type = '设置'; _options.type = '设置';
_options.properties = DeviceModel.propertiesName; _options.properties = _data.message.propertiesName;
_options.propertiesValue = _options.propertiesValue =
typeof DeviceModel.propertiesValue === 'object' typeof DeviceModel.propertiesValue === 'object'
? JSON.stringify(DeviceModel.propertiesValue) ? JSON.stringify(DeviceModel.propertiesValue)
@ -183,7 +183,7 @@ const onSave = (_data: any) => {
} }
} }
if (_options.selector === 'tag') { if (_options.selector === 'tag') {
_options.taglist = DeviceModel.tagList.map((it) => ({ _options.tagList = DeviceModel.tagList.map((it) => ({
name: it.column || it.name, name: it.column || it.name,
type: it.type ? (it.type === 'and' ? '并且' : '或者') : '', type: it.type ? (it.type === 'and' ? '并且' : '或者') : '',
value: it.value, value: it.value,
@ -205,6 +205,10 @@ const save = async (step?: number) => {
if (deviceRef.value) { if (deviceRef.value) {
await deviceRef.value?.onFormSave(); await deviceRef.value?.onFormSave();
current.value = 2; current.value = 2;
} else {
if(DeviceModel.selector === 'fixed' && DeviceModel.selectorValues?.length){
current.value = 2;
}
} }
} else { } else {
if (actionRef.value) { if (actionRef.value) {
@ -228,8 +232,8 @@ const prev = () => {
const saveClick = () => save(); const saveClick = () => save();
const onDeviceSave = (_data: any, _detail: any) => { const onDeviceSave = (_data: any, _detail: any, obj?: any) => {
Object.assign(DeviceModel, _data); Object.assign(DeviceModel, {..._data, ...obj});
DeviceModel.deviceDetail = _detail; DeviceModel.deviceDetail = _detail;
}; };