mirror of
https://github.com/justhtmls/html-tools.git
synced 2026-11-27 20:42:02 +08:00
338 lines
10 KiB
HTML
338 lines
10 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<link rel="icon" href="../../favicon.svg">
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>二维码解码器</title>
|
|
<link rel="canonical" href="https://www.htmls.dev/tools/qr-decoder/app.html">
|
|
<script src="https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.js" onerror="this.onerror=null;this.src='../../assets/vendor/jsqr/jsQR.min.js';"></script>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
|
color: #eee;
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 900px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.header {
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 2rem;
|
|
background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
background-clip: text;
|
|
}
|
|
|
|
.main-content {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 30px;
|
|
align-items: start;
|
|
}
|
|
|
|
.upload-section {
|
|
background: rgba(30, 30, 50, 0.8);
|
|
border-radius: 12px;
|
|
padding: 24px;
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.upload-area {
|
|
border: 2px dashed rgba(139, 92, 246, 0.5);
|
|
border-radius: 12px;
|
|
padding: 40px;
|
|
text-align: center;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.upload-area:hover, .upload-area.dragover {
|
|
border-color: #8b5cf6;
|
|
background: rgba(139, 92, 246, 0.1);
|
|
}
|
|
|
|
.upload-area i {
|
|
font-size: 48px;
|
|
color: #8b5cf6;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.upload-area p {
|
|
color: #888;
|
|
margin: 8px 0;
|
|
}
|
|
|
|
.upload-area input {
|
|
display: none;
|
|
}
|
|
|
|
.preview-section {
|
|
background: rgba(30, 30, 50, 0.8);
|
|
border-radius: 12px;
|
|
padding: 24px;
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.preview-image {
|
|
width: 100%;
|
|
max-width: 300px;
|
|
margin: 0 auto 20px;
|
|
display: block;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.result-section {
|
|
margin-top: 20px;
|
|
padding: 20px;
|
|
background: rgba(0, 0, 0, 0.3);
|
|
border-radius: 8px;
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.result-label {
|
|
color: #888;
|
|
font-size: 14px;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.result-content {
|
|
word-break: break-all;
|
|
padding: 12px;
|
|
background: rgba(0, 0, 0, 0.5);
|
|
border-radius: 6px;
|
|
font-family: monospace;
|
|
font-size: 14px;
|
|
max-height: 200px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.btn {
|
|
padding: 12px 24px;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
margin-top: 16px;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, #8b5cf6, #6366f1);
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
|
|
}
|
|
|
|
.btn:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.error-msg {
|
|
color: #ef4444;
|
|
background: rgba(239, 68, 68, 0.1);
|
|
padding: 12px;
|
|
border-radius: 6px;
|
|
margin-top: 16px;
|
|
display: none;
|
|
}
|
|
|
|
.error-msg.active {
|
|
display: block;
|
|
}
|
|
|
|
.tool-doc-link,
|
|
.tool-home-link {
|
|
position: fixed;
|
|
top: 16px;
|
|
padding: 6px 12px;
|
|
border-radius: 999px;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
color: #0f172a;
|
|
background: rgba(255, 255, 255, 0.9);
|
|
border: 1px solid rgba(15, 23, 42, 0.12);
|
|
text-decoration: none;
|
|
letter-spacing: 0.02em;
|
|
z-index: 9999;
|
|
box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
|
|
transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
|
|
}
|
|
|
|
.tool-doc-link {
|
|
right: 16px;
|
|
}
|
|
|
|
.tool-home-link {
|
|
right: 74px;
|
|
}
|
|
|
|
.tool-doc-link:hover,
|
|
.tool-home-link:hover {
|
|
background: rgba(255, 255, 255, 1);
|
|
border-color: rgba(15, 23, 42, 0.2);
|
|
transform: translateY(-1px);
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.main-content {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<a class="tool-home-link" href="../../index.html">首页</a>
|
|
<a class="tool-doc-link" href="index.html">说明</a>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>二维码解码器</h1>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<div class="upload-section">
|
|
<div class="upload-area" id="upload-area">
|
|
<input type="file" id="file-input" accept="image/*">
|
|
<i class="fas fa-upload"></i>
|
|
<p><strong>点击上传或拖拽图片</strong></p>
|
|
<p style="font-size: 12px; color: #666;">支持 PNG、JPG、JPEG 格式</p>
|
|
</div>
|
|
<img id="preview-img" class="preview-image" style="display: none;" alt="预览">
|
|
</div>
|
|
|
|
<div class="preview-section">
|
|
<div class="result-section" id="result-section" style="display: none;">
|
|
<div class="result-label">解码结果:</div>
|
|
<div class="result-content" id="result-content"></div>
|
|
<button class="btn btn-primary" onclick="copyResult()" id="copy-btn">
|
|
<i class="fas fa-copy"></i> 复制结果
|
|
</button>
|
|
</div>
|
|
<div class="error-msg" id="error-msg"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const uploadArea = document.getElementById('upload-area');
|
|
const fileInput = document.getElementById('file-input');
|
|
const previewImg = document.getElementById('preview-img');
|
|
const resultSection = document.getElementById('result-section');
|
|
const resultContent = document.getElementById('result-content');
|
|
const errorMsg = document.getElementById('error-msg');
|
|
let decodedText = '';
|
|
|
|
uploadArea.addEventListener('click', () => fileInput.click());
|
|
|
|
fileInput.addEventListener('change', (e) => {
|
|
if (e.target.files[0]) {
|
|
handleFile(e.target.files[0]);
|
|
}
|
|
});
|
|
|
|
uploadArea.addEventListener('dragover', (e) => {
|
|
e.preventDefault();
|
|
uploadArea.classList.add('dragover');
|
|
});
|
|
|
|
uploadArea.addEventListener('dragleave', () => {
|
|
uploadArea.classList.remove('dragover');
|
|
});
|
|
|
|
uploadArea.addEventListener('drop', (e) => {
|
|
e.preventDefault();
|
|
uploadArea.classList.remove('dragover');
|
|
if (e.dataTransfer.files[0]) {
|
|
handleFile(e.dataTransfer.files[0]);
|
|
}
|
|
});
|
|
|
|
function handleFile(file) {
|
|
if (!file.type.startsWith('image/')) {
|
|
showError('请上传图片文件');
|
|
return;
|
|
}
|
|
|
|
const reader = new FileReader();
|
|
reader.onload = (e) => {
|
|
previewImg.src = e.target.result;
|
|
previewImg.style.display = 'block';
|
|
decodeQRCode(e.target.result);
|
|
};
|
|
reader.readAsDataURL(file);
|
|
}
|
|
|
|
function decodeQRCode(imageSrc) {
|
|
errorMsg.classList.remove('active');
|
|
resultSection.style.display = 'none';
|
|
|
|
const img = new Image();
|
|
img.onload = () => {
|
|
const canvas = document.createElement('canvas');
|
|
const ctx = canvas.getContext('2d');
|
|
canvas.width = img.width;
|
|
canvas.height = img.height;
|
|
ctx.drawImage(img, 0, 0);
|
|
|
|
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
const code = jsQR(imageData.data, imageData.width, imageData.height);
|
|
|
|
if (code) {
|
|
decodedText = code.data;
|
|
resultContent.textContent = decodedText;
|
|
resultSection.style.display = 'block';
|
|
} else {
|
|
showError('未能识别二维码,请确保图片清晰且包含完整的二维码');
|
|
}
|
|
};
|
|
img.src = imageSrc;
|
|
}
|
|
|
|
function copyResult() {
|
|
if (decodedText) {
|
|
navigator.clipboard.writeText(decodedText).then(() => {
|
|
const btn = document.getElementById('copy-btn');
|
|
const original = btn.innerHTML;
|
|
btn.innerHTML = '<i class="fas fa-check"></i> 已复制!';
|
|
setTimeout(() => {
|
|
btn.innerHTML = original;
|
|
}, 2000);
|
|
});
|
|
}
|
|
}
|
|
|
|
function showError(message) {
|
|
errorMsg.textContent = message;
|
|
errorMsg.classList.add('active');
|
|
}
|
|
</script>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" onerror="this.onerror=null;this.href='../../assets/vendor/fontawesome/css/all.min.css';">
|
|
<script src="../../assets/clicks.js" defer></script>
|
|
</body>
|
|
</html>
|