仿生人AI服务端测试网页

This commit is contained in:
BBIT-Kai
2025-11-05 18:05:09 +08:00
parent 179604931d
commit f50521e548
14 changed files with 6521 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import { getLogContainer } from '../document.js'
const logContainer = getLogContainer();
// 日志记录函数
export function log(message, type = 'info') {
// 将消息按换行符分割成多行
const lines = message.split('\n');
const now = new Date();
// const timestamp = `[${now.toLocaleTimeString()}] `;
const timestamp = `[${now.toLocaleTimeString()}.${now.getMilliseconds().toString().padStart(3, '0')}] `;
// 为每一行创建日志条目
lines.forEach((line, index) => {
const logEntry = document.createElement('div');
logEntry.className = `log-entry log-${type}`;
// 如果是第一条日志,显示时间戳
const prefix = index === 0 ? timestamp : ' '.repeat(timestamp.length);
logEntry.textContent = `${prefix}${line}`;
// logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
// logEntry.style 保留起始的空格
logEntry.style.whiteSpace = 'pre';
if (type === 'error') {
logEntry.style.color = 'red';
} else if (type === 'debug') {
logEntry.style.color = 'gray';
return;
} else if (type === 'warning') {
logEntry.style.color = 'orange';
} else if (type === 'success') {
logEntry.style.color = 'green';
} else {
logEntry.style.color = 'black';
}
logContainer.appendChild(logEntry);
});
logContainer.scrollTop = logContainer.scrollHeight;
}