DigitalDashBoard.vue
6.28 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
<script lang="ts" setup>
import { computed, onMounted, onUnmounted, ref, unref } from 'vue';
import { Space, Tooltip } from 'ant-design-vue';
import {
DigitalComponentDefaultConfig,
DigitalDashBoardLayout,
DigitalDashBoardValue,
} from './digitalDashBoard.config';
import { dateUtil } from '/@/utils/dateUtil';
import {
fontSize,
RadioRecord,
DEFAULT_DATE_FORMAT,
DEFAULT_RADIO_RECORD,
DEFAULT_ANIMATION_INTERVAL,
} from '../../detail/config/util';
import { isNaN } from 'lodash';
const props = defineProps<{
layout: DigitalDashBoardLayout;
value: DigitalDashBoardValue;
radio?: RadioRecord;
random?: boolean;
}>();
const changeValue = ref(0);
const getPropsValue = computed(() => {
return { value: unref(changeValue), ...DigitalComponentDefaultConfig, ...props.value };
});
const integerPart = computed(() => {
let { value = 0 } = unref(getPropsValue);
const { max = 5 } = props.layout;
if (isNaN(value)) value = 0;
let _value = Number(value).toFixed(2).split('.')[0];
if (_value.length < max) _value = _value.padStart(5, '0');
if (_value.length > max) _value = ''.padStart(5, '9');
return _value;
});
const decimalPart = computed(() => {
let { value = 0 } = unref(getPropsValue);
const { keepNumber = 2 } = props.layout;
if (isNaN(value)) value = 0;
let _value = Number(value)?.toFixed(2).split('.')[1];
if (_value.length < keepNumber) _value = _value.padStart(5, '0');
if (_value.length > keepNumber) _value = ''.padStart(5, '0');
return _value;
});
const getRadio = computed(() => {
// const { radio } = props.radio || DEFAULT_RADIO_RECORD;
// return radio;
return props.radio || DEFAULT_RADIO_RECORD;
});
let timeout: Nullable<number> = null;
const handleRandom = () => {
const newValue = Math.floor(Math.random() * 100);
changeValue.value = newValue;
};
const getScale = computed(() => {
const { width } = props.radio || DEFAULT_RADIO_RECORD;
return width / 360 > 1 ? 1 : width / 360;
});
onMounted(() => {
if (props.random)
timeout = setInterval(handleRandom, DEFAULT_ANIMATION_INTERVAL) as unknown as number;
});
onUnmounted(() => {
clearInterval(timeout as number);
timeout = null;
});
</script>
<template>
<section class="w-full h-full">
<div class="flex flex-col w-full h-full">
<div class="flex-1 flex justify-center items-center">
<div class="flex px-4 items-center" :style="{ transform: `scale(${getScale})` }">
<Space
justify="end"
class="justify-end"
:size="4"
:style="{
backgroundColor: '#585357',
padding: fontSize({ radioRecord: getRadio, basic: 10 }),
}"
>
<div
v-for="number in integerPart"
:key="number"
class="digital-wrapper__int"
:style="{
color: getPropsValue.fontColor,
fontSize: fontSize({ radioRecord: getRadio, basic: 20, max: 20 }),
padding: fontSize({ radioRecord: getRadio, basic: 5 }),
}"
>
<div class="digital-text__int p-1 text-light-50"> {{ number }}</div>
</div>
</Space>
<div
class="m-0.5 rounded-1/2"
style="background-color: #333; width: 6px; height: 6px; align-self: flex-end"
>
</div>
<Space
justify="end"
class="justify-end"
:size="4"
:style="{
backgroundColor: '#b74940',
padding: fontSize({ radioRecord: getRadio, basic: 10 }),
}"
>
<div
v-for="number in decimalPart"
:key="number"
class="digital-wrapper__float"
:style="{
color: getPropsValue.fontColor,
fontSize: fontSize({ radioRecord: getRadio, basic: 20, max: 20 }),
padding: fontSize({ radioRecord: getRadio, basic: 5 }),
}"
>
<div class="digital-text__float p-1 text-light-50">
{{ number }}
</div>
</div>
</Space>
<div
class="px-1 font-bold"
:style="{ fontSize: fontSize({ radioRecord: getRadio, basic: 18, max: 18 }) }"
>
{{ getPropsValue.unit }}
</div>
</div>
</div>
<div
class="text-center truncate"
:style="{ fontSize: fontSize({ radioRecord: getRadio, basic: 18 }) }"
>
<span>{{ props.value.name || '电表' }}</span>
</div>
<Tooltip
placement="top"
:title="
props.value?.updateTime
? dateUtil(props?.value?.updateTime).format(DEFAULT_DATE_FORMAT)
: '暂无更新时间'
"
>
<div
class="text-center text-xs truncate p-5"
:style="{
fontSize: fontSize({ radioRecord: getRadio, basic: 12, max: 16 }),
color: '#999',
}"
>
<span class="mr-1">更新时间:</span>
<span>
{{
props.value?.updateTime
? dateUtil(props?.value?.updateTime).format(DEFAULT_DATE_FORMAT)
: '暂无更新时间'
}}
</span>
</div>
</Tooltip>
</div>
<div></div>
</section>
</template>
<style scoped lang="less">
.digital-wrapper__int {
border-radius: 1px;
box-shadow: inset 0px 1px 3px 0px rgba(0, 0, 0, 0.7);
background: url('/@/assets/images/digital-wrapper-bg-int.png') 0px -1px no-repeat;
padding: 5px;
background-size: 100% 100%;
}
.digital-text_int {
display: inline-block;
overflow-wrap: break-word;
color: rgba(255, 255, 255, 1);
white-space: nowrap;
text-align: center;
}
.digital-wrapper__float {
border-radius: 1px;
box-shadow: inset 0px 1px 3px 0px rgba(112, 22, 15, 1);
background: url('/@/assets/images/digital-wrapper-bg-float.png') 0px -1px no-repeat;
padding: 5px;
background-size: 100% 100%;
}
.digital-text_float {
display: inline-block;
overflow-wrap: break-word;
color: rgba(255, 255, 255, 1);
white-space: nowrap;
text-align: center;
}
</style>