|
|
@@ -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>
|