index.vue
3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<script lang="ts" setup>
import { ComponentPropsConfigType } from '/@/views/visual/packages/index.type';
import { option } from './config';
import { useComponentScale } from '/@/views/visual/packages/hook/useComponentScale';
import { computed, unref } from 'vue';
import { ref } from 'vue';
import { UpdateTime } from '/@/views/visual/commonComponents/UpdateTime';
import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
import { useDataFetch } from '../../../hook/socket/useSocket';
import { DataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
import { useDeviceProfileQueryContext } from '/@/views/visual/palette/hooks/useDeviceProfileQueryContext';
import { useThingsModelValueTransform } from '/@/views/visual/palette/hooks/useThingsModelValueTransform';
const props = defineProps<{
config: ComponentPropsConfigType<typeof option>;
}>();
const currentValue = ref<string | number>(123);
const time = ref<Nullable<number>>(null);
const { getDeviceProfileTslByIdWithIdentifier } = useDeviceProfileQueryContext();
const getThingModelTsl = computed(() => {
const { option } = props.config;
const { deviceProfileId, attribute } = option;
return getDeviceProfileTslByIdWithIdentifier?.(deviceProfileId, attribute);
});
const getDesign = computed(() => {
const { persetOption = {}, option } = props.config;
const {
fontColor: persetFontColor,
valueSize: persetValueSize,
fontSize: persetFontSize,
} = persetOption;
const { componentInfo, attribute, attributeRename } = option;
const { fontColor, valueSize, fontSize } = componentInfo || {};
return {
fontColor: fontColor || persetFontColor,
valueSize: valueSize || persetValueSize || 20,
fontSize: fontSize || persetFontSize || 14,
attribute: attributeRename || unref(getThingModelTsl)?.functionName || attribute,
};
});
const updateFn: DataFetchUpdateFn = (message, attribute) => {
const { data = {} } = message;
const [info] = data[attribute] || [];
if (!info.length) return;
const [timespan, value] = info;
currentValue.value = useThingsModelValueTransform(
value,
unref(getThingModelTsl)?.specs?.dataType
);
time.value = timespan;
};
useDataFetch(props, updateFn);
const { getScale, getRatio } = useComponentScale(props);
</script>
<template>
<main class="w-full h-full flex flex-col justify-center items-center">
<DeviceName :config="config" />
<div class="flex-1 flex justify-center items-center flex-col w-full" :style="getScale">
<h1
class="my-4 font-bold !my-2 truncate w-full text-center"
:style="{
color: getDesign.fontColor,
fontSize: (getRatio ? getRatio * getDesign.valueSize : getDesign.valueSize) + 'px',
}"
>
{{ currentValue || 0 }}
</h1>
<div
class="text-gray-500 truncate"
:style="{
fontSize: (getRatio ? getRatio * getDesign.fontSize : getDesign.fontSize) + 'px',
}"
>{{ getDesign.attribute || '温度' }}</div
>
</div>
<UpdateTime :time="time" />
</main>
</template>