-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_interface.html
More file actions
408 lines (366 loc) · 14 KB
/
Copy pathuser_interface.html
File metadata and controls
408 lines (366 loc) · 14 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<link rel="icon" href="tupianwenjian/logo.ico">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>天衍云阁 - 用户界面</title>
<style>
/* 引入字体 */
@font-face {
font-family: Aa瘦金体粗;
src: url(../shouye/宋徽宗瘦金加粗版-Regular.ttf);
}
@font-face {
font-family: 瘦金体;
src: url(../shouye/宋徽宗瘦金体_爱给网_aigei_com.ttf);
}
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
/* 新的主题背景颜色 */
background: #F6D365;
background: linear-gradient(90deg, #F6D365 0%, #FDA085 100%);
margin: 0;
padding: 0;
display: flex;
/* 修改布局方向为垂直排列 */
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
}
/* 整体容器 - 玻璃面板效果 */
.container {
background: rgba(255, 255, 255, 0.2);
border-radius: 16px;
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
border: 1px solid rgba(255, 255, 255, 0.3);
width: 800px;
padding: 32px;
margin-bottom: 20px; /* 为容器下方添加间距 */
}
/* 信息展示部分 */
.info-display {
text-align: center;
}
.info-display .user-avatar {
width: 180px;
height: 180px;
border-radius: 50%;
object-fit: cover;
border: 4px solid #cbd5e0;
margin-bottom: 24px;
transition: transform 0.3s ease;
}
.info-display .user-avatar:hover {
transform: scale(1.05);
}
.info-display .user-detail {
font-size: 18px;
color: #4a5568;
font-family: 瘦金体;
}
.info-display .user-detail p {
margin: 8px 0;
}
.info-display .user-detail span {
font-weight: 600;
color: #2d3748;
}
/* 通用按钮样式 */
.gradient-button {
background-image: linear-gradient(to right, #FFD59E 0%, #FFA781 51%, #FFD59E 100%);
transition: 0.5s;
background-size: 200% auto;
color: #fff;
font-family: Aa瘦金体粗;
padding: 12px 24px;
border: none;
border-radius: 8px;
font-size: 18px;
cursor: pointer;
}
.gradient-button:hover {
background-position: right center;
color: #c30f0f;
}
/* 信息编辑部分 */
.info-edit {
display: none;
}
.info-edit label {
display: block;
font-size: 16px;
font-weight: 600;
color: #2d3748;
margin-bottom: 8px;
font-family: 瘦金体;
}
.info-edit input {
width: 100%;
padding: 12px;
border: 1px solid #cbd5e0;
border-radius: 8px;
font-size: 16px;
margin-bottom: 24px;
transition: border-color 0.3s ease;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
border: 1px solid rgba(255, 255, 255, 0.3);
color: #2d3748;
}
.info-edit input:focus {
border-color: #48bb78;
outline: none;
}
/* 美化文件选择框 */
.info-edit input[type="file"] {
display: none; /* 隐藏默认的文件选择框 */
}
/* 自定义文件选择按钮 */
.file-upload-label {
background-image: linear-gradient(to right, #FFD59E 0%, #FFA781 51%, #FFD59E 100%);
transition: 0.5s;
background-size: 200% auto;
color: #fff;
font-family: Aa瘦金体粗;
padding: 12px 24px;
border: none;
border-radius: 8px;
font-size: 18px;
cursor: pointer;
display: inline-block;
}
.file-upload-label:hover {
background-position: right center;
color: #c30f0f;
}
/* 显示已选择的文件名 */
#selected-file-name {
margin-left: 10px;
font-family: 瘦金体;
color: #2d3748;
}
.info-edit #avatar-preview {
width: 100px;
height: 100px;
border-radius: 50%;
object-fit: cover;
border: 2px solid #cbd5e0;
margin-top: 12px;
display: none;
}
/* 美化日期选择弹出框(部分浏览器支持) */
input[type="date"]::-webkit-calendar-picker-indicator {
background-color: #FFA781; /* 修改日期选择图标背景色 */
border-radius: 4px;
padding: 4px;
cursor: pointer;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover {
background-color: #FFD59E; /* 鼠标悬停时的背景色 */
}
/* 对 Firefox 等浏览器的日期选择器样式调整 */
input[type="date"]::-moz-calendar-picker {
background-color: #FFA781;
border-radius: 4px;
padding: 4px;
cursor: pointer;
}
input[type="date"]::-moz-calendar-picker:hover {
background-color: #FFD59E;
}
/* footer 样式 */
footer {
text-align: center;
color: #2d3748;
font-family: 瘦金体;
padding: 10px;
}
/* 返回上一级按钮样式 */
.btn-back {
background-image: linear-gradient(to right, #FFD59E 0%, #FFA781 51%, #FFD59E 100%);
transition: 0.5s;
background-size: 200% auto;
color: #fff;
font-family: Aa瘦金体粗;
padding: 12px 24px;
border: none;
border-radius: 8px;
font-size: 18px;
cursor: pointer;
margin-bottom: 10px;
}
.btn-back:hover {
background-position: right center;
color: #c30f0f;
}
/* 分界线样式 */
.divider {
width: 800px; /* 与容器宽度一致 */
border-top: 1px solid rgba(255, 255, 255, 0.5);
margin-bottom: 20px;
}
/* 媒体查询,当屏幕宽度小于 850px 时应用以下样式 */
@media (max-width: 850px) {
.container {
width: 90%;
padding: 20px;
box-sizing: border-box;
}
.info-edit {
width: 90%;
box-sizing: border-box;
}
.gradient-button,
.btn-back,
.file-upload-label {
width: 100%;
margin-bottom: 10px;
box-sizing: border-box;
}
}
</style>
</head>
<body>
<div class="container">
<!-- 信息展示部分 -->
<div class="info-display">
<img id="user-avatar" class="user-avatar" src="#" alt="用户头像">
<div class="user-detail">
<p>用户名:<span id="username"></span></p>
<p>昵称:<span id="nickname-display"></span></p>
<p>邮箱:<span id="email-display"></span></p>
<p>手机号:<span id="phone-display"></span></p>
<p>出生日期:<span id="birthdate-display"></span></p>
</div>
<!-- 应用通用按钮类 -->
<button class="gradient-button" onclick="showEditSection()">修改信息</button>
</div>
<!-- 信息编辑部分 -->
<div class="info-edit">
<label for="nickname">昵称:</label>
<input type="text" id="nickname" placeholder="请输入昵称">
<label for="email">邮箱:</label>
<input type="email" id="email" placeholder="example@domain.com">
<label for="phone">手机号:</label>
<input type="tel" id="phone" placeholder="请输入手机号">
<label for="birthdate">出生日期:</label>
<input type="date" id="birthdate">
<label for="avatar">上传头像:</label>
<!-- 自定义文件选择按钮 -->
<label for="avatar" class="file-upload-label">选择文件</label>
<span id="selected-file-name"></span>
<input type="file" id="avatar" accept="image/*" onchange="previewAvatar(event); showSelectedFileName(event)">
<img id="avatar-preview" class="user-avatar" style="display: none;" alt="头像预览">
<!-- 应用通用按钮类 -->
<button class="gradient-button" onclick="saveUserInfo()">保存修改</button>
<!-- 应用通用按钮类 -->
<button class="gradient-button" onclick="showDisplaySection()">取消</button>
</div>
</div>
<!-- 分界线 -->
<div class="divider"></div>
<footer>
<button class="btn btn-back" onclick="goBack()">返回上一级</button>
<p>版权所有 © 2023 天衍云阁</p>
</footer>
<script>
function loadUserInfo() {
fetch('/api/get_user_info.php')
.then(response => response.json())
.then(data => {
if (data.success) {
const user = data.data;
document.getElementById('user-avatar').src = user.avatar || 'default_avatar.png';
document.getElementById('username').textContent = user.username;
document.getElementById('nickname-display').textContent = user.nickname || '未设置';
document.getElementById('email-display').textContent = user.email || '未设置';
document.getElementById('phone-display').textContent = user.phone || '未设置';
document.getElementById('birthdate-display').textContent = user.birthdate || '未设置';
document.getElementById('nickname').value = user.nickname || '';
document.getElementById('email').value = user.email || '';
document.getElementById('phone').value = user.phone || '';
document.getElementById('birthdate').value = user.birthdate || '';
} else {
alert('加载用户信息失败:' + data.message);
}
})
.catch(error => {
console.error('加载用户信息失败:', error);
alert('加载用户信息失败,请检查网络或联系管理员');
});
}
function previewAvatar(event) {
const reader = new FileReader();
reader.onload = function (e) {
document.getElementById('avatar-preview').src = e.target.result;
document.getElementById('avatar-preview').style.display = 'block';
};
reader.readAsDataURL(event.target.files[0]);
}
function saveUserInfo() {
const formData = new FormData();
const nickname = document.getElementById('nickname').value;
const email = document.getElementById('email').value;
const phone = document.getElementById('phone').value;
const birthdateInput = document.getElementById('birthdate');
let birthdate = birthdateInput.value;
if (birthdate === '') {
birthdate = null;
}
const avatarInput = document.getElementById('avatar');
if (avatarInput.files && avatarInput.files.length > 0) {
formData.append('avatar', avatarInput.files[0]);
}
formData.append('nickname', nickname);
formData.append('email', email);
formData.append('phone', phone);
if (birthdate!== null) {
formData.append('birthdate', birthdate);
}
fetch('/api/update_user_info.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('信息更新成功!');
loadUserInfo();
showDisplaySection();
} else {
alert('信息更新失败:' + data.message);
}
})
.catch(error => {
console.error('保存用户信息失败:', error);
alert('保存用户信息失败,请检查网络或联系管理员');
});
}
function showEditSection() {
document.querySelector('.info-display').style.display = 'none';
document.querySelector('.info-edit').style.display = 'block';
}
function showDisplaySection() {
document.querySelector('.info-display').style.display = 'block';
document.querySelector('.info-edit').style.display = 'none';
}
// 显示已选择的文件名
function showSelectedFileName(event) {
const fileName = event.target.files[0]? event.target.files[0].name : '';
document.getElementById('selected-file-name').textContent = fileName;
}
// 添加 goBack 函数
function goBack() {
window.history.back();
}
document.addEventListener('DOMContentLoaded', function () {
loadUserInfo();
});
</script>
</body>
</html>