index.vue
6.42 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<script lang="ts" setup>
import { ComponentPropsConfigType } from '/@/views/visual/packages/index.type';
import { option } from './config';
import { computed } from 'vue';
import { ref } from 'vue';
import { unref } 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 { useComponentScale } from '../../../hook/useComponentScale';
import { useDeviceProfileQueryContext } from '/@/views/visual/palette/hooks/useDeviceProfileQueryContext';
const props = defineProps<{
config: ComponentPropsConfigType<typeof option>;
}>();
const currentValue = ref(25);
const time = ref<Nullable<number>>(null);
const { getDeviceProfileTslByIdWithIdentifier } = useDeviceProfileQueryContext();
const getDesign = computed(() => {
const { option, persetOption } = props.config;
const { componentInfo, attribute, attributeRename, deviceProfileId } = option;
const { functionName } =
getDeviceProfileTslByIdWithIdentifier?.(deviceProfileId, attribute) || {};
const { flowmeterConfig, unit, fontColor, showTime, maxNumber, fontSize, valueSize } =
componentInfo || {};
const { backgroundColor, waveFirst, waveSecond, waveThird } = flowmeterConfig || {};
const {
flowmeterConfig: presetFlowmeterConfig,
unit: persetUnit,
fontColor: presetFontColor,
showTime: persetShowTime,
maxNumber: persetMaxNumber,
fontSize: persetFontSize,
valueSize: persetValueSize,
} = persetOption || {};
const {
backgroundColor: presetBackgroundColor,
waveFirst: presetWaveFirst,
waveSecond: presetWaveSecond,
waveThird: presetWaveThird,
} = presetFlowmeterConfig || {};
return {
backgroundColor: backgroundColor ?? presetBackgroundColor,
waveFirst: waveFirst ?? presetWaveFirst,
waveSecond: waveSecond ?? presetWaveSecond,
waveThird: waveThird ?? presetWaveThird,
unit: unit ?? persetUnit,
fontColor: fontColor ?? presetFontColor,
attribute: attributeRename || functionName,
showTime: showTime ?? persetShowTime,
maxNumber: maxNumber ?? persetMaxNumber,
fontSize: fontSize || persetFontSize || 14,
valueSize: valueSize || persetValueSize || 20,
};
});
const getWaveHeight = computed(() => {
const value = unref(currentValue);
const size = ref(1);
if (unref(getDesign).maxNumber > 100) {
size.value = 100 / unref(getDesign).maxNumber;
}
return value * unref(size) <= 0 ? 0 : -(value * unref(size)) - 15;
});
const getHeight = computed(() => {
const value = unref(currentValue);
const size = ref(1);
if (unref(getDesign).maxNumber > 100) {
size.value = 100 / unref(getDesign).maxNumber;
}
return value * unref(size) >= 100 ? 0 : 100 - value * unref(size) + 10;
});
const updateFn: DataFetchUpdateFn = (message, attribute) => {
const { data = {} } = message;
const [latest] = data[attribute] || [];
const [timespan, value] = latest;
if (!latest.length) return;
time.value = timespan;
currentValue.value = Number(value);
};
useDataFetch(props, updateFn);
const { getRatio } = useComponentScale(props);
</script>
<template>
<main
class="w-full h-full flex flex-col justify-center items-center relative"
:class="!getDesign.showTime && 'p-5'"
>
<DeviceName :config="config" />
<svg
class="waves-rect"
viewBox="0 0 100 100"
preserveAspectRatio="none"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
>
<defs>
<path
id="wave"
d="M-160 118c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v100h-352z"
/>
</defs>
<rect
class="bgColor"
x="0"
y="0"
width="100"
height="100"
:fill="getDesign.backgroundColor"
/>
<g class="height" :transform="`translate(0 ${getWaveHeight})`">
<use class="wave waveFirst" xlink:href="#wave" :fill="getDesign.waveFirst" x="0" y="0" />
<use class="wave waveSecond" xlink:href="#wave" :fill="getDesign.waveSecond" x="0" y="2" />
<use class="wave waveThird" xlink:href="#wave" :fill="getDesign.waveThird" x="0" y="4" />
</g>
<rect
class="waveThird"
:transform="`translate(0 ${getHeight})`"
x="0"
y="0"
width="100"
height="100"
:fill="getDesign.waveThird"
/>
</svg>
<div
class="absolute w-full h-full top-0 left-0 text-center text-lg flex items-center justify-center"
:style="{
color: getDesign.fontColor,
fontSize: (getRatio ? getRatio * getDesign.valueSize : getDesign.valueSize) + 'px',
}"
>
<div>{{ currentValue }}</div>
<div class="ml-1">{{ getDesign.unit }}</div>
</div>
<div
class="text-gray-500"
style="flex: 0 0 20px"
:style="{
fontSize: (getRatio ? getRatio * getDesign.fontSize : getDesign.fontSize) + 'px',
height: (getRatio ? getRatio * getDesign.fontSize : getDesign.fontSize) + 'px',
}"
>{{ getDesign.attribute || '属性' }}</div
>
<UpdateTime v-show="getDesign.showTime" :time="time" />
</main>
</template>
<style lang="less" scoped>
.waves-rect {
width: 90%;
height: 90%;
}
@keyframes move {
from {
transform: translate(-90px, 0%);
}
to {
transform: translate(85px, 0%);
}
}
.wave {
animation: move 3s linear infinite;
animation-play-state: running;
}
.wave:nth-child(1) {
animation-delay: -2s;
animation-duration: 9s;
}
.wave:nth-child(2) {
animation-delay: -4s;
animation-duration: 6s;
}
.wave:nth-child(3) {
animation-delay: -6s;
animation-duration: 3s;
}
.waves-rect > g + rect {
// transform: translateY(
// calc(calc(100 - var(--value)) * var(--full-flag) * 1% + var(--full-flag) * 15%)
// );
transition: transform linear 1s;
}
.height {
// transform: translateY(calc(var(--value) * -1% - 10% + var(--over-min-flag) * 10%));
transition: transform linear 1s;
}
.waves-rect .text {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: #fff;
font-weight: 700;
}
</style>