index.vue
4.08 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<script lang="ts" setup>
import { ComponentPropsConfigType } from '../../../index.type';
import { option } from './config';
import { ref, unref } from 'vue';
import { SvgIcon } from '/@/components/Icon';
import { computed } from 'vue';
import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
import { useReceiveMessage } from '../../../hook/useReceiveMessage';
import { useReceiveValue } from '../../../hook/useReceiveValue';
import { useMultipleDataFetch } from '../../../hook/socket/useSocket';
import { MultipleDataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
import { useComponentScale } from '../../../hook/useComponentScale';
const props = defineProps<{
config: ComponentPropsConfigType<typeof option>;
}>();
const time = ref<Nullable<number>>(null);
const getDesign = computed(() => {
const { persetOption = {}, option } = props.config;
const { dataSource = [] } = option || {};
const {
unit: persetUnit,
fontColor: persetFontColor,
icon: persetIcon,
iconColor: persetIconColor,
valueSize: persetValueSize,
fontSize: persetFontSize,
} = persetOption || {};
return {
dataSource: dataSource.map((item) => {
const { fontColor, icon, iconColor, unit, valueSize, fontSize } = item.componentInfo;
const { attribute, attributeRename, deviceName, deviceRename, deviceId, attributeName } =
item;
return {
unit: unit ?? persetUnit,
fontColor: fontColor ?? persetFontColor,
icon: icon ?? persetIcon,
iconColor: iconColor ?? persetIconColor,
attribute,
deviceName: deviceRename || deviceName,
attributeName: attributeRename || attributeName,
id: deviceId,
valueSize: valueSize || persetValueSize || 20,
fontSize: fontSize || persetFontSize || 14,
};
}),
};
});
const defaultSvgList = ref<any>([
{
value: 26.2,
deviceName: '温湿度',
attributeName: '温度',
icon: 'zongfushe',
unit: '℃',
iconColor: '#367BFF',
fontColor: '#357CFB',
},
{
value: 53.7,
deviceName: '温湿度',
attributeName: '湿度',
icon: 'guangzhaoqiangdu',
unit: '℃',
iconColor: '#FFA000',
fontColor: '#FFA000',
},
]);
const { forEachGroupMessage } = useReceiveMessage();
const { getNumberValue } = useReceiveValue();
const updateSvgList = ref(
props.config.option.dataSource ? unref(getDesign).dataSource : defaultSvgList
);
const updateFn: MultipleDataFetchUpdateFn = (message, deviceId, attribute) => {
forEachGroupMessage(message, deviceId, attribute, (attribute, value, timespan) => {
updateSvgList.value.forEach((item) => {
if (item.id === deviceId && item.attribute === attribute && value) {
item.value = getNumberValue(value);
time.value = timespan;
}
});
});
};
useMultipleDataFetch(props, updateFn);
const { getRatio } = useComponentScale(props);
</script>
<template>
<main class="w-full h-full flex flex-col justify-evenly items-center">
<DeviceName :config="config" />
<div
style="width: 86%"
v-for="item in updateSvgList"
:key="item.id"
class="flex justify-between items-center mt-2"
>
<div class="flex items-center">
<SvgIcon
:name="item.icon!"
prefix="iconfont"
:size="getRatio ? 30 * getRatio : 30"
:style="{ color: item.iconColor }"
/>
<div
class="text-gray-500 ml-6"
:style="{ fontSize: (getRatio ? getRatio * item.fontSize : item.fontSize) + 'px' }"
>{{ item.deviceName + '-' + item.attributeName || '温度' }}</div
>
</div>
<span
:style="{
color: item.fontColor,
fontSize: (getRatio ? getRatio * item.valueSize : item.valueSize) + 'px',
}"
>
<span> {{ item.value || 0 }}</span>
<span>{{ item.unit }} </span>
</span>
</div>
<!-- <UpdateTime :time="time" /> -->
</main>
</template>