index.vue
2.6 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
<script lang="ts" setup>
import { ComponentPropsConfigType } from '/@/views/visual/packages/index.type';
import { option } from './config';
import { SvgIcon } from '/@/components/Icon';
import { computed, ref } from 'vue';
import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
import { UpdateTime } from '/@/views/visual/commonComponents/UpdateTime';
import { useDataFetch } from '../../../hook/socket/useSocket';
import { DataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
import { useReceiveValue } from '../../../hook/useReceiveValue';
const props = defineProps<{
config: ComponentPropsConfigType<typeof option>;
}>();
const time = ref<Nullable<number>>(null);
const isOpenClose = ref<boolean>(true);
const getDesign = computed(() => {
const { persetOption = {}, option } = props.config;
const {
iconColor: persetIconColor,
unit: perseUnit,
icon: persetIcon,
fontColor: persetFontColor,
iconClose: persetIconCLose,
iconColorClose: persetIconColorClose,
showTime: persetShowTime,
} = persetOption;
const { componentInfo, attributeRename } = option;
const { icon, iconColor, fontColor, unit, iconClose, iconColorClose, attributeName, showTime } =
componentInfo || {};
return {
iconColor: iconColor || persetIconColor,
unit: unit ?? perseUnit,
icon: icon || persetIcon,
fontColor: fontColor || persetFontColor,
attribute: attributeRename || attributeName,
iconClose: iconClose || persetIconCLose,
iconColorClose: iconColorClose || persetIconColorClose,
showTime: showTime ?? persetShowTime,
};
});
const { getNumberValue } = useReceiveValue();
const updateFn: DataFetchUpdateFn = (message, attribute) => {
const { data = {} } = message;
const [latest] = data[attribute] || [];
const [timespan, value] = latest;
time.value = timespan;
isOpenClose.value = Boolean(getNumberValue(value));
};
useDataFetch(props, updateFn);
</script>
<template>
<main class="w-full h-full flex flex-col justify-center items-center">
<DeviceName :config="config" />
<div class="flex flex-1 flex-col justify-center items-center">
<SvgIcon
:name="isOpenClose ? getDesign.icon : getDesign.iconClose"
prefix="iconfont"
:size="60"
:style="{ color: isOpenClose ? getDesign.iconColor : getDesign.iconColorClose }"
/>
<div class="text-gray-500 text-sm truncate m-2">{{ getDesign.attribute || '温度' }}</div>
</div>
<UpdateTime v-show="getDesign.showTime" :time="time" />
</main>
</template>