459 lines
15 KiB
HTML
459 lines
15 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html lang="zh-CN">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
<title>客户模拟端</title>
|
||
|
|
<style>
|
||
|
|
* {
|
||
|
|
margin: 0;
|
||
|
|
padding: 0;
|
||
|
|
box-sizing: border-box;
|
||
|
|
}
|
||
|
|
body {
|
||
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||
|
|
background: #f5f5f5;
|
||
|
|
height: 100vh;
|
||
|
|
display: flex;
|
||
|
|
justify-content: center;
|
||
|
|
align-items: center;
|
||
|
|
}
|
||
|
|
.phone-frame {
|
||
|
|
width: 375px;
|
||
|
|
height: 700px;
|
||
|
|
background: #fff;
|
||
|
|
border-radius: 30px;
|
||
|
|
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
||
|
|
overflow: hidden;
|
||
|
|
display: flex;
|
||
|
|
flex-direction: column;
|
||
|
|
border: 8px solid #333;
|
||
|
|
}
|
||
|
|
.phone-header {
|
||
|
|
background: #ededed;
|
||
|
|
padding: 15px;
|
||
|
|
text-align: center;
|
||
|
|
border-bottom: 1px solid #d9d9d9;
|
||
|
|
position: relative;
|
||
|
|
}
|
||
|
|
.phone-header .status-bar {
|
||
|
|
position: absolute;
|
||
|
|
top: 5px;
|
||
|
|
left: 15px;
|
||
|
|
right: 15px;
|
||
|
|
display: flex;
|
||
|
|
justify-content: space-between;
|
||
|
|
font-size: 11px;
|
||
|
|
color: #333;
|
||
|
|
}
|
||
|
|
.phone-header .title {
|
||
|
|
margin-top: 15px;
|
||
|
|
font-size: 16px;
|
||
|
|
font-weight: 500;
|
||
|
|
}
|
||
|
|
.phone-header .subtitle {
|
||
|
|
font-size: 11px;
|
||
|
|
color: #999;
|
||
|
|
margin-top: 2px;
|
||
|
|
}
|
||
|
|
.chat-area {
|
||
|
|
flex: 1;
|
||
|
|
overflow-y: auto;
|
||
|
|
padding: 15px;
|
||
|
|
background: #f5f5f5;
|
||
|
|
}
|
||
|
|
.message {
|
||
|
|
margin-bottom: 15px;
|
||
|
|
display: flex;
|
||
|
|
flex-direction: column;
|
||
|
|
}
|
||
|
|
.message.sent {
|
||
|
|
align-items: flex-end;
|
||
|
|
}
|
||
|
|
.message.received {
|
||
|
|
align-items: flex-start;
|
||
|
|
}
|
||
|
|
.message-bubble {
|
||
|
|
max-width: 75%;
|
||
|
|
padding: 10px 14px;
|
||
|
|
border-radius: 8px;
|
||
|
|
font-size: 14px;
|
||
|
|
line-height: 1.4;
|
||
|
|
position: relative;
|
||
|
|
}
|
||
|
|
.message.sent .message-bubble {
|
||
|
|
background: #95ec69;
|
||
|
|
border-radius: 8px 0 8px 8px;
|
||
|
|
}
|
||
|
|
.message.received .message-bubble {
|
||
|
|
background: #fff;
|
||
|
|
border-radius: 0 8px 8px 8px;
|
||
|
|
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
||
|
|
}
|
||
|
|
.message-time {
|
||
|
|
font-size: 10px;
|
||
|
|
color: #999;
|
||
|
|
margin-top: 4px;
|
||
|
|
}
|
||
|
|
.sender-name {
|
||
|
|
font-size: 11px;
|
||
|
|
color: #999;
|
||
|
|
margin-bottom: 3px;
|
||
|
|
}
|
||
|
|
.typing-indicator {
|
||
|
|
display: none;
|
||
|
|
align-items: center;
|
||
|
|
padding: 10px 14px;
|
||
|
|
background: #fff;
|
||
|
|
border-radius: 0 8px 8px 8px;
|
||
|
|
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
||
|
|
width: fit-content;
|
||
|
|
}
|
||
|
|
.typing-indicator.show {
|
||
|
|
display: flex;
|
||
|
|
}
|
||
|
|
.typing-indicator span {
|
||
|
|
width: 6px;
|
||
|
|
height: 6px;
|
||
|
|
background: #999;
|
||
|
|
border-radius: 50%;
|
||
|
|
margin: 0 2px;
|
||
|
|
animation: typing 1.4s infinite;
|
||
|
|
}
|
||
|
|
.typing-indicator span:nth-child(2) {
|
||
|
|
animation-delay: 0.2s;
|
||
|
|
}
|
||
|
|
.typing-indicator span:nth-child(3) {
|
||
|
|
animation-delay: 0.4s;
|
||
|
|
}
|
||
|
|
@keyframes typing {
|
||
|
|
0%, 60%, 100% { transform: translateY(0); }
|
||
|
|
30% { transform: translateY(-4px); }
|
||
|
|
}
|
||
|
|
.input-area {
|
||
|
|
background: #f7f7f7;
|
||
|
|
padding: 10px;
|
||
|
|
border-top: 1px solid #e0e0e0;
|
||
|
|
}
|
||
|
|
.input-row {
|
||
|
|
display: flex;
|
||
|
|
align-items: flex-end;
|
||
|
|
gap: 8px;
|
||
|
|
}
|
||
|
|
.input-row textarea {
|
||
|
|
flex: 1;
|
||
|
|
padding: 10px;
|
||
|
|
border: none;
|
||
|
|
border-radius: 20px;
|
||
|
|
background: #fff;
|
||
|
|
resize: none;
|
||
|
|
height: 40px;
|
||
|
|
max-height: 100px;
|
||
|
|
font-size: 14px;
|
||
|
|
outline: none;
|
||
|
|
}
|
||
|
|
.input-row button {
|
||
|
|
width: 40px;
|
||
|
|
height: 40px;
|
||
|
|
border-radius: 50%;
|
||
|
|
border: none;
|
||
|
|
background: #07c160;
|
||
|
|
color: white;
|
||
|
|
font-size: 18px;
|
||
|
|
cursor: pointer;
|
||
|
|
display: flex;
|
||
|
|
align-items: center;
|
||
|
|
justify-content: center;
|
||
|
|
}
|
||
|
|
.input-row button:hover {
|
||
|
|
background: #06ad56;
|
||
|
|
}
|
||
|
|
.input-row button:disabled {
|
||
|
|
background: #ccc;
|
||
|
|
}
|
||
|
|
.quick-actions {
|
||
|
|
display: flex;
|
||
|
|
gap: 8px;
|
||
|
|
margin-top: 8px;
|
||
|
|
}
|
||
|
|
.quick-action {
|
||
|
|
padding: 6px 12px;
|
||
|
|
background: #fff;
|
||
|
|
border: 1px solid #e0e0e0;
|
||
|
|
border-radius: 15px;
|
||
|
|
font-size: 12px;
|
||
|
|
cursor: pointer;
|
||
|
|
}
|
||
|
|
.quick-action:hover {
|
||
|
|
background: #f5f5f5;
|
||
|
|
}
|
||
|
|
.settings-panel {
|
||
|
|
position: absolute;
|
||
|
|
top: 10px;
|
||
|
|
right: 10px;
|
||
|
|
background: #fff;
|
||
|
|
border-radius: 8px;
|
||
|
|
padding: 15px;
|
||
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||
|
|
z-index: 100;
|
||
|
|
display: none;
|
||
|
|
}
|
||
|
|
.settings-panel.show {
|
||
|
|
display: block;
|
||
|
|
}
|
||
|
|
.settings-panel h4 {
|
||
|
|
margin-bottom: 10px;
|
||
|
|
font-size: 14px;
|
||
|
|
}
|
||
|
|
.settings-panel input {
|
||
|
|
width: 100%;
|
||
|
|
padding: 8px;
|
||
|
|
margin-bottom: 8px;
|
||
|
|
border: 1px solid #d9d9d9;
|
||
|
|
border-radius: 4px;
|
||
|
|
font-size: 12px;
|
||
|
|
}
|
||
|
|
.settings-panel button {
|
||
|
|
width: 100%;
|
||
|
|
padding: 8px;
|
||
|
|
background: #07c160;
|
||
|
|
color: white;
|
||
|
|
border: none;
|
||
|
|
border-radius: 4px;
|
||
|
|
cursor: pointer;
|
||
|
|
}
|
||
|
|
.settings-btn {
|
||
|
|
position: absolute;
|
||
|
|
top: 10px;
|
||
|
|
right: 10px;
|
||
|
|
background: #fff;
|
||
|
|
border: 1px solid #d9d9d9;
|
||
|
|
border-radius: 50%;
|
||
|
|
width: 30px;
|
||
|
|
height: 30px;
|
||
|
|
cursor: pointer;
|
||
|
|
font-size: 14px;
|
||
|
|
}
|
||
|
|
.transfer-notice {
|
||
|
|
background: #fff3cd;
|
||
|
|
border: 1px solid #ffc107;
|
||
|
|
border-radius: 8px;
|
||
|
|
padding: 10px;
|
||
|
|
margin: 10px 0;
|
||
|
|
font-size: 12px;
|
||
|
|
color: #856404;
|
||
|
|
text-align: center;
|
||
|
|
}
|
||
|
|
.system-message {
|
||
|
|
text-align: center;
|
||
|
|
font-size: 11px;
|
||
|
|
color: #999;
|
||
|
|
margin: 10px 0;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="phone-frame">
|
||
|
|
<div class="phone-header">
|
||
|
|
<div class="status-bar">
|
||
|
|
<span id="currentTime">12:00</span>
|
||
|
|
<span>📶 🔋</span>
|
||
|
|
</div>
|
||
|
|
<div class="title">智能客服</div>
|
||
|
|
<div class="subtitle" id="statusText">AI在线</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="chat-area" id="chatArea">
|
||
|
|
<div class="system-message">会话已开始</div>
|
||
|
|
<div class="message received">
|
||
|
|
<div class="sender-name">客服</div>
|
||
|
|
<div class="message-bubble">您好!我是智能客服,有什么可以帮您的吗?</div>
|
||
|
|
<div class="message-time">刚刚</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="input-area">
|
||
|
|
<div class="input-row">
|
||
|
|
<textarea id="messageInput" placeholder="输入消息..." rows="1"></textarea>
|
||
|
|
<button onclick="sendMessage()" id="sendBtn">➤</button>
|
||
|
|
</div>
|
||
|
|
<div class="quick-actions">
|
||
|
|
<button class="quick-action" onclick="quickSend('你好')">你好</button>
|
||
|
|
<button class="quick-action" onclick="quickSend('转人工')">转人工</button>
|
||
|
|
<button class="quick-action" onclick="quickSend('投诉')">投诉</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<button class="settings-btn" onclick="toggleSettings()">⚙️</button>
|
||
|
|
|
||
|
|
<div class="settings-panel" id="settingsPanel">
|
||
|
|
<h4>测试设置</h4>
|
||
|
|
<input type="text" id="customerId" placeholder="客户ID" value="customer_001">
|
||
|
|
<input type="text" id="kfId" placeholder="客服账号ID" value="kf_001">
|
||
|
|
<button onclick="saveSettings()">保存设置</button>
|
||
|
|
<button onclick="clearChat()" style="margin-top: 8px; background: #ff4d4f;">清空聊天</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
const baseUrl = window.location.origin;
|
||
|
|
let customerId = 'customer_001';
|
||
|
|
let kfId = 'kf_001';
|
||
|
|
let sessionStatus = 'AI';
|
||
|
|
|
||
|
|
function updateTime() {
|
||
|
|
const now = new Date();
|
||
|
|
document.getElementById('currentTime').textContent =
|
||
|
|
now.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' });
|
||
|
|
}
|
||
|
|
setInterval(updateTime, 1000);
|
||
|
|
updateTime();
|
||
|
|
|
||
|
|
function toggleSettings() {
|
||
|
|
document.getElementById('settingsPanel').classList.toggle('show');
|
||
|
|
}
|
||
|
|
|
||
|
|
function saveSettings() {
|
||
|
|
customerId = document.getElementById('customerId').value || 'customer_001';
|
||
|
|
kfId = document.getElementById('kfId').value || 'kf_001';
|
||
|
|
toggleSettings();
|
||
|
|
addSystemMessage('设置已更新');
|
||
|
|
}
|
||
|
|
|
||
|
|
function clearChat() {
|
||
|
|
document.getElementById('chatArea').innerHTML = '<div class="system-message">会话已重置</div>';
|
||
|
|
sessionStatus = 'AI';
|
||
|
|
document.getElementById('statusText').textContent = 'AI在线';
|
||
|
|
toggleSettings();
|
||
|
|
}
|
||
|
|
|
||
|
|
function addSystemMessage(text) {
|
||
|
|
const chatArea = document.getElementById('chatArea');
|
||
|
|
const msg = document.createElement('div');
|
||
|
|
msg.className = 'system-message';
|
||
|
|
msg.textContent = text;
|
||
|
|
chatArea.appendChild(msg);
|
||
|
|
chatArea.scrollTop = chatArea.scrollHeight;
|
||
|
|
}
|
||
|
|
|
||
|
|
function addMessage(content, isSent, senderName = '') {
|
||
|
|
const chatArea = document.getElementById('chatArea');
|
||
|
|
const msg = document.createElement('div');
|
||
|
|
msg.className = 'message ' + (isSent ? 'sent' : 'received');
|
||
|
|
|
||
|
|
const time = new Date().toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' });
|
||
|
|
|
||
|
|
msg.innerHTML = `
|
||
|
|
${senderName ? '<div class="sender-name">' + senderName + '</div>' : ''}
|
||
|
|
<div class="message-bubble">${content}</div>
|
||
|
|
<div class="message-time">${time}</div>
|
||
|
|
`;
|
||
|
|
|
||
|
|
chatArea.appendChild(msg);
|
||
|
|
chatArea.scrollTop = chatArea.scrollHeight;
|
||
|
|
}
|
||
|
|
|
||
|
|
function showTyping() {
|
||
|
|
const chatArea = document.getElementById('chatArea');
|
||
|
|
const typing = document.createElement('div');
|
||
|
|
typing.className = 'message received';
|
||
|
|
typing.id = 'typingIndicator';
|
||
|
|
typing.innerHTML = `
|
||
|
|
<div class="typing-indicator show">
|
||
|
|
<span></span><span></span><span></span>
|
||
|
|
</div>
|
||
|
|
`;
|
||
|
|
chatArea.appendChild(typing);
|
||
|
|
chatArea.scrollTop = chatArea.scrollHeight;
|
||
|
|
}
|
||
|
|
|
||
|
|
function hideTyping() {
|
||
|
|
const typing = document.getElementById('typingIndicator');
|
||
|
|
if (typing) typing.remove();
|
||
|
|
}
|
||
|
|
|
||
|
|
async function sendMessage() {
|
||
|
|
const input = document.getElementById('messageInput');
|
||
|
|
const content = input.value.trim();
|
||
|
|
if (!content) return;
|
||
|
|
|
||
|
|
addMessage(content, true);
|
||
|
|
input.value = '';
|
||
|
|
|
||
|
|
showTyping();
|
||
|
|
|
||
|
|
try {
|
||
|
|
const response = await fetch(baseUrl + '/test/send-message?' +
|
||
|
|
'customerId=' + encodeURIComponent(customerId) +
|
||
|
|
'&kfId=' + encodeURIComponent(kfId) +
|
||
|
|
'&content=' + encodeURIComponent(content), {
|
||
|
|
method: 'POST'
|
||
|
|
});
|
||
|
|
|
||
|
|
const result = await response.json();
|
||
|
|
|
||
|
|
setTimeout(() => {
|
||
|
|
hideTyping();
|
||
|
|
|
||
|
|
if (result.code === 200) {
|
||
|
|
if (content.includes('人工') || content.includes('转人工') || content.includes('投诉')) {
|
||
|
|
sessionStatus = 'PENDING';
|
||
|
|
document.getElementById('statusText').textContent = '等待人工接入...';
|
||
|
|
addTransferNotice();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}, 1000 + Math.random() * 1000);
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
hideTyping();
|
||
|
|
console.error('发送失败:', error);
|
||
|
|
addMessage('消息发送失败,请重试', false, '系统');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function addTransferNotice() {
|
||
|
|
const chatArea = document.getElementById('chatArea');
|
||
|
|
const notice = document.createElement('div');
|
||
|
|
notice.className = 'transfer-notice';
|
||
|
|
notice.textContent = '正在为您转接人工客服,请稍候...';
|
||
|
|
chatArea.appendChild(notice);
|
||
|
|
chatArea.scrollTop = chatArea.scrollHeight;
|
||
|
|
}
|
||
|
|
|
||
|
|
function quickSend(text) {
|
||
|
|
document.getElementById('messageInput').value = text;
|
||
|
|
sendMessage();
|
||
|
|
}
|
||
|
|
|
||
|
|
document.getElementById('messageInput').addEventListener('keypress', function(e) {
|
||
|
|
if (e.key === 'Enter' && !e.shiftKey) {
|
||
|
|
e.preventDefault();
|
||
|
|
sendMessage();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
document.getElementById('messageInput').addEventListener('input', function() {
|
||
|
|
this.style.height = 'auto';
|
||
|
|
this.style.height = Math.min(this.scrollHeight, 100) + 'px';
|
||
|
|
});
|
||
|
|
|
||
|
|
setInterval(async () => {
|
||
|
|
try {
|
||
|
|
const response = await fetch(baseUrl + '/api/sessions?status=MANUAL');
|
||
|
|
const result = await response.json();
|
||
|
|
if (result.code === 200) {
|
||
|
|
const mySession = result.data.find(s =>
|
||
|
|
s.customerId === customerId && s.status === 'MANUAL'
|
||
|
|
);
|
||
|
|
if (mySession && sessionStatus !== 'MANUAL') {
|
||
|
|
sessionStatus = 'MANUAL';
|
||
|
|
document.getElementById('statusText').textContent = '人工客服接待中';
|
||
|
|
addSystemMessage('人工客服已接入');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} catch (e) {}
|
||
|
|
}, 3000);
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|