-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
136 lines (127 loc) · 4.68 KB
/
index.php
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/materialize.min.css">
<link rel="stylesheet" href="css/icon.css">
<title>留言板</title>
</head>
<body>
<!-- 导航栏 -->
<nav>
<div class="nav-wrapper">
<a class="brand-logo center"></a>
<ul id="nav-mobile" class="right">
<li><a href="#" onclick="LogOut()"><i class="material-icons">exit_to_app</i></a></li>
</ul>
</div>
</nav>
<!-- 内容栏 -->
<div class="container">
<!-- 输入留言 -->
<div class="row">
<div class="col s12">
<form>
<div class="input-field">
<textarea name="comment" id="comment" class="materialize-textarea" required></textarea>
<label for="comment">我也要留言</label>
<button onclick="retuen Comment();" class="btn">提交</button>
</div>
</form>
</div>
</div>
<!-- 显示留言 -->
<div class="row">
<div class="col s12">
<ul class="collection">
</ul>
</div>
</div>
</div>
<script src="js/materialize.min.js"></script>
<script src="js/jquery-3.4.1.min.js"></script>
<script>
//载入留言
function Load() {
$.post({url:"query.php",
dataType:"json",
data: {'action': 'query'},
success:(data)=>{
$('.collection').empty();
data.forEach(element => {
let $li = $('<li class="collection-item avatar"></li>');
let hearimg = element['headimg'];
if (hearimg == null)
hearimg = 'img/th.jpg'; //空头像则设置个默认头像
$li.append('<img src="' + hearimg + '" alt="" class="circle">');
$li.append('<span class="title"><b>' + element['nickname'] + '<b></span>');
let $p = $('<p></p>');
$p.append(element['comment'] + '<br/>');
$p.append(element['addtime']);
$li.append($p);
if (element['uid'] == uid) {
$li.append('<a href="#"' +
'onClick="Del(' + element['id'] + ');return false;" ' +
'class="secondary-content"><i class="material-icons">clear</i></a>');
}
$('.collection').append($li);
});
}});
}
//删除留言
function Del(id) {
if (!confirm("确定要删除这条留言吗?"))
return
$.post({url: "query.php",
dataType:"json",
data: {'action': 'del', 'id': id},
success:(data)=>{
alert("删除留言成功")
Load();
}})
}
//用户退出
function LogOut() {
$.post({url: "user.php",
dataType: "json",
data: {'action': 'out'},
success:()=>{
location.href = 'login.php';
}
});
}
//留言
function Comment() {
if ($('#comment').val() === '')
return true;
$.post({url: "query.php",
dataType: "json",
data: $('form').serialize(),
success:()=>{
alert('留言成功');
$('#comment').val('');
Load();
}
});
return false;
}
let uid, nickname;
//载入用户信息
$.post({url: "user.php",
dataType: "json",
data: {'action': 'user'},
success:(data)=>{
uid = data['uid'];
nickname = data['nickname'];
$('.brand-logo.center').append(nickname);
},
error: ()=>{
location.href = 'login.php';
}
});
Load();
</script>
</body>
</html>