Merge branch 'dev'
# Conflicts: # src/views/system/Menu/Setting/utils.ts
This commit is contained in:
commit
820ca7330e
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<j-empty
|
<j-empty
|
||||||
v-if="!metadata || (metadata && !metadata.functions.length)"
|
v-if="!metadata || (metadata && !metadata.functions?.length)"
|
||||||
style="margin-top: 50px"
|
style="margin-top: 50px"
|
||||||
>
|
>
|
||||||
<template #description>
|
<template #description>
|
||||||
|
|
|
||||||
|
|
@ -318,10 +318,17 @@ const debug = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
// onMounted(() => {
|
||||||
|
// getDeviceCode();
|
||||||
|
// getTopic();
|
||||||
|
// });
|
||||||
|
|
||||||
|
watch(() => instanceStore.current?.id, () => {
|
||||||
|
if (instanceStore.current?.id) {
|
||||||
getDeviceCode();
|
getDeviceCode();
|
||||||
getTopic();
|
getTopic();
|
||||||
});
|
}
|
||||||
|
}, { immediate: true })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang='less'>
|
<style scoped lang='less'>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<j-modal
|
<j-modal
|
||||||
:maskClosable="false"
|
:maskClosable="false"
|
||||||
:visible="true"
|
:visible="true"
|
||||||
title="编辑"
|
title="编辑"
|
||||||
|
|
@ -7,80 +7,111 @@
|
||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
:confirmLoading="loading"
|
:confirmLoading="loading"
|
||||||
>
|
>
|
||||||
<j-alert message="当数据来源为设备时,填写的值将下发到设备" type="warning" showIcon />
|
<j-alert
|
||||||
<j-form :rules="rules" layout="vertical" ref="formRef" :model="modelRef" style="margin-top: 20px">
|
message="当数据来源为设备时,填写的值将下发到设备"
|
||||||
<j-form-item name="propertyValue" :label="data?.name || '自定义属性'">
|
type="warning"
|
||||||
|
showIcon
|
||||||
|
/>
|
||||||
|
<j-form
|
||||||
|
:rules="rules"
|
||||||
|
layout="vertical"
|
||||||
|
ref="formRef"
|
||||||
|
:model="modelRef"
|
||||||
|
style="margin-top: 20px"
|
||||||
|
>
|
||||||
|
<j-form-item
|
||||||
|
name="propertyValue"
|
||||||
|
:label="data?.name || '自定义属性'"
|
||||||
|
>
|
||||||
<ValueItem
|
<ValueItem
|
||||||
v-model:modelValue="modelRef.propertyValue"
|
v-model:modelValue="modelRef.propertyValue"
|
||||||
:itemType="data?.valueType?.type || data?.dataType"
|
:itemType="data?.valueType?.type || data?.dataType"
|
||||||
:options="
|
:options="options"
|
||||||
(data?.valueType?.type || data?.dataType) === 'enum'
|
|
||||||
? (data?.valueType?.elements || []).map((item) => {
|
|
||||||
return {
|
|
||||||
label: item?.text,
|
|
||||||
value: item?.value
|
|
||||||
};
|
|
||||||
})
|
|
||||||
: undefined
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
</j-form-item>
|
</j-form-item>
|
||||||
</j-form>
|
</j-form>
|
||||||
</j-modal>
|
</j-modal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { setProperty } from '@/api/device/instance'
|
import { setProperty } from '@/api/device/instance';
|
||||||
import { useInstanceStore } from "@/store/instance"
|
import { useInstanceStore } from '@/store/instance';
|
||||||
import { message } from 'jetlinks-ui-components';
|
import { message } from 'jetlinks-ui-components';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
data: {
|
data: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => {}
|
default: () => {},
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['close']);
|
const emit = defineEmits(['close']);
|
||||||
|
|
||||||
const loading = ref<boolean>(false)
|
const loading = ref<boolean>(false);
|
||||||
const instanceStore = useInstanceStore()
|
const instanceStore = useInstanceStore();
|
||||||
|
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
|
|
||||||
const modelRef = reactive({
|
const modelRef = reactive({
|
||||||
propertyValue: undefined
|
propertyValue: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
emit('close')
|
emit('close');
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const options = computed(() => {
|
||||||
|
const _type = props.data?.valueType?.type || props.data?.dataType;
|
||||||
|
if (_type === 'enum') {
|
||||||
|
return (props.data?.valueType?.elements || []).map((item: any) => {
|
||||||
|
return {
|
||||||
|
label: item?.text,
|
||||||
|
value: item?.value,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (_type === 'boolean') {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: props.data?.valueType?.falseText,
|
||||||
|
value: props.data?.valueType?.falseValue,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: props.data?.valueType?.trueText,
|
||||||
|
value: props.data?.valueType?.trueValue,
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
|
||||||
const rules = {
|
const rules = {
|
||||||
propertyValue: [
|
propertyValue: [
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: '该字段是必填字段',
|
message: '该字段是必填字段',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
formRef.value
|
formRef.value
|
||||||
.validate()
|
.validate()
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const resp = await setProperty(instanceStore.current?.id || '', {[props.data?.id]: toRaw(modelRef)?.propertyValue}).finally(() => {
|
const resp = await setProperty(instanceStore.current?.id || '', {
|
||||||
loading.value = false
|
[props.data?.id]: toRaw(modelRef)?.propertyValue,
|
||||||
})
|
}).finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
message.success('操作成功!');
|
message.success('操作成功!');
|
||||||
emit('close')
|
emit('close');
|
||||||
formRef.value.resetFields();
|
formRef.value.resetFields();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err: any) => {
|
.catch((err: any) => {
|
||||||
console.log('error', err);
|
console.log('error', err);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
:request="query"
|
:request="query"
|
||||||
:params="_params"
|
:params="_params"
|
||||||
:bodyStyle="{ padding: '0 0 0 20px' }"
|
:bodyStyle="{ padding: '0 0 0 20px' }"
|
||||||
|
:scroll="{y : 400}"
|
||||||
>
|
>
|
||||||
<template #headerTitle>
|
<template #headerTitle>
|
||||||
<j-input-search
|
<j-input-search
|
||||||
|
|
@ -75,7 +76,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import _, { groupBy, toArray } from 'lodash-es';
|
import _, { groupBy, throttle, toArray } from 'lodash-es';
|
||||||
import { PropertyData } from '../../../typings';
|
import { PropertyData } from '../../../typings';
|
||||||
import PropertyCard from './PropertyCard.vue';
|
import PropertyCard from './PropertyCard.vue';
|
||||||
import ValueRender from './ValueRender.vue';
|
import ValueRender from './ValueRender.vue';
|
||||||
|
|
@ -137,7 +138,7 @@ const _params = reactive({
|
||||||
|
|
||||||
const subRef = ref();
|
const subRef = ref();
|
||||||
|
|
||||||
const list = ref<any[]>([]);
|
// const list = ref<any[]>([]);
|
||||||
|
|
||||||
const getActions = (data: Partial<Record<string, any>>) => {
|
const getActions = (data: Partial<Record<string, any>>) => {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
|
|
@ -213,15 +214,21 @@ const getActions = (data: Partial<Record<string, any>>) => {
|
||||||
return arr;
|
return arr;
|
||||||
};
|
};
|
||||||
|
|
||||||
// const valueChange = (arr: Record<string, any>[]) => {
|
const valueChange = (arr: Record<string, any>[]) => {
|
||||||
// (arr || [])
|
(arr || [])
|
||||||
// .sort((a: any, b: any) => a.timestamp - b.timestamp)
|
.sort((a: any, b: any) => a.timestamp - b.timestamp)
|
||||||
// .forEach((item: any) => {
|
.forEach((item: any) => {
|
||||||
// const { value } = item;
|
const { value } = item;
|
||||||
// propertyValue.value[value?.property] = { ...item, ...value };
|
propertyValue.value[value?.property] = { ...item, ...value };
|
||||||
// });
|
});
|
||||||
// list.value = []
|
};
|
||||||
// };
|
|
||||||
|
let messageCache = new Map()
|
||||||
|
|
||||||
|
const throttleFn = throttle(() => {
|
||||||
|
const _list = [...messageCache.values()]
|
||||||
|
valueChange(_list)
|
||||||
|
}, 500)
|
||||||
|
|
||||||
const subscribeProperty = () => {
|
const subscribeProperty = () => {
|
||||||
const id = `instance-info-property-${instanceStore.current.id}-${
|
const id = `instance-info-property-${instanceStore.current.id}-${
|
||||||
|
|
@ -235,22 +242,26 @@ const subscribeProperty = () => {
|
||||||
})
|
})
|
||||||
?.pipe(map((res: any) => res.payload))
|
?.pipe(map((res: any) => res.payload))
|
||||||
.subscribe((payload) => {
|
.subscribe((payload) => {
|
||||||
list.value = [...list.value, payload];
|
if(payload.value?.property) {
|
||||||
unref(list)
|
messageCache.set(payload.value?.property, payload)
|
||||||
.sort((a: any, b: any) => a.timestamp - b.timestamp)
|
throttleFn()
|
||||||
.forEach((item: any) => {
|
}
|
||||||
const { value } = item;
|
// unref(list)
|
||||||
propertyValue.value[value?.property] = {
|
// .sort((a: any, b: any) => a.timestamp - b.timestamp)
|
||||||
...item,
|
// .forEach((item: any) => {
|
||||||
...value,
|
// const { value } = item;
|
||||||
};
|
// propertyValue.value[value?.property] = {
|
||||||
});
|
// ...item,
|
||||||
|
// ...value,
|
||||||
|
// };
|
||||||
|
// });
|
||||||
// list.value = [...list.value, payload];
|
// list.value = [...list.value, payload];
|
||||||
// throttle(valueChange(list.value), 500);
|
// throttle(valueChange(list.value), 500);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDashboard = async () => {
|
const getDashboard = async () => {
|
||||||
|
if(!dataSource.value?.length) return
|
||||||
const param = [
|
const param = [
|
||||||
{
|
{
|
||||||
dashboard: 'device',
|
dashboard: 'device',
|
||||||
|
|
@ -287,6 +298,7 @@ const getDashboard = async () => {
|
||||||
});
|
});
|
||||||
propertyValue.value = { ...unref(propertyValue), ...obj };
|
propertyValue.value = { ...unref(propertyValue), ...obj };
|
||||||
}
|
}
|
||||||
|
subRef.value && subRef.value?.unsubscribe();
|
||||||
subscribeProperty();
|
subscribeProperty();
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
};
|
};
|
||||||
|
|
@ -302,9 +314,11 @@ const query = (params: Record<string, any>) =>
|
||||||
});
|
});
|
||||||
arr = _.cloneDeep(li);
|
arr = _.cloneDeep(li);
|
||||||
}
|
}
|
||||||
|
dataSource.value = arr.slice(_from, _to)
|
||||||
|
messageCache.clear()
|
||||||
resolve({
|
resolve({
|
||||||
result: {
|
result: {
|
||||||
data: arr.slice(_from, _to),
|
data: dataSource.value,
|
||||||
pageIndex: params.pageIndex || 0,
|
pageIndex: params.pageIndex || 0,
|
||||||
pageSize: params.pageSize || 12,
|
pageSize: params.pageSize || 12,
|
||||||
total: arr.length,
|
total: arr.length,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
<FunctionItem
|
<FunctionItem
|
||||||
:builtInList="builtInList"
|
:builtInList="builtInList"
|
||||||
@change="onChange"
|
@change="onChange"
|
||||||
:source="record.source"
|
v-model:source="record.source"
|
||||||
:data="record"
|
:data="record"
|
||||||
v-model:value="record.value"
|
v-model:value="record.value"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,8 @@ const checkDeviceDelete = async () => {
|
||||||
|
|
||||||
if (item!.message!.messageType === 'WRITE_PROPERTY') {
|
if (item!.message!.messageType === 'WRITE_PROPERTY') {
|
||||||
let hasProperties = false
|
let hasProperties = false
|
||||||
|
const propertiesKey = Object.keys(item!.message!.properties!)?.[0]
|
||||||
if (item!.message!.properties && metadata.properties.length) {
|
if (item!.message!.properties && metadata.properties.length) {
|
||||||
const propertiesKey = Object.keys(item!.message!.properties!)?.[0]
|
|
||||||
hasProperties = metadata.properties?.some((item: any) => item.id === propertiesKey)
|
hasProperties = metadata.properties?.some((item: any) => item.id === propertiesKey)
|
||||||
}
|
}
|
||||||
if (!hasProperties) {
|
if (!hasProperties) {
|
||||||
|
|
@ -162,6 +162,22 @@ const checkDeviceDelete = async () => {
|
||||||
formTouchOff()
|
formTouchOff()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 判断值-内置参数
|
||||||
|
const _value = item!.message!.properties?.[propertiesKey]
|
||||||
|
if(_value.source === 'upper') {
|
||||||
|
const _params = {
|
||||||
|
branch: props.thenName,
|
||||||
|
branchGroup: props.branchesName,
|
||||||
|
action: props.name - 1,
|
||||||
|
};
|
||||||
|
const option = (await getBuildInData(_params, _data.value))(_value?.value!, 'id')
|
||||||
|
if(!option) {
|
||||||
|
_data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.message!.properties![propertiesKey] = undefined
|
||||||
|
_data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.changeData = true
|
||||||
|
formTouchOff()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item!.message!.messageType === 'INVOKE_FUNCTION') {
|
if (item!.message!.messageType === 'INVOKE_FUNCTION') {
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ const getUser = async (_source: string, _triggerType: string) => {
|
||||||
children: relationResp.result.map((item: any) => {
|
children: relationResp.result.map((item: any) => {
|
||||||
const obj = {
|
const obj = {
|
||||||
...item,
|
...item,
|
||||||
value: item.id,
|
value: item.relation,
|
||||||
key: item.id,
|
key: item.id,
|
||||||
title: item.name,
|
title: item.name,
|
||||||
isRelation: true,
|
isRelation: true,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export const mergeArr = (oldData: Array<any>, newData: Array<any>) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(oldItem && newItem){
|
if(oldItem && newItem){
|
||||||
oldItem = { ...oldData,...omit(newItem, ['children'])}
|
oldItem.sortIndex = newItem?.sortIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oldItem.children && newItem.children) {
|
if (!oldItem.children && newItem.children) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue