Просмотр исходного кода

feat(admin): 添加客服聊天测试页面- 创建客服聊天测试页面 admin.html- 实现 WebSocket 连接和消息收发功能
- 添加发送消息和心跳包功能
- 支持输入用户ID和客服ID进行通信- 添加基础样式和消息展示区域
- 实现登录消息发送和心跳检测
- 添加未读消息提示样式

nahida 7 месяцев назад
Родитель
Сommit
f24f883af6
1 измененных файлов с 65 добавлено и 0 удалено
  1. 65 0
      zksy-admin/src/main/resources/static/admin.html

+ 65 - 0
zksy-admin/src/main/resources/static/admin.html

@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html lang="zh">
+<head>
+    <meta charset="UTF-8"/>
+    <title>客服聊天测试</title>
+    <style>
+        body { font-family: sans-serif; }
+        #messages { border: 1px solid #ccc; height: 300px; overflow-y: auto; padding: 8px; }
+        #unread { color: white; background: red; border-radius: 50%; padding: 3px 8px; }
+    </style>
+</head>
+<body>
+<h2>客服聊天测试</h2>
+<div id="messages"></div>
+<input type="text" id="msgInput" placeholder="输入消息"/>
+<input type="text" id="userId" placeholder="输入用户ID"/>
+<button onclick="sendMessage()">发送</button>
+<button onclick="sendHeartbeat()">发送心跳</button>
+<input type="text" id="adminId" placeholder="输入你客服ID"/>
+
+
+
+<script>
+    const adminIdInput = document.getElementById("adminId");
+    adminIdInput.value = prompt("请输入你的客服ID");
+    const ws = new WebSocket("ws://localhost:8081/ws");
+
+    const messagesDiv = document.getElementById("messages");
+
+    ws.onopen = () => {
+        console.log("已连接");
+        ws.send(JSON.stringify({from: adminIdInput.value,role:"admin", type: "login"}));
+    };
+
+    ws.onmessage = (e) => {
+        const msg = JSON.parse(e.data);
+        const p = document.createElement("p");
+        p.textContent = msg.from + ": " + msg.content;
+        messagesDiv.appendChild(p);
+
+    };
+
+    function sendMessage() {
+        const input = document.getElementById("msgInput");
+        const content = input.value;
+        if (content.trim()) {
+            const userIdInput = document.getElementById("userId");
+            const toUserId = userIdInput.value.trim();
+            if (toUserId) {
+                ws.send(JSON.stringify({from: adminIdInput.value, to: toUserId, type: "chat", content: content,role:"admin"}));
+                input.value = "";
+            } else {
+                alert("请输入目标用户ID");
+            }
+        }
+    }
+
+
+
+    function sendHeartbeat() {
+        ws.send(JSON.stringify({from: adminIdInput.value, role: "admin", type: "heartbeat"}));
+    }
+</script>
+</body>
+</html>