index.vue
2.02 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
<script lang="ts" setup>
import { ComponentPropsConfigType } from '/@/views/visual/packages/index.type';
import { option } from './config';
import { useComponentScale } from '/@/views/visual/packages/hook/useComponentScale';
import { ref, onMounted, unref } from 'vue';
import { useIntervalFn } from '@vueuse/core';
import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
import { useReceiveValue } from '../../../hook/useReceiveValue';
import { useDataFetch } from '../../../hook/socket/useSocket';
import { DataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
const props = defineProps<{
config: ComponentPropsConfigType<typeof option>;
}>();
const isOpenClose = ref<boolean>(true);
const randomFn = () => {
useIntervalFn(() => {
isOpenClose.value = !unref(isOpenClose);
}, 2000);
};
const { getNumberValue } = useReceiveValue();
const updateFn: DataFetchUpdateFn = (message, attribute) => {
const { data = {} } = message;
const [latest] = data[attribute] || [];
const [_, value] = latest;
isOpenClose.value = Boolean(getNumberValue(value));
};
onMounted(() => {
!props.config.option.uuid && randomFn();
});
useDataFetch(props, updateFn);
const { getScale } = useComponentScale(props);
</script>
<template>
<main :style="getScale" class="w-full h-full flex flex-col justify-center items-center">
<DeviceName :config="config" class="text-center" />
<div
style="--open-color: `${getDesign.openColor}`; --close-color: `${getDesign.closeColor}`"
:class="isOpenClose ? 'switch_open' : 'switch_close'"
>
</div>
</main>
</template>
<style lang="less" scoped>
.switch_open {
background: var(--open-color);
box-shadow: var(--open-color) 0 0 10px 3px;
width: 60px;
height: 60px;
border-radius: 50%;
margin: 10px 0;
}
.switch_close {
background-color: var(--close-color);
box-shadow: none;
width: 42.023px;
height: 42.023px;
border-radius: 50%;
margin: 10px 0;
}
</style>