fix: 修改场景联动

This commit is contained in:
100011797 2023-03-27 17:04:08 +08:00
parent 9594893a50
commit ee7c4e11f7
13 changed files with 224 additions and 210 deletions

View File

@ -1,5 +1,5 @@
<template>
<pro-search class="search" type="simple" :columns="columns" target="device-instance-running-events" @search="handleSearch" />
<pro-search class="device-search" type="simple" :columns="columns" target="device-instance-running-events" @search="handleSearch" />
<JProTable
ref="eventsRef"
:columns="columns"
@ -62,14 +62,14 @@ const _getEventList = (_params: any) =>
watchEffect(() => {
if (events.data?.valueType?.type === 'object') {
(events.data.valueType?.properties || []).map((i: any) => {
(events.data.valueType?.properties || []).reverse().map((i: any) => {
columns.value.splice(0, 0, {
key: i.id,
title: i.name,
dataIndex: `${i.id}_format`,
search: {
type: 'string',
},
type: i?.valueType?.type || 'string',
}
});
});
} else {
@ -97,8 +97,8 @@ const detail = (_info: any) => {
};
</script>
<style lang="less" scoped>
.search {
padding: 0 0 0 24px;
<style lang="less">
.device-search {
margin: 0 0 24px 0 ;
}
</style>

View File

@ -33,8 +33,10 @@
}指标值`,
}"
:name="['metrics', index, 'value', 0]"
:label="item?.name || '指标值'"
>
<template #label>
<Ellipsis>{{ item?.name || '指标值' }}</Ellipsis>
</template>
<ValueItem
v-model:modelValue="item.value[0]"
:itemType="data.valueType?.type"
@ -95,6 +97,7 @@
import { queryMetric, saveMetric } from '@/api/device/instance';
import { useInstanceStore } from '@/store/instance';
import { message } from 'jetlinks-ui-components';
import { isNumber } from 'lodash-es';
const props = defineProps({
data: {
@ -110,7 +113,7 @@ const instanceStore = useInstanceStore();
const formRef = ref();
const modelRef = reactive<{
metrics: any[]
metrics: any[];
}>({
metrics: [],
});
@ -132,8 +135,8 @@ watch(
) {
const list = resp?.result.map((item: any) => {
const val = Array.isArray(item?.value)
? [item?.value]
: item?.value?.split(',');
? item?.value
: (isNumber(item?.value) ? [item.value] : item?.value?.split(','))
return {
...item,
value: val,
@ -172,7 +175,7 @@ watch(
const handleSave = () => {
formRef.value
.validate()
.then(async () => {
.then(async (_data: any) => {
loading.value = true;
const list = (toRaw(modelRef)?.metrics || []).map((item: any) => {
return {

View File

@ -9,7 +9,7 @@
@select="onChange"
>
<template v-slot="{ label }">
<j-input :value="label" />
<j-input :value="label" readonly />
</template>
</ParamsDropdown>
</template>

View File

@ -41,7 +41,7 @@
@select="onValueChange"
>
<template v-slot="{ label }">
<j-input :value="label" placeholder="请选择" />
<j-input readonly :value="label" placeholder="请选择" />
</template>
</ParamsDropdown>
</j-form-item>
@ -112,7 +112,6 @@ const filterParamsData = (type?: string, data?: any[]): any[] => {
item.children = _children;
return _children.length ? true : false;
} else if (item.type === type) {
// optionMap.current.set(item.id, item);
return true;
}
return false;
@ -132,12 +131,12 @@ const handleOptions = computed(() => {
if (_type === 'boolean') {
return [
{
label: _item.trueText,
value: _item.trueValue,
label: _item.trueText || true,
value: _item.trueValue || true,
},
{
label: _item.falseText,
value: _item.falseValue,
label: _item.falseText || false,
value: _item.falseValue || false,
},
];
}

View File

@ -22,12 +22,13 @@
showSearch
placeholder="请选择功能"
v-model:value="modelRef.message.functionId"
@select="functionSelect"
@change="functionSelect"
>
<j-select-option
v-for="item in metadata?.functions || []"
:value="item?.id"
:key="item?.id"
:label="item?.name"
>{{ item?.name }}</j-select-option
>
</j-select>
@ -54,6 +55,7 @@
showSearch
placeholder="请选择属性"
v-model:value="modelRef.message.properties[0]"
@change="propertySelect"
>
<j-select-option
v-for="item in metadata?.properties.filter((i) =>
@ -61,6 +63,7 @@
) || []"
:value="item?.id"
:key="item?.id"
:label="item?.name"
>{{ item?.name }}</j-select-option
>
</j-select>
@ -130,8 +133,14 @@ const props = defineProps({
type: Number,
default: 0,
},
productDetail: {
type: Object,
default: () => {},
},
});
const emit = defineEmits(['change']);
const formRef = ref();
const modelRef = reactive({
@ -146,8 +155,19 @@ const modelRef = reactive({
const writeFormRef = ref();
const functionSelect = () => {
const functionSelect = (val: any, options?: any) => {
modelRef.message.inputs = [];
emit('change', {
propertiesName: options?.label,
propertiesValue: modelRef.propertiesValue,
});
};
const propertySelect = (val: any, options?: any) => {
emit('change', {
propertiesName: options?.label,
propertiesValue: modelRef.propertiesValue,
});
};
const functionRules = [
@ -239,11 +259,11 @@ const onMessageTypeChange = (val: string) => {
};
watch(
() => props.values,
() => props.productDetail,
(newVal) => {
if (newVal?.productDetail?.id) {
if (newVal?.selector === 'fixed') {
const id = newVal?.selectorValues?.[0]?.value;
if (newVal?.id) {
if (props.values?.selector === 'fixed') {
const id = props.values?.selectorValues?.[0]?.value;
if (id) {
detail(id).then((resp) => {
if (resp.status === 200) {
@ -254,9 +274,7 @@ watch(
});
}
} else {
metadata.value = JSON.parse(
newVal?.productDetail?.metadata || '{}',
);
metadata.value = JSON.parse(newVal?.metadata || '{}');
}
}
},
@ -282,6 +300,13 @@ watch(
const onWriteChange = (val: string) => {
modelRef.propertiesValue = val;
emit('change', {
propertiesName:
deviceMessageType.value === 'INVOKE_FUNCTION'
? _function.value?.name
: _property.value?.name,
propertiesValue: modelRef.propertiesValue,
});
};
const onFormSave = () => {
@ -295,19 +320,19 @@ const onFormSave = () => {
reject(false);
}
}
//
const obj = {
resolve({
message: {
...modelRef.message,
..._data.message,
propertiesName:
deviceMessageType.value === 'INVOKE_FUNCTION'
? _function.value?.name
: _property.value?.name,
propertiesValue: modelRef.propertiesValue,
},
};
resolve(obj);
});
emit('change', {
propertiesName:
deviceMessageType.value === 'INVOKE_FUNCTION'
? _function.value?.name
: _property.value?.name,
propertiesValue: modelRef.propertiesValue,
});
})
.catch((err: any) => {
reject(err);

View File

@ -177,15 +177,8 @@ const onValueChange = () => {
value: item.value,
};
});
const arr = _data.map((item: any) => {
return {
column: item.name,
type: item.type,
value: item.value,
};
});
emits('update:value', [{ value: newValue, name: '标签' }]);
emits('change', [{ value: newValue, name: '标签' }], arr);
emits('change', [{ value: newValue, name: '标签' }], _data);
};
</script>

View File

@ -13,18 +13,12 @@
@change="onSelectorChange"
/>
</j-form-item>
<!-- <j-form-item
v-if="modelRef.selector === 'fixed'"
name="selectorValues"
:rules="[{ required: true, message: '请选择设备' }]"
> -->
<Device
v-if="modelRef.selector === 'fixed'"
:productId="values.productDetail.id"
:productId="productDetail.id"
v-model:value="modelRef.selectorValues"
@change="onDeviceChange"
/>
<!-- </j-form-item> -->
<j-form-item
v-else-if="modelRef.selector === 'relation'"
label="关系"
@ -107,6 +101,10 @@ const props = defineProps({
parallel: {
type: Boolean,
},
productDetail: {
type: Object,
default: () => {},
},
});
// savedeviceDetail
@ -122,9 +120,7 @@ const modelRef = reactive({
selectorValues: undefined,
deviceId: '',
source: '',
relationName: '',
upperKey: '',
message: undefined,
});
const list = ref<any[]>([]);
@ -166,10 +162,11 @@ const filterTree = (nodes: any[]) => {
if (
it.children.find(
(item: any) =>
item.id.indexOf('deviceId' || 'device_id' || 'device_Id') >
-1,
item?.id?.indexOf(
'deviceId' || 'device_id' || 'device_Id',
) > -1,
) &&
!it.children.find((item: any) => item.id.indexOf('boolean') > -1)
!it.children.find((item: any) => item?.id.indexOf('boolean') > -1)
) {
return true;
}
@ -197,7 +194,7 @@ const sourceChangeEvent = async () => {
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) {
if (productId === props?.productDetail?.id) {
const _data = await getParams(_params, unref(data));
builtInList.value = handleParamsData(filterTree(_data), 'id');
} else {
@ -205,7 +202,7 @@ const sourceChangeEvent = async () => {
}
};
const filterType = async () => {
const filterType = async (newVal: any) => {
const _list = TypeList.filter((item) => item.value === 'fixed');
if (unref(data)?.trigger?.type === 'device') {
//
@ -221,10 +218,9 @@ const filterType = async () => {
_list.push(...array);
}
//
const tag = JSON.parse(
props.values.productDetail?.metadata || '{}',
)?.tags;
const tag = JSON.parse(newVal?.metadata || '{}')?.tags;
if (tag && tag.length !== 0) {
tagList.value = tag || [];
const array = TypeList.filter((item) => item.value === 'tag');
_list.push(...array);
}
@ -251,23 +247,23 @@ const filterType = async () => {
}
};
const onSelectorChange = () => {
const onSelectorChange = (val: string) => {
modelRef.selectorValues = undefined;
modelRef.selector = val;
};
const onDeviceChange = (_detail: any) => {
if (_detail) {
if (_detail.id) {
modelRef.deviceId = _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);
emits('save', unref(modelRef), { name: _detail.name });
}
};
@ -276,8 +272,7 @@ const onRelationChange = (val: any, options: any) => {
modelRef.source = 'upper';
modelRef.selectorValues = val;
modelRef.upperKey = 'scene.deviceId';
modelRef.relationName = options.label;
emits('save', unref(modelRef), {});
emits('save', unref(modelRef), { relationName: options.label });
};
const onTagChange = (val: any[], arr: any[]) => {
@ -285,27 +280,61 @@ const onTagChange = (val: any[], arr: any[]) => {
modelRef.deviceId = 'deviceId';
modelRef.source = 'fixed';
}
emits('save', unref(modelRef), {}, arr ? { tagList: arr } : {});
const tagName = arr.map((i, _index) => {
return `${_index !== 0 && _index !== (arr || []).length && i.type}${
i.name
}为${i.value}`;
});
emits(
'save',
unref(modelRef),
{},
arr ? { tagName: tagName.join('') } : {},
);
};
const onVariableChange = (val: any, node: any) => {
modelRef.deviceId = val;
modelRef.selectorValues = [{ value: val, name: node.description }] as any;
emits('save', unref(modelRef), node);
emits('save', unref(modelRef), { name: node.description });
};
watchEffect(() => {
Object.assign(modelRef, props.values);
});
watch(
() => props.values,
(newVal) => {
Object.assign(modelRef, newVal);
},
{
immediate: true,
deep: true,
},
);
watch(
() => props.values.productDetail,
() => props.productDetail,
async (newVal) => {
await sourceChangeEvent();
if (newVal) {
const metadata = JSON.parse(newVal?.metadata || '{}');
tagList.value = metadata?.tags || [];
filterType();
filterType(newVal);
}
},
{
immediate: true,
deep: true,
},
);
watch(
() => [props.values, builtInList.value],
([newVal1, newVal2]) => {
if (newVal2 && newVal2.length) {
const param = newVal1?.selectorValues?.[0]?.value;
const isVariable = (newVal2 || [])?.find((item: any) => {
return item.children.find((i: any) => i.id === param);
});
if (isVariable) {
modelRef.selector = 'variable';
}
}
},
{
@ -319,14 +348,14 @@ const onFormSave = () => {
formRef.value
.validate()
.then(async (_data: any) => {
if(modelRef.selector === 'fixed'){
if(!modelRef?.selectorValues?.[0]?.value){
onlyMessage('请选择设备', 'error')
if (modelRef.selector === 'fixed') {
if (!modelRef?.selectorValues?.[0]?.value) {
onlyMessage('请选择设备', 'error');
reject(false);
} else {
resolve({
..._data,
selectorValues: modelRef.selectorValues
selectorValues: modelRef.selectorValues,
});
}
} else {

View File

@ -23,7 +23,7 @@
<Product
v-if="current === 0"
v-model:rowKey="DeviceModel.productId"
v-model:detail="DeviceModel.productDetail"
v-model:detail="productDetail"
@change="onProductChange"
/>
<Device
@ -34,6 +34,7 @@
:thenName="thenName"
:values="DeviceModel"
@save="onDeviceSave"
:productDetail="productDetail"
ref="deviceRef"
/>
<Action
@ -42,7 +43,9 @@
:branchesName="branchesName"
:thenName="thenName"
:values="DeviceModel"
:productDetail="productDetail"
ref="actionRef"
@change="onActionsChange"
/>
</div>
<template #footer>
@ -61,7 +64,7 @@
</template>
<script lang="ts" setup>
import { DeviceModelType } from './typings';
import { DeviceModelType, DeviceOptionType } from './typings';
import Product from './Product.vue';
import Device from './device/index.vue';
import Action from './actions/index.vue';
@ -105,26 +108,22 @@ const current = ref<number>(0);
const deviceRef = ref<any>();
const actionRef = ref<any>();
const productDetail = ref<any>({});
const DeviceModel = reactive<DeviceModelType>({
productId: '',
deviceId: '',
productDetail: {},
device: {},
deviceDetail: {},
options: {},
selector: 'fixed',
selectorValues: [],
upperKey: '',
source: 'fixed',
relationName: '',
message: {},
propertiesName: '',
propertiesValue: '',
columns: [],
actionName: '',
tagList: [],
message: {
messageType: 'INVOKE_FUNCTION',
},
});
const DeviceOptions = ref<DeviceOptionType>({});
const emit = defineEmits<Emit>();
const onCancel = () => {
@ -139,7 +138,6 @@ const onSave = (_data: any) => {
productId: DeviceModel.productId,
message: _data.message,
};
//
if (DeviceModel.selector === 'variable') {
item.selector = 'fixed';
}
@ -152,55 +150,46 @@ const onSave = (_data: any) => {
properties: '', //
propertiesValue: '', //
selector: DeviceModel.selector, //
productName: DeviceModel.productDetail.name,
relationName: DeviceModel.relationName,
triggerName: data.value.options?.trigger?.name || '触发设备',
tagList: [],
columns: [],
otherColumns: [],
...DeviceOptions.value,
};
_options.name =
DeviceModel.deviceDetail?.name || DeviceModel.selectorValues?.[0]?.name;
const _type = _data.message.messageType;
if (_type === 'INVOKE_FUNCTION') {
_options.type = '执行';
_options.properties = _data.message.propertiesName;
}
if (_type === 'READ_PROPERTY') {
_options.type = '读取';
_options.properties = _data.message.propertiesName;
}
if (_type === 'WRITE_PROPERTY') {
_options.type = '设置';
_options.properties = _data.message.propertiesName;
_options.propertiesValue =
typeof _data.message.propertiesValue === 'object'
? JSON.stringify(_data.message.propertiesValue)
: `${_data.message.propertiesValue}`;
_options.columns = DeviceModel.columns;
_options.otherColumns = DeviceModel.columns;
const cur: any = Object.values(_data.message.properties)?.[0];
if (cur?.source === 'upper') {
_options.propertiesValue = DeviceModel.actionName;
}
}
if (_options.selector === 'tag') {
_options.taglist = DeviceModel.tagList.map((it) => ({
name: it.column || it.name,
type: it.type ? (it.type === 'and' ? '并且' : '或者') : '',
value: it.value,
}));
}
if (_options.selector === 'variable') {
_options.name = DeviceModel.selectorValues?.[0]?.name;
(typeof _options?.propertiesValue === 'object'
? JSON.stringify(_options?.propertiesValue)
: `${_options?.propertiesValue}`) || DeviceModel?.selectorValues?.[0]?.value;
}
emit('save', item, _options);
};
const onProductChange = () => {
DeviceModel.selectorValues = undefined
DeviceModel.message = {}
}
const onProductChange = (_val: any) => {
DeviceModel.selectorValues = undefined;
DeviceModel.message = {
messageType: 'INVOKE_FUNCTION',
};
DeviceOptions.value.productName = _val?.name;
};
const onDeviceSave = (_data: any, obj?: any) => {
Object.assign(DeviceModel, { ..._data });
DeviceOptions.value = { ...unref(DeviceOptions), ...obj };
};
const onActionsChange = (options?: any) => {
const obj = {
...DeviceOptions.value,
...options,
};
DeviceOptions.value = obj;
};
const save = async (step?: number) => {
let _step = step !== undefined ? step : current.value;
@ -215,7 +204,7 @@ const save = async (step?: number) => {
} else if (DeviceModel.selectorValues?.length) {
current.value = 2;
} else {
onlyMessage('请选择设备', 'error')
onlyMessage('请选择设备', 'error');
}
} else {
if (actionRef.value) {
@ -239,41 +228,15 @@ const prev = () => {
const saveClick = () => save();
const onDeviceSave = (_data: any, _detail: any, obj?: any) => {
Object.assign(DeviceModel, { ..._data, ...obj });
DeviceModel.deviceDetail = _detail;
};
watch(
() => props.value,
(newValue) => {
Object.assign(DeviceModel, newValue);
console.log(newValue)
Object.assign(DeviceModel, {...newValue});
if (newValue?.productId) {
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;
}
productDetail.value = resp.result;
}
});
}

View File

@ -2,27 +2,27 @@ import { ProductItem } from '@/views/device/Product/typings';
import { ActionsDeviceProps } from '../../../typings';
type DeviceModelType = {
// steps: {
// key: string;
// title: string;
// content: React.ReactNode;
// }[];
// current: number;
productId: string;
deviceId: string;
productDetail: ProductItem | any;
device: Partial<ActionsDeviceProps>;
deviceDetail: any;
options: any;
source: string;
selector: string;
selectorValues: any;
upperKey: string;
source: string;
relationName: string;
message: any;
propertiesName: string;
propertiesValue: string | any;
columns: string[];
actionName: string;
tagList: any[];
}
upperKey: string;
deviceId: string;
message: {
properties?: any;
messageType: string;
inputs?: any[]
}
}
type DeviceOptionType = {
name?: string;
productName?: string;
propertiesValue?: string;
propertiesName?: any;
tagName?: string;
relationName?: string;
actionName?: string;
}

View File

@ -263,7 +263,7 @@
{{data?.options?.name}}
</Ellipsis>
<Ellipsis style='max-width: 400px;'>
{{data?.options?.properties}}
{{data?.options?.propertiesName}}
</Ellipsis>
<Ellipsis style='max-width: 200px;'>
@ -295,21 +295,9 @@
"
/>
{{ data?.options?.type }}
<span
v-for="(i, _index) in data?.options?.taglist ||
[]"
:key="i.value"
>
{{
_index !== 0 &&
_index !==
(data?.options?.taglist || []).length &&
i.type
}}
{{ i.name }}{{ i.value }}
</span>
<span>{{ data?.options?.tagName }}</span>
{{ data?.options?.productName }}
{{ data?.options?.properties }}
{{ data?.options?.propertiesName }}
</div>
</template>
<template v-else-if="data?.device?.selector === 'relation'">
@ -328,7 +316,7 @@
>具有相同 {{ data?.options?.relationName }}{{
data?.options?.productName
}}设备的
{{ data?.options?.properties }}
{{ data?.options?.propertiesName }}
</div>
</template>
</div>

View File

@ -44,6 +44,10 @@ const props = defineProps({
},
});
watchEffect(() => {
console.log(props.data)
})
const emit = defineEmits(['cancel', 'save']);
const onCancel = () => {

View File

@ -117,9 +117,7 @@
</j-form-item>
</template>
<template v-else-if="column.key === 'notnull'">
<j-form-item
:name="['data', index, 'notnull']"
>
<j-form-item :name="['data', index, 'notnull']">
<j-radio-group
v-model:value="record.notnull"
button-style="solid"
@ -134,9 +132,7 @@
</j-form-item>
</template>
<template v-else-if="column.key === 'comment'">
<j-form-item
:name="['data', index, 'notnull']"
>
<j-form-item :name="['data', index, 'notnull']">
<j-input
v-model:value="record.comment"
placeholder="请输入说明"
@ -167,20 +163,27 @@
</j-button>
</div>
</div>
<j-modal v-model:visible="dialog.visible" title="新增" @ok="handleOk">
<j-form :model="dialog.form" ref="addFormRef">
<j-modal
:visible="true"
v-if="dialog.visible"
title="新增"
@ok="handleOk"
@cancel="handleCancel"
>
<j-form :model="dialog.form" ref="addFormRef" :layout="'vertical'">
<j-form-item
label="名称"
name="name"
:required="true"
:rules="[
{
required: true,
message: '请输入名称',
},
// {
// required: true,
// message: '',
// },
{
max: 64,
message: '最多可输入64个字符',
trigger: 'blur',
trigger: 'change',
},
{
// pattern: /^[0-9].*$/,
@ -191,7 +194,7 @@
{
pattern: /^\w+$/,
message: '名称只能由数字、字母、下划线、中划线组成',
trigger: 'blur',
trigger: 'change',
},
]"
>
@ -410,6 +413,11 @@ const handleOk = () => {
});
};
const handleCancel = () => {
dialog.visible = false;
addFormRef.value?.resetFields();
};
watch(
[() => leftData.searchValue, () => leftData.sourceTree],
([m, n]) => {
@ -458,6 +466,8 @@ const checkName = (_: any, value: any) =>
} else {
resolve('');
}
} else {
reject('请输入名称');
}
});
</script>

View File

@ -3700,8 +3700,8 @@ jetlinks-store@^0.0.3:
jetlinks-ui-components@^1.0.5:
version "1.0.5"
resolved "http://47.108.170.157:9013/jetlinks-ui-components/-/jetlinks-ui-components-1.0.5.tgz#593185f6313895485b59e9a79bc920c63374d84d"
integrity sha512-dkSOmatSPLHlV91YdTcHWO2wfwriUIZKEuLd5bJF2GsO9SvDMyJ2YJ4n/3fkklOoL5albhY37iX2Ot3A+7QYwA==
resolved "http://47.108.170.157:9013/jetlinks-ui-components/-/jetlinks-ui-components-1.0.5.tgz#6a3cc76cd6d98319e070da597bfcf146fa12d375"
integrity sha512-ASPqiWprK2v4/zQIYxOytjkVFgx+AkBaD5Klg2ik88y9uDAW/Ylvqa91v149znihU1y8Q2Nm2PXvUSJFD7HPpw==
dependencies:
"@vueuse/core" "^9.12.0"
ant-design-vue "^3.2.15"