|
@@ -1,96 +1,430 @@
|
|
|
<!DOCTYPE html>
|
|
<!DOCTYPE html>
|
|
|
-<html lang="zh">
|
|
|
|
|
|
|
+<html lang="zh-CN">
|
|
|
<head>
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
<meta charset="UTF-8">
|
|
|
- <title>宝可梦卡片搜索</title>
|
|
|
|
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
+ <title>Pokemon Card Search</title>
|
|
|
<style>
|
|
<style>
|
|
|
- body { font-family: sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; }
|
|
|
|
|
- .container { display: flex; gap: 20px; }
|
|
|
|
|
- .upload-section { flex: 1; border-right: 1px solid #ccc; padding-right: 20px; }
|
|
|
|
|
- .results-section { flex: 2; }
|
|
|
|
|
- .card { border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; display: flex; align-items: center; border-radius: 8px; }
|
|
|
|
|
- .card img { max-width: 100px; max-height: 140px; margin-right: 20px; }
|
|
|
|
|
- .card-info { font-size: 14px; }
|
|
|
|
|
- .similarity { color: green; font-weight: bold; }
|
|
|
|
|
|
|
+ :root {
|
|
|
|
|
+ --primary-color: #4F46E5; /* 靛蓝色 */
|
|
|
|
|
+ --primary-hover: #4338ca;
|
|
|
|
|
+ --bg-color: #f3f4f6;
|
|
|
|
|
+ --card-bg: #ffffff;
|
|
|
|
|
+ --text-main: #1f2937;
|
|
|
|
|
+ --text-sub: #6b7280;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ * { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
|
+
|
|
|
|
|
+ body {
|
|
|
|
|
+ font-family: 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
|
|
|
|
|
+ background-color: var(--bg-color);
|
|
|
|
|
+ color: var(--text-main);
|
|
|
|
|
+ line-height: 1.5;
|
|
|
|
|
+ padding: 2rem 1rem;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .container {
|
|
|
|
|
+ max-width: 1200px;
|
|
|
|
|
+ margin: 0 auto;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ header {
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ margin-bottom: 2rem;
|
|
|
|
|
+ }
|
|
|
|
|
+ header h1 {
|
|
|
|
|
+ font-size: 2.5rem;
|
|
|
|
|
+ color: var(--text-main);
|
|
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
|
|
+ }
|
|
|
|
|
+ header p { color: var(--text-sub); }
|
|
|
|
|
+
|
|
|
|
|
+ /* 搜索上传区域 */
|
|
|
|
|
+ .search-panel {
|
|
|
|
|
+ background: var(--card-bg);
|
|
|
|
|
+ padding: 2rem;
|
|
|
|
|
+ border-radius: 16px;
|
|
|
|
|
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
|
|
|
|
+ max-width: 600px;
|
|
|
|
|
+ margin: 0 auto 3rem auto;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .upload-zone {
|
|
|
|
|
+ border: 2px dashed #d1d5db;
|
|
|
|
|
+ border-radius: 12px;
|
|
|
|
|
+ padding: 2rem;
|
|
|
|
|
+ margin-bottom: 1.5rem;
|
|
|
|
|
+ cursor: pointer;
|
|
|
|
|
+ transition: all 0.3s ease;
|
|
|
|
|
+ position: relative;
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .upload-zone:hover {
|
|
|
|
|
+ border-color: var(--primary-color);
|
|
|
|
|
+ background-color: #f9fafb;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* 拖拽激活时的样式 */
|
|
|
|
|
+ .upload-zone.drag-active {
|
|
|
|
|
+ border-color: var(--primary-color);
|
|
|
|
|
+ background-color: #eef2ff; /* 浅蓝色背景 */
|
|
|
|
|
+ transform: scale(1.02);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #preview-container {
|
|
|
|
|
+ display: none;
|
|
|
|
|
+ margin-top: 1rem;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #preview-img {
|
|
|
|
|
+ max-width: 100%;
|
|
|
|
|
+ max-height: 300px;
|
|
|
|
|
+ border-radius: 8px;
|
|
|
|
|
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ input[type="file"] { display: none; }
|
|
|
|
|
+
|
|
|
|
|
+ .upload-label {
|
|
|
|
|
+ display: block;
|
|
|
|
|
+ color: var(--text-sub);
|
|
|
|
|
+ font-weight: 500;
|
|
|
|
|
+ pointer-events: none;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .controls {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ gap: 1rem;
|
|
|
|
|
+ margin-bottom: 1rem;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .search-btn {
|
|
|
|
|
+ background-color: var(--primary-color);
|
|
|
|
|
+ color: white;
|
|
|
|
|
+ border: none;
|
|
|
|
|
+ padding: 0.75rem 2rem;
|
|
|
|
|
+ border-radius: 8px;
|
|
|
|
|
+ font-size: 1rem;
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+ cursor: pointer;
|
|
|
|
|
+ transition: background-color 0.2s;
|
|
|
|
|
+ display: inline-flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .search-btn:hover { background-color: var(--primary-hover); }
|
|
|
|
|
+ .search-btn:disabled { background-color: #9ca3af; cursor: not-allowed; }
|
|
|
|
|
+
|
|
|
|
|
+ .top-n-input {
|
|
|
|
|
+ padding: 0.75rem;
|
|
|
|
|
+ border: 1px solid #d1d5db;
|
|
|
|
|
+ border-radius: 8px;
|
|
|
|
|
+ width: 80px;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* 结果展示区域 */
|
|
|
|
|
+ .results-grid {
|
|
|
|
|
+ display: grid;
|
|
|
|
|
+ grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
|
|
|
|
+ gap: 1.5rem;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .result-card {
|
|
|
|
|
+ background: var(--card-bg);
|
|
|
|
|
+ border-radius: 12px;
|
|
|
|
|
+ overflow: hidden;
|
|
|
|
|
+ box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
|
|
|
|
+ transition: transform 0.2s, box-shadow 0.2s;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ flex-direction: column;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .result-card:hover {
|
|
|
|
|
+ transform: translateY(-5px);
|
|
|
|
|
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .card-img-wrapper {
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+ height: 280px;
|
|
|
|
|
+ background-color: #e5e7eb;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+ overflow: hidden;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .card-img-wrapper img {
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ object-fit: contain;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .card-info { padding: 1rem; }
|
|
|
|
|
+
|
|
|
|
|
+ .card-title {
|
|
|
|
|
+ font-size: 1.1rem;
|
|
|
|
|
+ font-weight: bold;
|
|
|
|
|
+ color: var(--text-main);
|
|
|
|
|
+ margin-bottom: 0.25rem;
|
|
|
|
|
+ white-space: nowrap;
|
|
|
|
|
+ overflow: hidden;
|
|
|
|
|
+ text-overflow: ellipsis;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .card-meta {
|
|
|
|
|
+ font-size: 0.875rem;
|
|
|
|
|
+ color: var(--text-sub);
|
|
|
|
|
+ margin-bottom: 0.75rem;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ justify-content: space-between;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .score-bar-bg {
|
|
|
|
|
+ height: 6px;
|
|
|
|
|
+ background-color: #e5e7eb;
|
|
|
|
|
+ border-radius: 3px;
|
|
|
|
|
+ overflow: hidden;
|
|
|
|
|
+ margin-top: 0.5rem;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .score-bar-fill {
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ background-color: #10b981;
|
|
|
|
|
+ width: 0%;
|
|
|
|
|
+ transition: width 0.5s ease-out;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .score-text {
|
|
|
|
|
+ font-size: 0.75rem;
|
|
|
|
|
+ color: var(--text-sub);
|
|
|
|
|
+ margin-top: 4px;
|
|
|
|
|
+ text-align: right;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .spinner {
|
|
|
|
|
+ border: 3px solid rgba(255,255,255,0.3);
|
|
|
|
|
+ border-radius: 50%;
|
|
|
|
|
+ border-top: 3px solid white;
|
|
|
|
|
+ width: 20px;
|
|
|
|
|
+ height: 20px;
|
|
|
|
|
+ animation: spin 1s linear infinite;
|
|
|
|
|
+ margin-right: 8px;
|
|
|
|
|
+ display: none;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @keyframes spin {
|
|
|
|
|
+ 0% { transform: rotate(0deg); }
|
|
|
|
|
+ 100% { transform: rotate(360deg); }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @media (max-width: 640px) {
|
|
|
|
|
+ header h1 { font-size: 1.8rem; }
|
|
|
|
|
+ .results-grid { grid-template-columns: 1fr 1fr; }
|
|
|
|
|
+ .card-img-wrapper { height: 200px; }
|
|
|
|
|
+ }
|
|
|
</style>
|
|
</style>
|
|
|
</head>
|
|
</head>
|
|
|
<body>
|
|
<body>
|
|
|
- <h1>🔍 Pokemon Card Search</h1>
|
|
|
|
|
|
|
|
|
|
<div class="container">
|
|
<div class="container">
|
|
|
- <div class="upload-section">
|
|
|
|
|
- <h3>图片搜索</h3>
|
|
|
|
|
- <input type="file" id="imgInput" accept="image/*">
|
|
|
|
|
- <br><br>
|
|
|
|
|
- <label>Top N: <input type="number" id="topN" value="5" style="width: 50px;"></label>
|
|
|
|
|
- <br><br>
|
|
|
|
|
- <button onclick="searchImage()">搜索</button>
|
|
|
|
|
- <br><hr><br>
|
|
|
|
|
- <h3>文字过滤</h3>
|
|
|
|
|
- <input type="text" id="nameFilter" placeholder="卡名 (如 Swadloon)">
|
|
|
|
|
- <button onclick="filterData()">查询</button>
|
|
|
|
|
|
|
+ <header>
|
|
|
|
|
+ <h1>🔍 Pokemon Card Search</h1>
|
|
|
|
|
+ <p>Upload a card image to find similar matches</p>
|
|
|
|
|
+ </header>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="search-panel">
|
|
|
|
|
+ <!-- 上传区域:增加 id 和 ondrop 处理 -->
|
|
|
|
|
+ <div class="upload-zone" id="dropZone">
|
|
|
|
|
+ <div id="upload-placeholder">
|
|
|
|
|
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#9ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
|
|
+ <rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
|
|
|
|
|
+ <circle cx="8.5" cy="8.5" r="1.5"></circle>
|
|
|
|
|
+ <polyline points="21 15 16 10 5 21"></polyline>
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ <span class="upload-label">点击或拖拽上传图片</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div id="preview-container">
|
|
|
|
|
+ <img id="preview-img" src="" alt="Input Preview">
|
|
|
|
|
+ <p style="margin-top:0.5rem; color:var(--text-sub); font-size:0.9rem;">点击可重新选择</p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 隐藏的 input -->
|
|
|
|
|
+ <input type="file" id="imgInput" accept="image/*">
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="controls">
|
|
|
|
|
+ <div style="display:flex; align-items:center; gap:0.5rem;">
|
|
|
|
|
+ <label for="topN" style="font-weight:500; color:var(--text-sub)">Top Results:</label>
|
|
|
|
|
+ <input type="number" id="topN" class="top-n-input" value="5" min="1" max="20">
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <button class="search-btn" onclick="searchImage()" id="searchBtn">
|
|
|
|
|
+ <div class="spinner" id="loadingSpinner"></div>
|
|
|
|
|
+ Search
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- <div class="results-section">
|
|
|
|
|
- <h3>结果</h3>
|
|
|
|
|
- <div id="results"></div>
|
|
|
|
|
|
|
+ <div id="resultsArea">
|
|
|
|
|
+ <h3 style="margin-bottom: 1rem; color: var(--text-sub); display:none;" id="resultTitle">Search Results</h3>
|
|
|
|
|
+ <div class="results-grid" id="resultsGrid"></div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
+ const imgInput = document.getElementById('imgInput');
|
|
|
|
|
+ const dropZone = document.getElementById('dropZone');
|
|
|
|
|
+ const previewContainer = document.getElementById('preview-container');
|
|
|
|
|
+ const previewImg = document.getElementById('preview-img');
|
|
|
|
|
+ const placeholder = document.getElementById('upload-placeholder');
|
|
|
|
|
+
|
|
|
|
|
+ // --- 核心改动:处理拖拽事件 ---
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 阻止浏览器默认行为 (打开图片)
|
|
|
|
|
+ ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
|
|
|
|
+ dropZone.addEventListener(eventName, preventDefaults, false);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ function preventDefaults(e) {
|
|
|
|
|
+ e.preventDefault();
|
|
|
|
|
+ e.stopPropagation();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 视觉反馈 (高亮)
|
|
|
|
|
+ ['dragenter', 'dragover'].forEach(eventName => {
|
|
|
|
|
+ dropZone.addEventListener(eventName, () => dropZone.classList.add('drag-active'), false);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ ['dragleave', 'drop'].forEach(eventName => {
|
|
|
|
|
+ dropZone.addEventListener(eventName, () => dropZone.classList.remove('drag-active'), false);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 处理文件放置 (Drop)
|
|
|
|
|
+ dropZone.addEventListener('drop', handleDrop, false);
|
|
|
|
|
+
|
|
|
|
|
+ function handleDrop(e) {
|
|
|
|
|
+ const dt = e.dataTransfer;
|
|
|
|
|
+ const files = dt.files;
|
|
|
|
|
+
|
|
|
|
|
+ if (files && files.length > 0) {
|
|
|
|
|
+ // 将拖入的文件赋值给 input 元素,方便后续搜索逻辑使用
|
|
|
|
|
+ imgInput.files = files;
|
|
|
|
|
+ updatePreview(files[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 处理点击上传 (Click)
|
|
|
|
|
+ dropZone.addEventListener('click', () => imgInput.click());
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 阻止 input 的点击事件冒泡 (防止触发 dropZone 的 click 导致死循环)
|
|
|
|
|
+ imgInput.addEventListener('click', (e) => e.stopPropagation());
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 监听 Input 变化 (点击选择文件后触发)
|
|
|
|
|
+ imgInput.onchange = (e) => {
|
|
|
|
|
+ if (imgInput.files && imgInput.files[0]) {
|
|
|
|
|
+ updatePreview(imgInput.files[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // --- 统一的预览逻辑 ---
|
|
|
|
|
+ function updatePreview(file) {
|
|
|
|
|
+ if (file) {
|
|
|
|
|
+ placeholder.style.display = 'none';
|
|
|
|
|
+ previewContainer.style.display = 'block';
|
|
|
|
|
+ previewImg.src = URL.createObjectURL(file);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // --- 搜索逻辑 (保持不变) ---
|
|
|
async function searchImage() {
|
|
async function searchImage() {
|
|
|
- const input = document.getElementById('imgInput');
|
|
|
|
|
|
|
+ if (!imgInput.files[0]) {
|
|
|
|
|
+ alert("请先选择一张图片!");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const btn = document.getElementById('searchBtn');
|
|
|
|
|
+ const spinner = document.getElementById('loadingSpinner');
|
|
|
const topN = document.getElementById('topN').value;
|
|
const topN = document.getElementById('topN').value;
|
|
|
- if (!input.files[0]) return alert("请选择图片");
|
|
|
|
|
|
|
+ const grid = document.getElementById('resultsGrid');
|
|
|
|
|
+ const resultTitle = document.getElementById('resultTitle');
|
|
|
|
|
|
|
|
- const formData = new FormData();
|
|
|
|
|
- formData.append('file', input.files[0]);
|
|
|
|
|
|
|
+ btn.disabled = true;
|
|
|
|
|
+ spinner.style.display = 'block';
|
|
|
|
|
+ grid.innerHTML = '';
|
|
|
|
|
+ resultTitle.style.display = 'none';
|
|
|
|
|
|
|
|
- const res = await fetch(`/search/image?top_k=${topN}`, {
|
|
|
|
|
- method: 'POST',
|
|
|
|
|
- body: formData
|
|
|
|
|
- });
|
|
|
|
|
- const data = await res.json();
|
|
|
|
|
- renderResults(data.results);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+ formData.append('file', imgInput.files[0]);
|
|
|
|
|
|
|
|
- async function filterData() {
|
|
|
|
|
- const name = document.getElementById('nameFilter').value;
|
|
|
|
|
- const res = await fetch(`/search/filter?card_name=${name}&limit=10`, {
|
|
|
|
|
- method: 'POST'
|
|
|
|
|
- });
|
|
|
|
|
- const data = await res.json();
|
|
|
|
|
- renderResults(data.data, false);
|
|
|
|
|
|
|
+ const res = await fetch(`/api/search/image?top_k=${topN}`, {
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ body: formData
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (!res.ok) throw new Error("Server Error");
|
|
|
|
|
+
|
|
|
|
|
+ const data = await res.json();
|
|
|
|
|
+ renderResults(data.results);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ alert("搜索出错: " + error.message);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ btn.disabled = false;
|
|
|
|
|
+ spinner.style.display = 'none';
|
|
|
|
|
+ resultTitle.style.display = 'block';
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function renderResults(items, isSearch=true) {
|
|
|
|
|
- const container = document.getElementById('results');
|
|
|
|
|
- container.innerHTML = '';
|
|
|
|
|
|
|
+ function renderResults(items) {
|
|
|
|
|
+ const grid = document.getElementById('resultsGrid');
|
|
|
|
|
|
|
|
if (!items || items.length === 0) {
|
|
if (!items || items.length === 0) {
|
|
|
- container.innerHTML = '<p>无结果</p>';
|
|
|
|
|
|
|
+ grid.innerHTML = '<p style="text-align:center; grid-column: 1/-1; color:#666;">未找到相似结果</p>';
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- items.forEach(item => {
|
|
|
|
|
- const div = document.createElement('div');
|
|
|
|
|
- div.className = 'card';
|
|
|
|
|
-
|
|
|
|
|
- // 计算显示内容
|
|
|
|
|
- let scoreHtml = isSearch ? `<p class="similarity">相似度: ${(item.score).toFixed(4)}</p>` : '';
|
|
|
|
|
|
|
+ items.forEach((item, index) => {
|
|
|
|
|
+ const percentage = (item.score * 100).toFixed(1);
|
|
|
|
|
+ const cardNumDisplay = (item.card_num && item.card_num !== -1) ? `#${item.card_num}` : '';
|
|
|
|
|
|
|
|
- div.innerHTML = `
|
|
|
|
|
- <img src="${item.img_url}" alt="${item.card_name}" onerror="this.src=''">
|
|
|
|
|
- <div class="card-info">
|
|
|
|
|
- <h3>${item.card_name} #${item.card_num}</h3>
|
|
|
|
|
- <p>语言: ${item.lang} | Source ID: ${item.source_id}</p>
|
|
|
|
|
- ${scoreHtml}
|
|
|
|
|
- <p style="color:gray; font-size:12px;">ID: ${item.id}</p>
|
|
|
|
|
|
|
+ const cardHtml = `
|
|
|
|
|
+ <div class="result-card" style="opacity: 0; animation: fadeIn 0.5s forwards ${index * 0.1}s">
|
|
|
|
|
+ <div class="card-img-wrapper">
|
|
|
|
|
+ <img src="${item.img_url}" alt="${item.card_name}" onerror="this.src='https://via.placeholder.com/200?text=Image+Not+Found'">
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="card-info">
|
|
|
|
|
+ <div class="card-title" title="${item.card_name}">${item.card_name}</div>
|
|
|
|
|
+ <div class="card-meta">
|
|
|
|
|
+ <span>${item.lang.toUpperCase()}</span>
|
|
|
|
|
+ <span>${cardNumDisplay}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="score-bar-bg">
|
|
|
|
|
+ <div class="score-bar-fill" style="width: ${percentage}%"></div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="score-text">Sim: ${percentage}%</div>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
`;
|
|
`;
|
|
|
- container.appendChild(div);
|
|
|
|
|
|
|
+ grid.insertAdjacentHTML('beforeend', cardHtml);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ const style = document.createElement('style');
|
|
|
|
|
+ style.innerHTML = `
|
|
|
|
|
+ @keyframes fadeIn {
|
|
|
|
|
+ from { opacity: 0; transform: translateY(10px); }
|
|
|
|
|
+ to { opacity: 1; transform: translateY(0); }
|
|
|
|
|
+ }
|
|
|
|
|
+ `;
|
|
|
|
|
+ document.head.appendChild(style);
|
|
|
</script>
|
|
</script>
|
|
|
</body>
|
|
</body>
|
|
|
</html>
|
|
</html>
|