index.vue
4.39 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
<script lang="ts" setup>
import { ComponentPropsConfigType, DataFetchUpdateFn } from '/@/views/visual/packages/index.type';
import { option } from './config';
import { useDataFetch } from '/@/views/visual/packages/hook/useSocket';
import { computed } from 'vue';
import { ref } from 'vue';
import { unref } from 'vue';
import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
const props = defineProps<{
config: ComponentPropsConfigType<typeof option>;
}>();
const currentValue = ref(25);
const getDesign = computed(() => {
const { option, persetOption } = props.config;
const { componentInfo } = option;
const { flowmeterConfig, unit, fontColor } = componentInfo || {};
const { backgroundColor, waveFirst, waveSecond, waveThird } = flowmeterConfig || {};
const {
flowmeterConfig: presetFlowmeterConfig,
unit: persetUnit,
fontColor: presetFontColor,
} = 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,
};
});
const getSize = computed(() => {
const { option } = props.config;
const { itemHeightRatio, itemWidthRatio, widthPx, heightPx } = option;
const currentW = (widthPx * itemWidthRatio) / 100;
const currentH = (heightPx * itemHeightRatio) / 100;
const size = Math.min(currentW, currentH);
return size;
});
const getWaveHeight = computed(() => {
const value = unref(currentValue);
return value <= 0 ? 0 : -value - 15;
});
const getHeight = computed(() => {
const value = unref(currentValue);
return value >= 100 ? 0 : 100 - value + 10;
});
const updateFn: DataFetchUpdateFn = (message, attribute) => {
const { data = {} } = message;
const [latest] = data[attribute] || [];
const [_, value] = latest;
currentValue.value = Number(value);
};
useDataFetch(props, updateFn);
</script>
<template>
<main class="w-full h-full flex flex-col justify-center items-center relative">
<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"
clip-path="circle()"
transform="scale(0.9)"
:style="{ width: `${getSize}px`, height: `${getSize}px` }"
>
<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>
<circle cx="50" cy="50" r="50" :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
: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 flex-col"
:style="{ color: getDesign.fontColor }"
>
<div>{{ currentValue }}</div>
<div class="ml-1">{{ getDesign.unit }}</div>
</div>
</main>
</template>
<style lang="less" scoped>
@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 {
transition: transform linear 1s;
}
.height {
transition: transform linear 1s;
}
</style>