-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
192 lines (161 loc) · 4.73 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ESP32-控制面板</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #ffffff;
}
.nav {
width: 100%;
height: 60px;
line-height: 60px;
text-align: center;
font-size: 20px;
color: #ffffff;
background-color: #4091f7;
margin-bottom: 40px;
}
.layer {
margin: 0;
color: #000000d9;
font-size: 18px;
font-variant: tabular-nums;
line-height: 1.5715;
list-style: none;
font-feature-settings: "tnum";
position: relative;
display: none;
justify-content: center;
align-items: center;
padding: 8px 15px;
word-wrap: break-word;
border-radius: 2px;
background: #ffffff;
box-sizing: border-box;
box-shadow: 0 3px 6px -4px #0000001f, 0 6px 16px #00000014, 0 9px 28px 8px #0000000d;
position: absolute;
left: 50%;
top: 10%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
}
.container {
display: flex;
justify-content: space-evenly;
margin-bottom: 40px;
}
.button {
width: 150px;
height: 150px;
border-radius: 14%;
text-align: center;
}
.header svg {
width: 100px;
height: 100px;
margin-top: 10px;
}
.container .body {
font-size: 20px;
}
.body.weather {
color: #96d1f7;
}
.body.calendar {
color: #1296db;
}
.body.time {
color: #db639b;
}
.body.await {
color: #ee6c38;
}
</style>
</head>
<body>
<div class="nav">
切换模式
</div>
<div class="layer">
</div>
<div class="container">
<div class="button button-left weather">
<div class="body weather">
天气
</div>
</div>
<div class="button button-left calendar">
<div class="body calendar">
日历
</div>
</div>
</div>
<div class="container">
<div class="button button-right timer">
<div class="body timer">
时钟
</div>
</div>
<div class="button button-right screensaver">
<div class="body screensaver">
待机
</div>
</div>
</div>
</body>
<script>
let url = 'http://192.168.3.4:8000'
let weather = document.querySelector('.button.weather')
weather.addEventListener('click', () => { handleSwitchPattern('weather') })
let calendar = document.querySelector('.button.calendar')
calendar.addEventListener('click', () => { handleSwitchPattern('calendar') })
let time = document.querySelector('.button.timer')
time.addEventListener('click', () => { handleSwitchPattern('timer') })
let wait = document.querySelector('.button.screensaver')
wait.addEventListener('click', () => { handleSwitchPattern('screensaver') })
let handleSwitchPattern = async pattern => {
const resp = await fetch(url + '/switch', {
method: 'POST',
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
},
body: `pattern=${pattern}`,
})
const json = await resp.json()
console.log(json)
console.log('handleSwitchPattern', pattern)
let msg = ''
switch (pattern) {
case 'weather':
msg = '已切换天气模式'
break;
case 'calendar':
msg = '已切换日历模式'
break;
case 'timer':
msg = '已切换时钟模式'
break;
case 'screensaver':
msg = '已切换待机模式'
break;
}
handleShowAlert(msg)
}
let handleShowAlert = (msg) => {
let layer = document.querySelector('.layer')
if (!layer.style.display) {
layer.innerText = msg
layer.style.setProperty('display', 'flex')
setTimeout(() => {
layer.style.setProperty('display', '')
}, 1000);
}
}
</script>
</html>