Merge branch 'dev'

# Conflicts:
#	src/views/system/Menu/Setting/utils.ts
This commit is contained in:
XieYongHong 2023-06-05 15:32:12 +08:00
commit 820ca7330e
8 changed files with 129 additions and 61 deletions

View File

@ -1,6 +1,6 @@
<template>
<j-empty
v-if="!metadata || (metadata && !metadata.functions.length)"
v-if="!metadata || (metadata && !metadata.functions?.length)"
style="margin-top: 50px"
>
<template #description>

View File

@ -318,10 +318,17 @@ const debug = () => {
}
};
onMounted(() => {
// onMounted(() => {
// getDeviceCode();
// getTopic();
// });
watch(() => instanceStore.current?.id, () => {
if (instanceStore.current?.id) {
getDeviceCode();
getTopic();
});
}
}, { immediate: true })
</script>
<style scoped lang='less'>

View File

@ -1,5 +1,5 @@
<template>
<j-modal
<j-modal
:maskClosable="false"
:visible="true"
title="编辑"
@ -7,80 +7,111 @@
@cancel="handleCancel"
:confirmLoading="loading"
>
<j-alert message="当数据来源为设备时,填写的值将下发到设备" 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 || '自定义属性'">
<j-alert
message="当数据来源为设备时,填写的值将下发到设备"
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
v-model:modelValue="modelRef.propertyValue"
:itemType="data?.valueType?.type || data?.dataType"
:options="
(data?.valueType?.type || data?.dataType) === 'enum'
? (data?.valueType?.elements || []).map((item) => {
return {
label: item?.text,
value: item?.value
};
})
: undefined
"
:options="options"
/>
</j-form-item>
</j-form>
</j-modal>
</j-modal>
</template>
<script lang="ts" setup>
import { setProperty } from '@/api/device/instance'
import { useInstanceStore } from "@/store/instance"
import { setProperty } from '@/api/device/instance';
import { useInstanceStore } from '@/store/instance';
import { message } from 'jetlinks-ui-components';
const props = defineProps({
data: {
type: Object,
default: () => {}
}
})
default: () => {},
},
});
const emit = defineEmits(['close']);
const loading = ref<boolean>(false)
const instanceStore = useInstanceStore()
const loading = ref<boolean>(false);
const instanceStore = useInstanceStore();
const formRef = ref();
const modelRef = reactive({
propertyValue: undefined
propertyValue: undefined,
});
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 = {
propertyValue: [
{
required: true,
message: '该字段是必填字段',
}
},
],
}
};
const handleSave = () => {
formRef.value
.validate()
.then(async () => {
loading.value = true;
const resp = await setProperty(instanceStore.current?.id || '', {[props.data?.id]: toRaw(modelRef)?.propertyValue}).finally(() => {
loading.value = false
})
const resp = await setProperty(instanceStore.current?.id || '', {
[props.data?.id]: toRaw(modelRef)?.propertyValue,
}).finally(() => {
loading.value = false;
});
if (resp.status === 200) {
message.success('操作成功!');
emit('close')
emit('close');
formRef.value.resetFields();
}
})
.catch((err: any) => {
console.log('error', err);
});
}
};
</script>

View File

@ -5,6 +5,7 @@
:request="query"
:params="_params"
:bodyStyle="{ padding: '0 0 0 20px' }"
:scroll="{y : 400}"
>
<template #headerTitle>
<j-input-search
@ -75,7 +76,7 @@
</template>
<script lang="ts" setup>
import _, { groupBy, toArray } from 'lodash-es';
import _, { groupBy, throttle, toArray } from 'lodash-es';
import { PropertyData } from '../../../typings';
import PropertyCard from './PropertyCard.vue';
import ValueRender from './ValueRender.vue';
@ -137,7 +138,7 @@ const _params = reactive({
const subRef = ref();
const list = ref<any[]>([]);
// const list = ref<any[]>([]);
const getActions = (data: Partial<Record<string, any>>) => {
const arr = [];
@ -213,15 +214,21 @@ const getActions = (data: Partial<Record<string, any>>) => {
return arr;
};
// const valueChange = (arr: Record<string, any>[]) => {
// (arr || [])
// .sort((a: any, b: any) => a.timestamp - b.timestamp)
// .forEach((item: any) => {
// const { value } = item;
// propertyValue.value[value?.property] = { ...item, ...value };
// });
// list.value = []
// };
const valueChange = (arr: Record<string, any>[]) => {
(arr || [])
.sort((a: any, b: any) => a.timestamp - b.timestamp)
.forEach((item: any) => {
const { value } = item;
propertyValue.value[value?.property] = { ...item, ...value };
});
};
let messageCache = new Map()
const throttleFn = throttle(() => {
const _list = [...messageCache.values()]
valueChange(_list)
}, 500)
const subscribeProperty = () => {
const id = `instance-info-property-${instanceStore.current.id}-${
@ -235,22 +242,26 @@ const subscribeProperty = () => {
})
?.pipe(map((res: any) => res.payload))
.subscribe((payload) => {
list.value = [...list.value, payload];
unref(list)
.sort((a: any, b: any) => a.timestamp - b.timestamp)
.forEach((item: any) => {
const { value } = item;
propertyValue.value[value?.property] = {
...item,
...value,
};
});
if(payload.value?.property) {
messageCache.set(payload.value?.property, payload)
throttleFn()
}
// unref(list)
// .sort((a: any, b: any) => a.timestamp - b.timestamp)
// .forEach((item: any) => {
// const { value } = item;
// propertyValue.value[value?.property] = {
// ...item,
// ...value,
// };
// });
// list.value = [...list.value, payload];
// throttle(valueChange(list.value), 500);
});
};
const getDashboard = async () => {
if(!dataSource.value?.length) return
const param = [
{
dashboard: 'device',
@ -287,6 +298,7 @@ const getDashboard = async () => {
});
propertyValue.value = { ...unref(propertyValue), ...obj };
}
subRef.value && subRef.value?.unsubscribe();
subscribeProperty();
loading.value = false;
};
@ -302,9 +314,11 @@ const query = (params: Record<string, any>) =>
});
arr = _.cloneDeep(li);
}
dataSource.value = arr.slice(_from, _to)
messageCache.clear()
resolve({
result: {
data: arr.slice(_from, _to),
data: dataSource.value,
pageIndex: params.pageIndex || 0,
pageSize: params.pageSize || 12,
total: arr.length,

View File

@ -17,7 +17,7 @@
<FunctionItem
:builtInList="builtInList"
@change="onChange"
:source="record.source"
v-model:source="record.source"
:data="record"
v-model:value="record.value"
/>

View File

@ -152,8 +152,8 @@ const checkDeviceDelete = async () => {
if (item!.message!.messageType === 'WRITE_PROPERTY') {
let hasProperties = false
const propertiesKey = Object.keys(item!.message!.properties!)?.[0]
if (item!.message!.properties && metadata.properties.length) {
const propertiesKey = Object.keys(item!.message!.properties!)?.[0]
hasProperties = metadata.properties?.some((item: any) => item.id === propertiesKey)
}
if (!hasProperties) {
@ -162,6 +162,22 @@ const checkDeviceDelete = async () => {
formTouchOff()
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') {

View File

@ -274,7 +274,7 @@ const getUser = async (_source: string, _triggerType: string) => {
children: relationResp.result.map((item: any) => {
const obj = {
...item,
value: item.id,
value: item.relation,
key: item.id,
title: item.name,
isRelation: true,

View File

@ -40,7 +40,7 @@ export const mergeArr = (oldData: Array<any>, newData: Array<any>) => {
}
if(oldItem && newItem){
oldItem = { ...oldData,...omit(newItem, ['children'])}
oldItem.sortIndex = newItem?.sortIndex
}
if (!oldItem.children && newItem.children) {