|
@@ -1,298 +0,0 @@
|
|
|
-<!DOCTYPE html>
|
|
|
-<html lang="zh">
|
|
|
-<head>
|
|
|
- <meta charset="UTF-8">
|
|
|
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
- <title>图片搜索测试界面</title>
|
|
|
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
- <style>
|
|
|
- .preview-image {
|
|
|
- max-width: 200px;
|
|
|
- max-height: 200px;
|
|
|
- margin: 10px;
|
|
|
- border: 1px solid #ddd;
|
|
|
- border-radius: 4px;
|
|
|
- padding: 5px;
|
|
|
- }
|
|
|
- .preview-container {
|
|
|
- margin: 10px 0;
|
|
|
- min-height: 100px;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- justify-content: center;
|
|
|
- }
|
|
|
- .loading {
|
|
|
- position: relative;
|
|
|
- min-height: 200px;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- justify-content: center;
|
|
|
- background-color: rgba(255, 255, 255, 0.8);
|
|
|
- }
|
|
|
- .loading::after {
|
|
|
- content: "搜索中...";
|
|
|
- font-size: 16px;
|
|
|
- color: #666;
|
|
|
- }
|
|
|
- .result-card {
|
|
|
- border: 1px solid #ddd;
|
|
|
- border-radius: 8px;
|
|
|
- padding: 10px;
|
|
|
- margin: 10px;
|
|
|
- width: 250px;
|
|
|
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
|
- }
|
|
|
- .result-image {
|
|
|
- max-width: 230px;
|
|
|
- max-height: 230px;
|
|
|
- object-fit: contain;
|
|
|
- display: block;
|
|
|
- margin: 0 auto;
|
|
|
- }
|
|
|
- .results-container {
|
|
|
- display: flex;
|
|
|
- flex-wrap: wrap;
|
|
|
- gap: 15px;
|
|
|
- margin-top: 20px;
|
|
|
- justify-content: flex-start;
|
|
|
- }
|
|
|
- .result-info {
|
|
|
- margin-top: 10px;
|
|
|
- font-size: 14px;
|
|
|
- }
|
|
|
- .score-badge {
|
|
|
- background-color: #007bff;
|
|
|
- color: white;
|
|
|
- padding: 2px 6px;
|
|
|
- border-radius: 4px;
|
|
|
- font-size: 12px;
|
|
|
- }
|
|
|
- </style>
|
|
|
-</head>
|
|
|
-<body>
|
|
|
- <div class="container mt-5">
|
|
|
- <h2 class="mb-4">图片搜索测试界面</h2>
|
|
|
-
|
|
|
-
|
|
|
- <div class="mb-4">
|
|
|
- <label for="token" class="form-label">Authorization Token:</label>
|
|
|
- <input type="text" class="form-control" id="token" placeholder="输入token">
|
|
|
- </div>
|
|
|
-
|
|
|
-
|
|
|
- <div class="card mb-4">
|
|
|
- <div class="card-header">
|
|
|
- 上传图片
|
|
|
- </div>
|
|
|
- <div class="card-body">
|
|
|
- <div class="mb-3">
|
|
|
- <label for="imageUrl" class="form-label">图片URL</label>
|
|
|
- <input type="text" class="form-control" id="imageUrl" placeholder="输入图片URL">
|
|
|
- </div>
|
|
|
- <div class="mb-3">
|
|
|
- <label for="nameCn" class="form-label">中文名称</label>
|
|
|
- <input type="text" class="form-control" id="nameCn">
|
|
|
- </div>
|
|
|
- <div id="uploadPreview"></div>
|
|
|
- <button class="btn btn-primary" onclick="uploadImage()">上传</button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-
|
|
|
-
|
|
|
- <div class="card mb-4">
|
|
|
- <div class="card-header">
|
|
|
- 搜索图片
|
|
|
- </div>
|
|
|
- <div class="card-body">
|
|
|
- <div class="mb-3">
|
|
|
- <label for="searchImageUrl" class="form-label">搜索图片URL</label>
|
|
|
- <input type="text" class="form-control" id="searchImageUrl" placeholder="输入搜索图片URL">
|
|
|
- </div>
|
|
|
- <div id="searchPreview" class="preview-container"></div>
|
|
|
- <button class="btn btn-primary" onclick="searchImage()" id="searchBtn">搜索</button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-
|
|
|
-
|
|
|
- <div class="card">
|
|
|
- <div class="card-header">
|
|
|
- 搜索结果
|
|
|
- </div>
|
|
|
- <div class="card-body">
|
|
|
- <div id="searchResults" class="results-container"></div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <script>
|
|
|
- const baseUrl = 'http://47.96.90.34:18081/website';
|
|
|
-
|
|
|
- // 预览URL图片
|
|
|
- document.getElementById('imageUrl').addEventListener('change', function(e) {
|
|
|
- previewImageUrl(this.value, 'uploadPreview');
|
|
|
- });
|
|
|
-
|
|
|
- document.getElementById('searchImageUrl').addEventListener('input', function(e) {
|
|
|
- previewImageUrl(this.value, 'searchPreview');
|
|
|
- });
|
|
|
-
|
|
|
- // 清理URL,移除可能的重复拼接
|
|
|
- function cleanImageUrl(url) {
|
|
|
- try {
|
|
|
- // 如果URL包含我们的API endpoint,说明可能是重复拼接的
|
|
|
- const apiEndpoint = `${baseUrl}/image/fassi/list?url=`;
|
|
|
- if (url.includes(apiEndpoint)) {
|
|
|
- // 提取实际的图片URL
|
|
|
- const startIndex = url.lastIndexOf(apiEndpoint) + apiEndpoint.length;
|
|
|
- url = decodeURIComponent(url.substring(startIndex));
|
|
|
- }
|
|
|
- return url;
|
|
|
- } catch (error) {
|
|
|
- console.error('URL清理错误:', error);
|
|
|
- return url;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function previewImageUrl(url, previewId) {
|
|
|
- if (!url) {
|
|
|
- document.getElementById(previewId).innerHTML = '';
|
|
|
- return;
|
|
|
- }
|
|
|
- const cleanedUrl = cleanImageUrl(url);
|
|
|
- const previewDiv = document.getElementById(previewId);
|
|
|
- previewDiv.innerHTML = `
|
|
|
- <img src="${cleanedUrl}"
|
|
|
- class="preview-image"
|
|
|
- onerror="this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgZmlsbD0iI2VlZSIvPjx0ZXh0IHg9IjUwJSIgeT0iNTAlIiBmb250LWZhbWlseT0iQXJpYWwiIGZvbnQtc2l6ZT0iMTYiIGZpbGw9IiNhYWEiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGR5PSIuM2VtIj7lm77niYfliqDovb3lpLHotKU8L3RleHQ+PC9zdmc+'"
|
|
|
- alt="预览图片">
|
|
|
- `;
|
|
|
- }
|
|
|
-
|
|
|
- async function uploadImage() {
|
|
|
- const imageUrl = document.getElementById('imageUrl').value;
|
|
|
- if (!imageUrl) {
|
|
|
- alert('请输入图片URL');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const token = document.getElementById('token').value;
|
|
|
- if (!token) {
|
|
|
- alert('请输入token');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- const response = await fetch(`${baseUrl}/image/create`, {
|
|
|
- method: 'POST',
|
|
|
- headers: {
|
|
|
- 'Authorization': token,
|
|
|
- 'Content-Type': 'application/json'
|
|
|
- },
|
|
|
- body: JSON.stringify({
|
|
|
- rawImage: { url: imageUrl },
|
|
|
- nameCn: document.getElementById('nameCn').value || 'test'
|
|
|
- })
|
|
|
- });
|
|
|
-
|
|
|
- const data = await response.json();
|
|
|
- if (response.ok) {
|
|
|
- alert('上传成功');
|
|
|
- } else {
|
|
|
- alert('上传失败: ' + JSON.stringify(data));
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- alert('上传出错: ' + error.message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- async function searchImage() {
|
|
|
- const imageUrl = document.getElementById('searchImageUrl').value;
|
|
|
- if (!imageUrl) {
|
|
|
- alert('请输入搜索图片URL');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const token = document.getElementById('token').value;
|
|
|
- if (!token) {
|
|
|
- alert('请输入token');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 禁用搜索按钮并显示加载状态
|
|
|
- const searchBtn = document.getElementById('searchBtn');
|
|
|
- const resultsDiv = document.getElementById('searchResults');
|
|
|
- searchBtn.disabled = true;
|
|
|
- resultsDiv.innerHTML = '<div class="loading"></div>';
|
|
|
-
|
|
|
- try {
|
|
|
- const cleanedUrl = cleanImageUrl(imageUrl);
|
|
|
- const encodedUrl = encodeURIComponent(cleanedUrl);
|
|
|
- const response = await fetch(`${baseUrl}/image/fassi/list?url=${encodedUrl}`, {
|
|
|
- method: 'GET',
|
|
|
- headers: {
|
|
|
- 'Authorization': token,
|
|
|
- 'Content-Type': 'application/json'
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- const data = await response.json();
|
|
|
- if (response.ok && data.errorNo === 200) {
|
|
|
- displayResults(data.result);
|
|
|
- } else {
|
|
|
- resultsDiv.innerHTML = `<div class="alert alert-danger" role="alert">
|
|
|
- 搜索失败: ${data.errorDesc || JSON.stringify(data)}
|
|
|
- </div>`;
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- resultsDiv.innerHTML = `<div class="alert alert-danger" role="alert">
|
|
|
- 搜索出错: ${error.message}
|
|
|
- </div>`;
|
|
|
- } finally {
|
|
|
- // 恢复搜索按钮状态
|
|
|
- searchBtn.disabled = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function displayResults(results) {
|
|
|
- const resultsDiv = document.getElementById('searchResults');
|
|
|
- resultsDiv.innerHTML = '';
|
|
|
-
|
|
|
- if (!results || results.length === 0) {
|
|
|
- resultsDiv.innerHTML = '<p>没有找到匹配的图片</p>';
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- results.forEach(result => {
|
|
|
- const imgUrl = result.rawImage?.url;
|
|
|
- if (imgUrl) {
|
|
|
- const resultCard = document.createElement('div');
|
|
|
- resultCard.className = 'result-card';
|
|
|
-
|
|
|
- // 格式化时间
|
|
|
- const createTime = new Date(result.createTime);
|
|
|
- const formattedTime = createTime.toLocaleString('zh-CN', {
|
|
|
- year: 'numeric',
|
|
|
- month: '2-digit',
|
|
|
- day: '2-digit',
|
|
|
- hour: '2-digit',
|
|
|
- minute: '2-digit'
|
|
|
- });
|
|
|
-
|
|
|
- // 格式化相似度分数
|
|
|
- const score = (result.score * 100).toFixed(2);
|
|
|
-
|
|
|
- resultCard.innerHTML = `
|
|
|
- <img src="${imgUrl}" class="result-image" onerror="this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgZmlsbD0iI2VlZSIvPjx0ZXh0IHg9IjUwJSIgeT0iNTAlIiBmb250LWZhbWlseT0iQXJpYWwiIGZvbnQtc2l6ZT0iMTYiIGZpbGw9IiNhYWEiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGR5PSIuM2VtIj7lm77niYfliqDovb3lpLHotKU8L3RleHQ+PC9zdmc+'" alt="${result.nameCn || '未命名'}">
|
|
|
- <div class="result-info">
|
|
|
- <div><strong>${result.nameCn || '未命名'}</strong></div>
|
|
|
- <div>相似度: <span class="score-badge">${score}%</span></div>
|
|
|
- <div>创建时间: ${formattedTime}</div>
|
|
|
- </div>
|
|
|
- `;
|
|
|
- resultsDiv.appendChild(resultCard);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- </script>
|
|
|
-</body>
|
|
|
-</html>
|