-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_chat_1.html
385 lines (317 loc) · 10.7 KB
/
index_chat_1.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模拟短信发送</title>
<style>
/* 整体样式 */
* {
margin: 0;
padding: 0;
list-style: none;
background-color: #f1f3f6;
font-family: "PingFang SC"
}
/* 聊天框背景 */
#container {
width: 650px;
height: 600px;
background: #f1f3f6;
margin: 80px auto 0;
position: relative;
/* box-shadow: 0px 0px 10px rgb(231, 231, 233); */
border-radius: 20px;
box-shadow: 0 4px 23px 0 rgba(0, 0, 0, .09);
/* border-radius: 5px; */
}
/* 聊天框顶部信息 */
.header {
background: #f1f3f6;
height: 34px;
color: rgb(73, 73, 73);
line-height: 34px;
font-size: 16px;
padding: 10px 20px;
border-radius: 20px;
}
.header span {
background: #f1f3f6;
}
.footer {
width: 610px;
height: 50px;
background: #f1f3f6;
position: absolute;
bottom: 0;
padding: 20px;
border-radius: 20px;
}
/* 底部输入框的长度 */
.footer input {
width: 560px;
height: 38px;
color: #989b9e;
outline: none;
font-size: 14px;
text-indent: 10px;
padding: 5px 0 5px 14px;
border: 0;
position: absolute;
/* border-radius: 6px; */
right: 20px;
background: #f1f3f6;
box-shadow:
inset 2px 2px 5px #BABECC, inset -5px -5px 10px #FFF;
border-radius: 30px;
}
.footer input:focus {
box-shadow:
inset 1px 1px 2px #BABECC, inset -1px -1px 2px #FFF;
}
/* 发送按钮 */
.footer span {
display: inline-block;
margin: 0px 0 5px 0;
width: 72px;
height: 48px;
color: #60bec2;
/* background: #f1f3f6; */
box-shadow:
inset 0 0 15px rgba(55, 84, 170, 0),
inset 0 0 20px rgba(255, 255, 255, 0),
10px 10px 18px rgba(55, 84, 170, 0.15),
-10px -10px 22px white,
inset 0px 0px 4px rgba(255, 255, 255, 0.2);
/* font-weight: 900; */
font-size: 14px;
line-height: 48px;
cursor: pointer;
text-align: center;
position: absolute;
right: 20px;
border-radius: 0px 30px 30px 0px;
}
/* 发送按钮悬浮时的颜色 */
.footer span:hover {
/* color: rgb(107, 107, 107);
background: rgb(255, 255, 255); */
transition: box-shadow 0.3s;
/* box-shadow: 0 10px 20px 0 rgba(168, 182, 191, .6) !important; */
/* box-shadow: inset 1px 1px 3px rgba(55, 84, 170, 0.15), inset -2px -2px 5px white, 0px 0px 2px rgba(255, 255, 255, 0.2) */
box-shadow: inset 7px 7px 15px rgba(55, 84, 170, 0.15), inset -7px -7px 20px white, 0px 0px 4px rgba(255, 255, 255, 0.2);
}
.footer span:active {
box-shadow: inset 7px 7px 15px rgba(55, 84, 170, 0.15), inset -7px -7px 20px white, 0px 0px 4px rgba(255, 255, 255, 0.2);
}
/* 聊天框底部icon的样式 */
#icon {
display: inline-block;
background: rgb(255, 255, 255);
width: 45px;
height: 45px;
border-radius: 30px;
position: absolute;
bottom: 20px;
left: 14px;
cursor: pointer;
overflow: hidden;
}
/* 所有图片的尺寸 */
img {
width: 45px;
height: 45px;
}
/* 聊天可展示的显示区域 */
.content {
font-size: 14px;
width: 650px;
height: 440px;
overflow: auto;
/* padding: 5px; */
background-color: #f1f3f6;
}
.content li {
margin-top: 20px;
padding: 0 10px 0 10px;
width: 630px;
display: block;
clear: both;
overflow: hidden;
background-color: #f1f3f6;
}
.content li img {
float: left;
}
/* 聊天气泡 */
.content li span {
background: #60bec2;
padding: 10px;
margin: 0 10px 0 10px;
border-radius: 10px;
/* margin: 6px 10px 6 10px; */
max-width: 490px;
word-break: normal;
display: block;
word-wrap: break-word;
overflow: hidden;
}
.content li span img.spanimg {
width: 100px;
height: 100px;
}
.content li span img.spanimg:hover {
width: 400px;
height: 400px;
/* cursor: crosshair; */
/*放大倍数*/
/* transform: scale(4); */
}
.content li img.imgleft {
float: left;
width: 400px;
}
.content li img.imgright {
float: right;
width: 400px;
}
/* 左侧聊天框 */
.content li span.spanleft {
float: left;
color: #212121;
background: #ffffff;
}
/* 右侧聊天头像 */
.content li span.spanright {
float: right;
background: #60bec2;
color: #fff;
}
</style>
</head>
<body>
<div id="container">
<div class="header">
<span style="float: left;">私人助理</span>
<!-- <span style="float: right;">T 20:30</span> -->
</div>
<ul class="content">
<li>
<span class="spanleft">
<img src="/Users/luomingyang/PycharmProjects/pythonProject_test/20201027-百度识别api/头像.jpg"
class="spanimg" />
</span>
</li>
</ul>
<div class="footer">
<div id="icon">
<img src="/Users/luomingyang/Luo_MingYang/Utools/utools_hello_word/static/images/chatroom.png" alt="">
</div>
<input id="text" type="text" placeholder="说点什么吧...">
<span id="btn">send</span>
</div>
</div>
</body>
<script>
var save_file_arr = []
window.onload = function () {
var arrIcon = ['/Users/luomingyang/Luo_MingYang/Utools/utools_hello_word/static/images/chatroom.png', '/Users/luomingyang/Luo_MingYang/Utools/utools_hello_word/static/images/chatroom3.png'];
var num = 0; //控制聊天数量
var iNow = -1; //用来累加改变左右浮动
var btn = document.getElementById('btn');
var text = document.getElementById('text');
var content = document.getElementsByTagName('ul')[0];
var img = content.getElementsByTagName('img');
var span = content.getElementsByTagName('span');
//用于存储json数据
var res_json = {
id: 0,
text: 'text',
image: '',
time: Date(),
test: 'kdjhwflkhdsfjhakdhfkasdahfkahsdfkhasdlkfhkadsfhksdjhfkahdfkahdsfkhkhdsfjhakdhfkasdahfkahsdfkhasdlkfhkadsfhksdjhfkahdfkahdsfkhdsfjhakdhfkasdahfkahsdfkhasdlkfhkadsfhksdjhfkahdfkahdsf'
}
//发送的文本消息显示
function send(send = text.value) {
content.innerHTML += '<li><span class="spanright">' + send + '</span></li>';
}
function get_res(msg, json) {
if (msg == 'help') {
data = JSON.stringify(json);
} else if (json[msg]) {
data = json[msg]
} else { data = '未设置对应回复,点击添加' }
return data
}
function res(data) {
//文本类型的消息回复
function res_text(text) {
content.innerHTML += '<li><span class="spanleft">' + text + '</span></li>';
content.scrollTop = content.scrollHeight
}
// 图像类型消息回复
function res_img(img_path = '/Users/luomingyang/PycharmProjects/pythonProject_test/20201027-百度识别api/头像.jpg') {
content.innerHTML += '<li><span class="spanleft" ><img src="' + img_path + '" class = "spanimg" /></span></li>';
content.scrollTop = content.scrollHeight
}
if (data == 'img') {
res_img('/Users/luomingyang/PycharmProjects/pythonProject_test/20201027-百度识别api/头像.jpg')
} else {
res_text(data)
}
}
// 处理输入的信息
function dispose_msg(msg) {
send(msg)//发送的信息
save_file_arr[num] = msg
num++
data = get_res(msg, res_json)//从数据中获得获取回应的信息
save_file_arr[num] = data
res(data)//回复信息
}
//主函数 :0.监听输入的内容 1.显示发送的信息 2.根据规则匹配回复的内容 3.回复内容
function main() {
//按键监听
window.onkeydown = function () {
if (13 == event.keyCode) {
dispose_msg(text.value)
}
}
//鼠标监听
btn.onclick = function () {
dispose_msg(text.value)
}
}
main()
}
// 构造下载文件的函数
function download(filename, content) {
var blob = new Blob([content], { type: 'text/plain' }); //Bolb 斑点
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.style = "display: none";
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function () {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 5);
}
// 重新加载时调用方法
window.onbeforeunload = onbeforeunload_handler;
//退出窗口时调用的方法
// window.onunload = onunload_handler;
function onbeforeunload_handler() {
var warning = "确认退出?";
//保存数据到本地
var content = save_file_arr
download('chat.txt', content)
return warning;
}
function onunload_handler() {
var warning = "谢谢光临";
alert(warning);
}
</script>
</html>