mirror of
https://github.com/LC044/WeChatMsg
synced 2025-02-23 03:22:17 +08:00
html页面输入页码可以回车跳转,跳转后自动滚动到页面顶部。统一了缩进
This commit is contained in:
parent
115ace3ae5
commit
abab101821
@ -518,20 +518,19 @@ html_head = '''
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Chat Records</title>
|
||||
<style>
|
||||
|
||||
*{
|
||||
*{
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
body{
|
||||
}
|
||||
body{
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.modal {
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 9999;
|
||||
@ -540,16 +539,16 @@ html_head = '''
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
}
|
||||
|
||||
.modal-image {
|
||||
.modal-image {
|
||||
display: block;
|
||||
max-width: 90%;
|
||||
max-height: 90%;
|
||||
margin: auto;
|
||||
margin-top: 5%;
|
||||
}
|
||||
.container{
|
||||
}
|
||||
.container{
|
||||
height: 760px;
|
||||
width: 900px;
|
||||
border-radius: 4px;
|
||||
@ -558,17 +557,17 @@ html_head = '''
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
.content{
|
||||
}
|
||||
.content{
|
||||
width: calc(100% - 40px);
|
||||
padding: 20px;
|
||||
overflow-y: scroll;
|
||||
flex: 1;
|
||||
}
|
||||
.content:hover::-webkit-scrollbar-thumb{
|
||||
}
|
||||
.content:hover::-webkit-scrollbar-thumb{
|
||||
background:rgba(0,0,0,0.1);
|
||||
}
|
||||
.bubble{
|
||||
}
|
||||
.bubble{
|
||||
max-width: 400px;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
@ -576,12 +575,12 @@ html_head = '''
|
||||
color: #000;
|
||||
word-wrap:break-word;
|
||||
word-break:normal;
|
||||
}
|
||||
.item-left .bubble{
|
||||
}
|
||||
.item-left .bubble{
|
||||
margin-left: 15px;
|
||||
background-color: #fff;
|
||||
}
|
||||
.item-left .bubble:before{
|
||||
}
|
||||
.item-left .bubble:before{
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 0;
|
||||
@ -591,12 +590,12 @@ html_head = '''
|
||||
border-right: 10px solid #fff;
|
||||
border-bottom: 10px solid transparent;
|
||||
left: -20px;
|
||||
}
|
||||
.item-right .bubble{
|
||||
}
|
||||
.item-right .bubble{
|
||||
margin-right: 15px;
|
||||
background-color: #9eea6a;
|
||||
}
|
||||
.item-right .bubble:before{
|
||||
}
|
||||
.item-right .bubble:before{
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 0;
|
||||
@ -606,19 +605,19 @@ html_head = '''
|
||||
border-right: 10px solid transparent;
|
||||
border-bottom: 10px solid transparent;
|
||||
right: -20px;
|
||||
}
|
||||
.item{
|
||||
}
|
||||
.item{
|
||||
margin-top: 15px;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
}
|
||||
.item.item-right{
|
||||
}
|
||||
.item.item-right{
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.item.item-center{
|
||||
}
|
||||
.item.item-center{
|
||||
justify-content: center;
|
||||
}
|
||||
.item.item-center span{
|
||||
}
|
||||
.item.item-center span{
|
||||
font-size: 12px;
|
||||
padding: 2px 4px;
|
||||
color: #fff;
|
||||
@ -629,32 +628,32 @@ html_head = '''
|
||||
-ms-user-select:none; /*IE10*/
|
||||
-khtml-user-select:none; /*早期浏览器*/
|
||||
user-select:none;
|
||||
}
|
||||
}
|
||||
|
||||
.chat-image img{
|
||||
.chat-image img{
|
||||
margin-right: 18px;
|
||||
margin-left: 18px;
|
||||
max-width: 300px;
|
||||
max-height: auto;
|
||||
}
|
||||
.avatar img{
|
||||
}
|
||||
.avatar img{
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.chat-video video{
|
||||
}
|
||||
.chat-video video{
|
||||
margin-right: 18px;
|
||||
margin-left: 18px;
|
||||
max-width: 350px;
|
||||
}
|
||||
.input-area{
|
||||
}
|
||||
.input-area{
|
||||
border-top:0.5px solid #e0e0e0;
|
||||
height: 150px;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
background-color: #fff;
|
||||
}
|
||||
textarea{
|
||||
}
|
||||
textarea{
|
||||
flex: 1;
|
||||
padding: 5px;
|
||||
font-size: 14px;
|
||||
@ -664,41 +663,41 @@ html_head = '''
|
||||
overflow-x: hidden;
|
||||
outline:none;
|
||||
resize:none;
|
||||
}
|
||||
.button-area{
|
||||
}
|
||||
.button-area{
|
||||
display: flex;
|
||||
height: 40px;
|
||||
margin-right: 10px;
|
||||
line-height: 40px;
|
||||
padding: 5px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.button-area button{
|
||||
}
|
||||
.button-area button{
|
||||
width: 80px;
|
||||
border: none;
|
||||
outline: none;
|
||||
border-radius: 4px;
|
||||
float: right;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
/* 设置滚动条的样式 */
|
||||
::-webkit-scrollbar {
|
||||
/* 设置滚动条的样式 */
|
||||
::-webkit-scrollbar {
|
||||
width:10px;
|
||||
}
|
||||
/* 滚动槽 */
|
||||
::-webkit-scrollbar-track {
|
||||
}
|
||||
/* 滚动槽 */
|
||||
::-webkit-scrollbar-track {
|
||||
-webkit-box-shadow:inset006pxrgba(0,0,0,0.3);
|
||||
border-radius:8px;
|
||||
}
|
||||
/* 滚动条滑块 */
|
||||
::-webkit-scrollbar-thumb {
|
||||
}
|
||||
/* 滚动条滑块 */
|
||||
::-webkit-scrollbar-thumb {
|
||||
border-radius:10px;
|
||||
background:rgba(0,0,0,0);
|
||||
-webkit-box-shadow:inset006pxrgba(0,0,0,0.5);
|
||||
}
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
.pagination-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
@ -758,7 +757,7 @@ input {
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="container">
|
||||
<div class="content" id="chat-container">
|
||||
<div class="item item-center"><span>昨天 12:35</span></div>
|
||||
<div class="item item-center"><span>你已添加了凡繁烦,现在可以开始聊天了。</span></div>
|
||||
@ -779,9 +778,7 @@ input {
|
||||
<div class="item item-center">
|
||||
<span>昨天 13:15</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div></div>
|
||||
<div id="modal" class="modal" onclick="hideModal()">
|
||||
@ -793,51 +790,51 @@ input {
|
||||
<button onclick="nextPage()">下一页</button>
|
||||
</div>
|
||||
<div class="jump-row">
|
||||
<input type="number" id="gotoPageInput" placeholder="跳转到第几页">
|
||||
<input type="number" id="gotoPageInput" onkeydown="checkEnter(event)" placeholder="跳转到第几页">
|
||||
<button onclick="gotoPage()">跳转</button>
|
||||
</div>
|
||||
<div id="paginationInfo"></div>
|
||||
</div>
|
||||
<script>
|
||||
const chatContainer = document.getElementById('chat-container');
|
||||
// Sample chat messages (replace this with your actual data)
|
||||
const chatMessages = [
|
||||
const chatContainer = document.getElementById('chat-container');
|
||||
// Sample chat messages (replace this with your actual data)
|
||||
const chatMessages = [
|
||||
'''
|
||||
html_end = '''
|
||||
];
|
||||
];
|
||||
function renderMessages(messages) {
|
||||
for (const message of messages) {
|
||||
const messageElement = document.createElement('div');
|
||||
if (message.type == 1){
|
||||
if (message.is_send == 1){
|
||||
if (message.type == 1) {
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='bubble bubble-right'>${message.text}</div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if(message.is_send==0){
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='bubble bubble-right'>${message.text}</div>`
|
||||
}
|
||||
}
|
||||
else if(message.type == 0){
|
||||
else if (message.type == 0) {
|
||||
messageElement.className = "item item-center";
|
||||
messageElement.innerHTML = `<span>${message.text}</span>`
|
||||
}
|
||||
else if (message.type == 3){
|
||||
if (message.is_send == 1){
|
||||
else if (message.type == 3) {
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='chat-image'><img src="${message.text}" /></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if(message.is_send==0){
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='chat-image'><img src="${message.text}" /></div>`
|
||||
}
|
||||
}
|
||||
else if (message.type == 43) {
|
||||
if (message.is_send == 1){
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='chat-video'><video src="${message.text}" controls /></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if(message.is_send==0){
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='chat-video'><video src="${message.text}" controls /></div>`
|
||||
}
|
||||
@ -846,6 +843,11 @@ html_end = '''
|
||||
}
|
||||
}
|
||||
|
||||
function checkEnter(event) {
|
||||
if (event.keyCode === 13) {
|
||||
gotoPage();
|
||||
}
|
||||
}
|
||||
|
||||
const itemsPerPage = 100; // 每页显示的元素个数
|
||||
let currentPage = 1; // 当前页
|
||||
@ -862,42 +864,43 @@ html_end = '''
|
||||
for (let i = startIndex; i < endIndex && i < chatMessages.length; i++) {
|
||||
const message = chatMessages[i];
|
||||
const messageElement = document.createElement('div');
|
||||
if (message.type == 1){
|
||||
if (message.is_send == 1){
|
||||
if (message.type == 1) {
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='bubble bubble-right'>${message.text}</div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if(message.is_send==0){
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='bubble bubble-right'>${message.text}</div>`
|
||||
}
|
||||
}
|
||||
else if(message.type == 0){
|
||||
else if (message.type == 0) {
|
||||
messageElement.className = "item item-center";
|
||||
messageElement.innerHTML = `<span>${message.text}</span>`
|
||||
}
|
||||
else if (message.type == 3){
|
||||
if (message.is_send == 1){
|
||||
else if (message.type == 3) {
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='chat-image' ><img src="${message.text}" onclick="showModal(this)"/></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if(message.is_send==0){
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}"/></div><div class='chat-image'><img src="${message.text}" onclick="showModal(this)"/></div>`
|
||||
}
|
||||
}
|
||||
else if (message.type == 43) {
|
||||
if (message.is_send == 1){
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='chat-video'><video src="${message.text}" controls /></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if(message.is_send==0){
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='chat-video'><video src="${message.text}" controls "/></div>`
|
||||
}
|
||||
}
|
||||
chatContainer.appendChild(messageElement);
|
||||
}
|
||||
document.querySelector("#chat-container").scrollTop = 0;
|
||||
updatePaginationInfo();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user