index.vue
7.95 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<script lang="ts" setup>
import { ComponentMode, ComponentPropsConfigType } from '/@/views/visual/packages/index.type';
import { option } from './config';
import { Spin } from 'ant-design-vue';
import { computed, ref, unref } from 'vue';
import { useComponentScale } from '../../../hook/useComponentScale';
import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
import { DataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
import { useDataFetch } from '../../../hook/socket/useSocket';
import PasswordModal from '../component/PasswordModal.vue';
import { useModal } from '/@/components/Modal';
import { useDeviceProfileQueryContext } from '/@/views/visual/palette/hooks/useDeviceProfileQueryContext';
import { useControlComand } from '../../../hook/useControlCommand';
import { useI18n } from '/@/hooks/web/useI18n';
const props = defineProps<{
config: ComponentPropsConfigType<typeof option>;
}>();
const { t } = useI18n();
const { getScale, getRatio } = useComponentScale(props);
const currentValue = ref(false);
const { getDeviceProfileTslByIdWithIdentifier } = useDeviceProfileQueryContext();
const getDesign = computed(() => {
const { option, persetOption } = props.config;
const { attribute, deviceProfileId, attributeRename, commandType, componentInfo } = option;
const { fontSize: persetFontSize, password: persetPassword } = persetOption || {};
const { fontSize, password } = componentInfo || {};
const tsl = getDeviceProfileTslByIdWithIdentifier?.(deviceProfileId, attribute);
return {
attribute: attributeRename || tsl?.functionName || attribute,
password: password || persetPassword,
commandType,
fontSize: fontSize || persetFontSize || 14,
};
});
const { loading, doControlSendCommand } = useControlComand();
const handleSendCommand = async () => {
if (props.config.option.mode === ComponentMode.SELECT_PREVIEW) return;
const { option } = props.config || {};
const result = await doControlSendCommand(option, Number(!unref(currentValue)));
currentValue.value = result ? !unref(currentValue) : unref(currentValue);
};
const handleChange = async (event: Event) => {
if (unref(getDesign).password) {
const target = event.target as HTMLInputElement;
const value = target.checked;
target.checked = !value;
currentValue.value = !value;
openModal(true, { password: unref(getDesign).password, control: event });
return;
}
handleSendCommand();
};
const updateFn: DataFetchUpdateFn = (message, attribute) => {
const { data = {} } = message;
const [latest] = data[attribute] || [];
const [_, value] = latest;
currentValue.value = isNaN(value as unknown as number) ? false : !!Number(value);
};
useDataFetch(props, updateFn);
const [registerModal, { openModal }] = useModal();
</script>
<template>
<main class="w-full h-full flex flex-col justify-center">
<DeviceName :config="config" class="text-center" />
<main class="w-full h-full flex flex-col justify-center items-center">
<Spin :spinning="loading" class="w-full h-full">
<div class="toggle-switch" :style="{ transform: `scale(${getRatio})` }">
<label class="switch">
<input type="checkbox" :checked="currentValue" @change="handleChange" />
<div class="button">
<div class="light"></div>
<div class="dots"></div>
<div class="characters"></div>
<div class="shine"></div>
<div class="shadow"></div>
</div>
</label>
</div>
<div
class="text-center mt-2 text-gray-500"
:style="{
...getScale,
fontSize: (getRatio ? getRatio * getDesign.fontSize : getDesign.fontSize) + 'px',
}"
>{{ getDesign.attribute || t('business.attributeText') }}</div
>
</Spin>
</main>
<PasswordModal @register="registerModal" @success="handleSendCommand" />
</main>
</template>
<style scoped>
:deep(.ant-spin-container) {
@apply !flex !flex-col justify-evenly items-center;
width: 100%;
height: 100%;
}
:deep(.ant-spin-nested-loading) {
width: 100%;
height: 100%;
}
.toggle-switch {
/* flex: 1 1 auto; */
max-width: 75px;
width: 75px;
max-height: 100px;
height: 100px;
/* height: 97.5px; */
display: flex;
}
.switch {
background-color: black;
box-sizing: border-box;
width: 100%;
height: 100%;
box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.2), 0 0 1px 2px black, inset 0 2px 2px -2px white,
inset 0 0 2px 15px #47434c, inset 0 0 2px 22px black;
border-radius: 5px;
padding: 10px;
perspective: 700px;
}
.switch input {
display: none;
}
.switch input:checked + .button {
transform: translateZ(20px) rotateX(25deg);
box-shadow: 0 -5px 10px #ff1818;
}
.switch input:checked + .button .light {
animation: flicker 0.2s infinite 0.3s;
}
.switch input:checked + .button .shine {
opacity: 1;
}
.switch input:checked + .button .shadow {
opacity: 0;
}
.switch .button {
display: flex;
justify-content: center;
align-items: center;
transition: all 0.3s cubic-bezier(1, 0, 1, 1);
transform-origin: center center -20px;
transform: translateZ(20px) rotateX(-25deg);
transform-style: preserve-3d;
width: 100%;
height: 100%;
position: relative;
cursor: pointer;
background: linear-gradient(#980000 0%, #6f0000 30%, #6f0000 70%, #980000 100%);
background-color: #9b0621;
background-repeat: no-repeat;
}
.switch .button::before {
content: '';
background: linear-gradient(
rgba(255, 255, 255, 0.8) 10%,
rgba(255, 255, 255, 0.3) 30%,
#650000 75%,
#320000
)
50% 50%/97% 97%,
#b10000;
background-repeat: no-repeat;
width: 100%;
height: 30px;
transform-origin: top;
transform: rotateX(-90deg);
position: absolute;
top: 0;
}
.switch .button::after {
content: '';
background-image: linear-gradient(#650000, #320000);
width: 100%;
height: 30px;
transform-origin: top;
transform: translateY(30px) rotateX(-90deg);
position: absolute;
bottom: 0;
box-shadow: 0 30px 8px 0 black, 0 60px 20px 0 rgb(0 0 0 / 50%);
}
.switch .light {
opacity: 0;
animation: light-off 1s;
position: absolute;
width: 80%;
height: 80%;
background-image: radial-gradient(#ffc97e, transparent 40%),
radial-gradient(circle, #ff1818 50%, transparent 80%);
}
.switch .dots {
position: absolute;
width: 100%;
height: 100%;
background-image: radial-gradient(transparent 30%, rgba(101, 0, 0, 0.7) 70%);
background-size: 10px 10px;
}
.switch .characters {
position: absolute;
width: 100%;
height: 100%;
background: linear-gradient(white, white) 50% 20%/5% 20%,
radial-gradient(circle, transparent 50%, white 52%, white 70%, transparent 72%) 50% 80%/33%
25%;
background-repeat: no-repeat;
}
.switch .shine {
transition: all 0.3s cubic-bezier(1, 0, 1, 1);
opacity: 0.3;
position: absolute;
width: 100%;
height: 100%;
background: linear-gradient(white, transparent 3%) 50% 50%/97% 97%,
linear-gradient(
rgba(255, 255, 255, 0.5),
transparent 50%,
transparent 80%,
rgba(255, 255, 255, 0.5)
)
50% 50%/97% 97%;
background-repeat: no-repeat;
}
.switch .shadow {
transition: all 0.3s cubic-bezier(1, 0, 1, 1);
opacity: 1;
position: absolute;
width: 100%;
height: 100%;
background: linear-gradient(transparent 70%, rgba(0, 0, 0, 0.8));
background-repeat: no-repeat;
}
@keyframes flicker {
0% {
opacity: 1;
}
80% {
opacity: 0.8;
}
100% {
opacity: 1;
}
}
@keyframes light-off {
0% {
opacity: 1;
}
80% {
opacity: 0;
}
}
</style>