-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.php
More file actions
80 lines (78 loc) · 3.13 KB
/
chat.php
File metadata and controls
80 lines (78 loc) · 3.13 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
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" id="viewport" content="width=device-width, initial-scale=1">
<title>简单门铃</title>
<style type="text/css">
body,h3{margin: 0;padding: 0;text-align: center}
.textBoxOuter{width: 100%}
.main{}
.footer{display:-webkit-flex;width:100%;height: 60px;background-color:#fff;position: fixed;bottom: 0;text-align: left}
.header{width:100%;height: 50px;background-color:#336699;line-height: 50px}
.header h3{color: #fff}
.content{height:100%;width:100%;background-color: #ddd;overflow-y:scroll;}
.sendBox{flex:1;height: 40px;margin: 10px 10px;padding:0 10px;font-size: 15px;border: 1px solid #0cf}
.sendBtn{height:40px;margin-top:10px;margin-right:10px;width:80px;border-radius: 8px;background-color: #0f0;color:#fff;border: 1px solid #0cf}
.sendBtn:active{opacity: 0.5}
.textBox{font-size: 16px;border-radius: 20px;margin: 10px 0 5px 0;padding:10px 15px;max-width: 300px;word-wrap:break-word;word-break:break-all;text-align:left;display: inline-block;}
.alert{float:center;background-color:#0cf;color: #444;padding:5px 20px;font-size: 13px;border-radius: 15px}
.send{float:right;margin-left:50px;background-color:#0f0;color:#000}
.receive{float:left;margin-right:50px;background-color:#fff;color: #000}
.clear{clear: both;}
</style>
</head>
<body>
<div class="main">
<div class="header"><h3>和房主对话</h3></div>
<div class="content">
<div class="textBox alert">已通知房主开门</div>
</div>
<div class="footer">
<input type="text" class="sendBox" placeholder="请输入想对房主说的话">
<button class="sendBtn">发送</button>
</div>
</div>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="./js/node_modules/leancloud-realtime/dist/realtime.browser.js"></script>
<script type="text/javascript" src="./js/leancloudapi.js"></script>
<script type="text/javascript">
var height = $(window).height();
$(".content").height((parseInt(height)-110)+'px');
//消息框滚动到最底部
var content = $(".content")
var scrollTo = content[0].scrollHeight;
content.scrollTop(scrollTo);
var visitor
,conv_id
,home_user = "<?=$_GET['home_user']?>";
//判断visitor是否已生成
sessionStorage.visitor = "<?=$_SESSION['visitor']?>";
sessionStorage.conv_id = "<?=$_SESSION['conv_id']?>";
if (!sessionStorage.visitor || !sessionStorage.conv_id) {
alert("会话已过期,请重新扫码");
exit();
}
visitor = sessionStorage.visitor;
//根据ID获取一个对话
getConvById()
//testSend()
//setInterval(testSend,1000);
//接收消息
receiveMessage();
//发送消息
$(".sendBtn").click(function(){
var message = $(".sendBox").val();
var content = $(".content")
if ($.trim(message) != "") {
content.append("<div class='textBoxOuter'><div class='textBox send'>"+$.trim(message)+"</div><div class='clear'></div>");
sendMessage($.trim(message));
$(".sendBox").val("");
var scrollTo = content[0].scrollHeight;
content.scrollTop(scrollTo);
}
})
</script>
</body>
</html>