From c85a43f542621b17a748a799eda8aa3040c8f6b5 Mon Sep 17 00:00:00 2001 From: hz4th_coder Date: Sat, 11 Jul 2026 23:10:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A6=96=E9=A1=B5=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD=EF=BC=9A=E6=94=B9=E4=B8=BA=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=85=A8=E5=B1=80=E6=90=9C=E7=B4=A2API=E5=B9=B6?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/index.html | 133 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 3 deletions(-) diff --git a/templates/index.html b/templates/index.html index c0fdde1..3534259 100644 --- a/templates/index.html +++ b/templates/index.html @@ -56,8 +56,20 @@ + + + -
+

热门模型 @@ -241,8 +253,123 @@ // 搜索 async function search() { const keyword = document.getElementById('searchInput').value.trim(); - if (!keyword) return; - window.location.href = `/models?q=${encodeURIComponent(keyword)}`; + if (!keyword) { + // 清空搜索时恢复原页面 + document.getElementById('searchResults').classList.add('hidden'); + document.getElementById('hotModels').classList.remove('hidden'); + document.getElementById('statsCards').classList.remove('hidden'); + document.getElementById('categoryCards').parentElement.classList.remove('hidden'); + return; + } + + // 调用全局搜索 API + const res = await fetch(`/api/search?q=${encodeURIComponent(keyword)}`); + const data = await res.json(); + + // 显示搜索结果区域 + document.getElementById('searchResults').classList.remove('hidden'); + document.getElementById('searchKeyword').textContent = `"${keyword}"`; + document.getElementById('hotModels').classList.add('hidden'); + + // 渲染搜索结果 + renderSearchResults(data, keyword); + } + + // 渲染搜索结果 + function renderSearchResults(data, keyword) { + const models = data.models || []; + const gpus = data.gpus || []; + const cpus = data.cpus || []; + const total = models.length + gpus.length + cpus.length; + + if (total === 0) { + document.getElementById('searchContent').innerHTML = ` +
+ +

未找到与 "${keyword}" 相关的结果

+
+ `; + return; + } + + let html = `
找到 ${total} 条结果
`; + + // AI模型结果 + if (models.length > 0) { + html += ` +
+

+ + AI模型 (${models.length}) +

+ +
+ `; + } + + // GPU结果 + if (gpus.length > 0) { + html += ` +
+

+ + GPU显卡 (${gpus.length}) +

+ +
+ `; + } + + // CPU结果 + if (cpus.length > 0) { + html += ` +
+

+ + CPU处理器 (${cpus.length}) +

+ +
+ `; + } + + document.getElementById('searchContent').innerHTML = html; } // 初始化