From c7de90d7749b2f361c256bfe41e25614f0f6f477 Mon Sep 17 00:00:00 2001 From: cjw <792430652@qq.com> Date: Mon, 16 Feb 2026 01:18:51 +0800 Subject: [PATCH] deving --- static/history.js | 165 ++++++++++++++++ templates/history.html | 207 +++++++++++++++++++ templates/result.html | 437 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 809 insertions(+) create mode 100644 static/history.js create mode 100644 templates/history.html create mode 100644 templates/result.html diff --git a/static/history.js b/static/history.js new file mode 100644 index 0000000..c1430b5 --- /dev/null +++ b/static/history.js @@ -0,0 +1,165 @@ +// static/history.js + +// 页面加载完成后加载历史记录 +document.addEventListener('DOMContentLoaded', function() { + loadHistory(); +}); + +async function loadHistory() { + const fileList = document.getElementById('fileList'); + + try { + const response = await fetch('/api/history'); + if (!response.ok) { + throw new Error('获取历史记录失败'); + } + + const data = await response.json(); + + if (data.files && data.files.length > 0) { + displayFileList(data.files); + } else { + fileList.innerHTML = ` +
+
📁
+

暂无历史记录

+

还没有上传过STP文件

+ +
+ `; + } + + } catch (error) { + fileList.innerHTML = ` +
+
❌
+

加载失败

+

${error.message}

+ +
+ `; + } +} + +function displayFileList(files) { + const fileList = document.getElementById('fileList'); + + fileList.innerHTML = files.map(file => ` +
+
+
+
📄 ${file.filename}
+
+ 总记录: ${file.record_count} 条 | + 最后上传: ${new Date(file.last_upload).toLocaleString()} +
+
+ +
+
+
+
+

正在加载记录详情...

+
+
+
+ `).join(''); +} + +async function toggleFileRecords(filename) { + const fileItem = document.getElementById(`file-${filename}`); + const recordList = document.getElementById(`records-${filename}`); + const expandBtn = fileItem.querySelector('.expand-btn'); + + // 切换展开状态 + if (fileItem.classList.contains('expanded')) { + fileItem.classList.remove('expanded'); + expandBtn.textContent = '➕'; + return; + } + + // 先设置展开状态 + fileItem.classList.add('expanded'); + expandBtn.textContent = '➖'; + + // 如果已经加载过数据,直接显示 + if (recordList.dataset.loaded === 'true') { + return; + } + + try { + const response = await fetch(`/api/history/${encodeURIComponent(filename)}`); + if (!response.ok) { + throw new Error('获取记录详情失败'); + } + + const records = await response.json(); + + if (records.length > 0) { + recordList.innerHTML = records.map(record => ` +
+
+
+ 📅 ${new Date(record.upload_time).toLocaleString()} +
+
+ ${getStatusText(record.status)} +
+
+
+
文件大小: ${formatFileSize(record.file_size)}
+
任务ID: ${record.task_id}
+
状态: ${record.status}
+ ${record.completed_at ? `
完成时间: ${new Date(record.completed_at).toLocaleTimeString()}
` : ''} +
+
+ `).join(''); + } else { + recordList.innerHTML = ` +
+

暂无详细记录

+
+ `; + } + + recordList.dataset.loaded = 'true'; + + } catch (error) { + recordList.innerHTML = ` +
+

❌ 加载失败: ${error.message}

+ +
+ `; + } +} + +function viewRecordDetails(taskId) { + // 跳转到详细结果页面 + window.location.href = `/result/${taskId}`; +} + +function getStatusText(status) { + const statusMap = { + 'completed': '已完成', + 'processing': '处理中', + 'failed': '失败' + }; + return statusMap[status] || status; +} + +function formatFileSize(bytes) { + if (!bytes || bytes === 0) return '0 Bytes'; + const k = 1024; + const sizes = ['Bytes', 'KB', 'MB', 'GB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; +} \ No newline at end of file diff --git a/templates/history.html b/templates/history.html new file mode 100644 index 0000000..8e82a5b --- /dev/null +++ b/templates/history.html @@ -0,0 +1,207 @@ + + + + + + + 历史记录 - STP文件几何分析工具 + + + + +
+
+
+

📊 历史记录

+

查看所有上传的STP文件分析记录

+
+ +
+ +
+
+
+

正在加载历史记录...

+
+
+
+ + + + \ No newline at end of file diff --git a/templates/result.html b/templates/result.html new file mode 100644 index 0000000..8b9a7e0 --- /dev/null +++ b/templates/result.html @@ -0,0 +1,437 @@ + + + + + + + 分析结果 - STP文件几何分析工具 + + + + +
+
+
+

📊 分析结果详情

+

查看STP文件的详细分析结果

+
+ +
+ +
+
+
+

正在加载任务信息...

+
+
+ +
+ +
+
+ + + + \ No newline at end of file