`;
filesList.appendChild(fileItem);
});
- // 只有在WebSocket未连接时才显示连接中状态
- if (!websocket || websocket.readyState !== WebSocket.OPEN) {
- console.log('WebSocket未连接,显示连接中状态');
- updateP2PStatus(false);
- } else {
- console.log('WebSocket已连接,启用下载功能');
- updateP2PStatus(true);
- }
+ // 显示文件列表后,检查连接状态
+ console.log('文件列表显示完成,当前WebSocket状态:', websocket ? websocket.readyState : 'null');
+
+ // 延迟一点检查状态,确保DOM更新完成
+ setTimeout(() => {
+ if (websocket && websocket.readyState === WebSocket.OPEN) {
+ console.log('WebSocket已连接,启用下载功能');
+ updateP2PStatus(true);
+ } else {
+ console.log('WebSocket未连接,显示连接中状态');
+ updateP2PStatus(false);
+ }
+ }, 100);
}
// 下载文件(多人房间版本)
@@ -857,9 +1245,11 @@ function updateP2PStatus(connected) {
if (connected) {
console.log('设置为已连接状态');
receiverStatus.innerHTML = `
-
-
- 已连接,可以下载文件
+
`;
// 启用下载按钮
@@ -867,24 +1257,43 @@ function updateP2PStatus(connected) {
console.log('启用下载按钮:', btn);
btn.disabled = false;
btn.classList.remove('opacity-50', 'cursor-not-allowed');
- btn.classList.add('hover:bg-blue-600');
- if (btn.textContent === '⏳ 请求中...') {
- btn.textContent = '📥 下载';
+ btn.classList.add('hover:bg-green-600');
+
+ // 更新按钮内容
+ const svg = btn.querySelector('svg');
+ if (svg) {
+ svg.innerHTML = `
`;
+ }
+ const textNode = btn.childNodes[btn.childNodes.length - 1];
+ if (textNode && textNode.nodeType === Node.TEXT_NODE) {
+ textNode.textContent = '下载';
}
});
} else {
console.log('设置为连接中状态');
receiverStatus.innerHTML = `
-
-
- 正在建立连接...
+
`;
// 禁用下载按钮
downloadButtons.forEach(btn => {
btn.disabled = true;
btn.classList.add('opacity-50', 'cursor-not-allowed');
- btn.classList.remove('hover:bg-blue-600');
+ btn.classList.remove('hover:bg-green-600');
+
+ // 更新按钮内容为等待状态
+ const svg = btn.querySelector('svg');
+ if (svg) {
+ svg.innerHTML = `
`;
+ }
+ const textNode = btn.childNodes[btn.childNodes.length - 1];
+ if (textNode && textNode.nodeType === Node.TEXT_NODE) {
+ textNode.textContent = '等待连接';
+ }
});
}
} else {
@@ -906,20 +1315,34 @@ function showTransferProgress(fileId, type, fileName = null) {
}
progressContainer.classList.remove('hidden');
+ progressContainer.classList.add('fade-in-up');
const displayName = fileName || fileId;
const progressItem = document.createElement('div');
progressItem.id = `progress-${fileId}`;
- progressItem.className = 'bg-gray-100 p-3 rounded-lg';
+ progressItem.className = 'bg-white border border-gray-200 p-4 rounded-xl shadow-sm';
progressItem.innerHTML = `
-
-
文件: ${displayName}
-
${type === 'uploading' ? '上传中' : '下载中'}
+
+
+
+
+
${displayName}
+
${type === 'uploading' ? '正在发送' : '正在接收'}
+
+
+
-
-
+
-
0%
`;
progressList.appendChild(progressItem);
@@ -927,15 +1350,20 @@ function showTransferProgress(fileId, type, fileName = null) {
// 更新传输进度
function updateTransferProgress(fileId, progress, received, total) {
- const progressItem = document.getElementById(`progress-${fileId}`);
- if (!progressItem) return;
+ const progressBar = document.getElementById(`progress-bar-${fileId}`);
+ const progressPercent = document.getElementById(`progress-percent-${fileId}`);
+ const progressSize = document.getElementById(`progress-size-${fileId}`);
- const progressBar = progressItem.querySelector('.bg-blue-500');
- const progressText = progressItem.querySelector('.text-sm.text-gray-500:last-child');
-
- if (progressBar && progressText) {
+ if (progressBar) {
progressBar.style.width = `${progress}%`;
- progressText.textContent = `${progress.toFixed(1)}% (${formatFileSize(received)}/${formatFileSize(total)})`;
+ }
+
+ if (progressPercent) {
+ progressPercent.textContent = `${progress.toFixed(1)}%`;
+ }
+
+ if (progressSize) {
+ progressSize.textContent = `${formatFileSize(received)} / ${formatFileSize(total)}`;
}
}
diff --git a/web/templates/index.html b/web/templates/index.html
index 87f9172..e7f0b78 100644
--- a/web/templates/index.html
+++ b/web/templates/index.html
@@ -1,132 +1,350 @@
{{define "content"}}
-
-
-
-
-
-
P2P文件传输
-
选择文件自动生成取件码,对方输入取件码即可在线下载
-
+
+
-
-
-
-
-
📤 发送文件
+<
+
+
+
+
🔗 P2P文件传输
+
安全快速的点对点文件传输
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 选择文件并生成取件码
+
+
选择要发送的文件,系统会生成取件码供接收方使用
+
-
-
-
📁
-
点击选择文件或拖拽文件到此处
-
支持多文件选择
-
+
+
+
+
�
+
选择文件
+
点击或拖拽文件到此处
+
支持多文件选择
+
+
+
+
+
+
+
+
已选择文件
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
点击取件码或链接可直接复制
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 房间状态 📊
+
+
+
+
+ 在线用户:
+ 0
+
+
+ 发送方:
+ 0
+
+
+ 接收方:
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 输入取件码获取文件
+
+
输入6位取件码,连接发送方并下载文件
-
-
-
已选择的文件:
-
-
-