280 lines
9.1 KiB
HTML
280 lines
9.1 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>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
|
<style>
|
|
.header-logo {
|
|
position: absolute;
|
|
top: 20px;
|
|
left: 20px;
|
|
width: 40px;
|
|
height: 40px;
|
|
z-index: 1000;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<img src="images/law.jpg" alt="Logo" class="header-logo">
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
position: relative;
|
|
}
|
|
.chat-container {
|
|
flex: 1;
|
|
max-width: 1360px;
|
|
margin: 0 auto;
|
|
width: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
padding: 20px;
|
|
box-sizing: border-box;
|
|
overflow-y: auto;
|
|
}
|
|
@media (max-width: 768px) {
|
|
.chat-container {
|
|
max-width: 100%;
|
|
padding: 10px;
|
|
}
|
|
}
|
|
.message-container {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 10px;
|
|
}
|
|
.input-container {
|
|
padding: 10px;
|
|
background: #f5f5f5;
|
|
position: sticky;
|
|
bottom: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
textarea {
|
|
width: calc(100% - 90px);
|
|
height: 60px;
|
|
padding: 10px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
resize: none;
|
|
margin-right: 10px;
|
|
}
|
|
button {
|
|
width: 20px;
|
|
height: 20px;
|
|
margin: 10px;
|
|
background: #007bff;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 50%;
|
|
cursor: pointer;
|
|
opacity: 0.7;
|
|
transition: opacity 0.2s, background-color 0.2s;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
button:hover {
|
|
opacity: 1;
|
|
}
|
|
button i {
|
|
font-size: 10px;
|
|
}
|
|
button:disabled {
|
|
background: #cccccc;
|
|
cursor: not-allowed;
|
|
opacity: 0.7;
|
|
}
|
|
.message {
|
|
width: 100%;
|
|
margin-bottom: 35px;
|
|
padding: 10px;
|
|
border-radius: 8px;
|
|
position: relative;
|
|
box-sizing: border-box;
|
|
}
|
|
.user-message {
|
|
text-align: right;
|
|
}
|
|
.user-message div {
|
|
font-weight: bold; /* 加粗 */
|
|
font-style: italic; /* 斜体 */
|
|
display: inline-block; /* 确保文本块行为正常 */
|
|
}
|
|
.bot-message {
|
|
text-align: left;
|
|
}
|
|
.copy-btn {
|
|
position: absolute;
|
|
right: 10px;
|
|
bottom: -20px;
|
|
width: 40px;
|
|
height: 40px;
|
|
background: none;
|
|
border: none;
|
|
cursor: pointer;
|
|
color: #007bff;
|
|
font-size: 20px;
|
|
opacity: 0.7;
|
|
transition: opacity 0.2s;
|
|
padding: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin: 0;
|
|
}
|
|
.loading-overlay {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background: rgba(0, 0, 0, 0.3);
|
|
display: none;
|
|
justify-content: center;
|
|
align-items: center;
|
|
z-index: 1000;
|
|
}
|
|
.spinner {
|
|
width: 40px;
|
|
height: 40px;
|
|
border: 4px solid #f3f3f3;
|
|
border-top: 4px solid #007bff;
|
|
border-radius: 50%;
|
|
animation: spin 1s linear infinite;
|
|
}
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="chat-container">
|
|
<div class="message-container" id="messageContainer"></div>
|
|
<div class="input-container">
|
|
<textarea id="messageInput" placeholder="请输入您的问题..."></textarea>
|
|
<button id="sendButton" onclick="sendMessage()" title="发送"><i class="fas fa-paper-plane"></i></button>
|
|
<button onclick="clearHistory()" style="background-color: #ff4d4f;" title="清空历史"><i class="fas fa-trash-alt"></i></button>
|
|
</div>
|
|
</div>
|
|
<div class="loading-overlay" id="loadingOverlay">
|
|
<div class="spinner"></div>
|
|
</div>
|
|
|
|
<script>
|
|
let conversationHistory = [];
|
|
|
|
function formatMarkdown(text) {
|
|
text = text.replace(/\n/g, '<br>');
|
|
text = text.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
|
|
text = text.replace(/\*(.*?)\*/g, '<em>$1</em>');
|
|
text = text.replace(/`(.*?)`/g, '<code>$1</code>');
|
|
text = text.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2" target="_blank">$1</a>');
|
|
return text;
|
|
}
|
|
|
|
async function sendMessage() {
|
|
const message = document.getElementById('messageInput').value;
|
|
const messageContainer = document.getElementById('messageContainer');
|
|
const sendButton = document.getElementById('sendButton');
|
|
const loadingOverlay = document.getElementById('loadingOverlay');
|
|
|
|
if (!message) {
|
|
alert('请输入消息');
|
|
return;
|
|
}
|
|
|
|
<<<<<<< HEAD
|
|
=======
|
|
loadingOverlay.style.display = 'flex';
|
|
sendButton.disabled = true;
|
|
|
|
>>>>>>> 19980d6 (update prompt)
|
|
const userMessageDiv = document.createElement('div');
|
|
userMessageDiv.className = 'message user-message';
|
|
userMessageDiv.innerHTML = `
|
|
<div>${message}</div>
|
|
`;
|
|
messageContainer.appendChild(userMessageDiv);
|
|
|
|
try {
|
|
conversationHistory.push({ role: 'user', content: message });
|
|
|
|
const response = await fetch('/api/chat', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
message,
|
|
history: conversationHistory
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
if (data.status === 'success') {
|
|
const formattedText = formatMarkdown(data.response.output.text);
|
|
const botMessageDiv = document.createElement('div');
|
|
botMessageDiv.className = 'message bot-message';
|
|
botMessageDiv.innerHTML = `
|
|
<div>${formattedText}</div>
|
|
<<<<<<< HEAD
|
|
=======
|
|
<button class="copy-btn" onclick="copyText(this)" title="复制"><i class="fas fa-copy"></i></button>
|
|
>>>>>>> 19980d6 (update prompt)
|
|
`;
|
|
messageContainer.appendChild(botMessageDiv);
|
|
|
|
conversationHistory.push({ role: 'assistant', content: data.response.output.text });
|
|
} else {
|
|
const errorMessageDiv = document.createElement('div');
|
|
errorMessageDiv.className = 'message bot-message';
|
|
errorMessageDiv.textContent = '请求失败,请稍后重试';
|
|
messageContainer.appendChild(errorMessageDiv);
|
|
}
|
|
} catch (error) {
|
|
console.error(error);
|
|
const errorMessageDiv = document.createElement('div');
|
|
errorMessageDiv.className = 'message bot-message';
|
|
errorMessageDiv.textContent = '网络错误,请检查连接';
|
|
messageContainer.appendChild(errorMessageDiv);
|
|
} finally {
|
|
loadingOverlay.style.display = 'none';
|
|
sendButton.disabled = false;
|
|
}
|
|
|
|
document.getElementById('messageInput').value = '';
|
|
messageContainer.scrollTop = messageContainer.scrollHeight;
|
|
}
|
|
|
|
function clearHistory() {
|
|
conversationHistory = [];
|
|
document.getElementById('messageContainer').innerHTML = '';
|
|
}
|
|
|
|
function copyText(button) {
|
|
const text = button.previousElementSibling.textContent;
|
|
navigator.clipboard.writeText(text).then(() => {
|
|
button.textContent = '已复制';
|
|
setTimeout(() => button.textContent = '复制', 2000);
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|
|
<<<<<<< HEAD
|
|
|
|
|
|
|
|
=======
|
|
>>>>>>> 19980d6 (update prompt)
|