<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>充电宝授权程序</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#3B82F6',
secondary: '#10B981',
accent: '#F59E0B',
danger: '#EF4444',
dark: '#1E293B',
light: '#F8FAFC'
},
fontFamily: {
sans: ['Inter', 'system-ui', 'sans-serif'],
},
}
}
}
</script>
<style type="text/tailwindcss">
@layer utilities {
.content-auto {
content-visibility: auto;
}
.animate-pulse-slow {
animation: pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
.bg-gradient-primary {
background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
}
}
</style>
</head>
<body class="bg-gray-50 min-h-screen font-sans">
<!-- 顶部导航 -->
<header class="bg-white shadow-sm sticky top-0 z-50 transition-all duration-300">
<div class="container mx-auto px-4 py-3 flex justify-between items-center">
<div class="flex items-center space-x-2">
<i class="fa fa-battery-full text-primary text-2xl"></i>
<h1 class="text-xl font-bold text-dark">充电宝授权系统</h1>
</div>
<div class="flex items-center space-x-4">
<button id="helpBtn" class="text-gray-600 hover:text-primary transition-colors">
<i class="fa fa-question-circle mr-1"></i>帮助
</button>
<button id="settingsBtn" class="text-gray-600 hover:text-primary transition-colors">
<i class="fa fa-cog mr-1"></i>设置
</button>
</div>
</div>
</header>
<!-- 主内容区 -->
<main class="container mx-auto px-4 py-8 max-w-4xl">
<!-- 状态指示器 -->
<div id="statusBar" class="mb-8 p-4 bg-blue-50 border border-blue-200 rounded-lg hidden">
<div class="flex items-center">
<i id="statusIcon" class="fa fa-info-circle text-primary mr-3"></i>
<p id="statusMessage" class="text-blue-800"></p>
</div>
</div>
<!-- 步骤指示器 -->
<div class="flex justify-between items-center mb-10 relative">
<div class="absolute top-1/2 left-0 right-0 h-1 bg-gray-200 -translate-y-1/2 z-0"></div>
<div class="absolute top-1/2 left-0 h-1 bg-gradient-primary -translate-y-1/2 z-10 transition-all duration-500" id="progressBar" style="width: 0%"></div>
<div class="flex flex-col items-center relative z-20" id="step1">
<div class="w-10 h-10 rounded-full bg-primary text-white flex items-center justify-center mb-2">
<i class="fa fa-user"></i>
</div>
<p class="text-sm font-medium text-primary">用户认证</p>
</div>
<div class="flex flex-col items-center relative z-20" id="step2">
<div class="w-10 h-10 rounded-full bg-gray-300 text-gray-600 flex items-center justify-center mb-2 transition-all duration-300">
<i class="fa fa-mobile"></i>
</div>
<p class="text-sm font-medium text-gray-500 transition-all duration-300">设备识别</p>
</div>
<div class="flex flex-col items-center relative z-20" id="step3">
<div class="w-10 h-10 rounded-full bg-gray-300 text-gray-600 flex items-center justify-center mb-2 transition-all duration-300">
<i class="fa fa-key"></i>
</div>
<p class="text-sm font-medium text-gray-500 transition-all duration-300">获取密钥</p>
</div>
</div>
<!-- 步骤内容 -->
<div class="bg-white rounded-xl shadow-md p-6 transition-all duration-500 transform">
<!-- 步骤1: 用户认证 -->
<div id="step1Content" class="space-y-6">
<div class="text-center mb-6">
<h2 class="text-2xl font-bold text-dark mb-2">用户认证</h2>
<p class="text-gray-500">请输入您的账号信息进行身份验证</p>
</div>
<form id="authForm" class="space-y-4">
<div>
<label for="username" class="block text-sm font-medium text-gray-700 mb-1">用户名</label>
<div class="relative">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<i class="fa fa-user text-gray-400"></i>
</div>
<input type="text" id="username" name="username" required
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-primary transition-all"
placeholder="请输入用户名">
</div>
</div>
<div>
<label for="password" class="block text-sm font-medium text-gray-700 mb-1">密码</label>
<div class="relative">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<i class="fa fa-lock text-gray-400"></i>
</div>
<input type="password" id="password" name="password" required
class="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-primary transition-all"
placeholder="请输入密码">
<button type="button" id="togglePassword" class="absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600">
<i class="fa fa-eye-slash"></i>
</button>
</div>
</div>
<div class="flex items-center">
<input type="checkbox" id="rememberMe" name="rememberMe"
class="w-4 h-4 text-primary border-gray-300 rounded focus:ring-primary">
<label for="rememberMe" class="ml-2 block text-sm text-gray-700">记住我的登录状态</label>
</div>
<button type="submit" id="authSubmit"
class="w-full bg-gradient-primary text-white py-3 px-4 rounded-lg font-medium hover:opacity-90 transition-opacity flex items-center justify-center">
<span>验证身份</span>
<i class="fa fa-arrow-right ml-2"></i>
</button>
</form>
<div class="text-center text-sm text-gray-500">
<p>还没有账号? <a href="#" class="text-primary hover:underline">立即注册</a></p>
<p class="mt-2"><a href="#" class="text-primary hover:underline">忘记密码?</a></p>
</div>
</div>
<!-- 步骤2: 设备识别 -->
<div id="step2Content" class="space-y-6 hidden">
<div class="text-center mb-6">
<h2 class="text-2xl font-bold text-dark mb-2">设备识别</h2>
<p class="text-gray-500">请连接充电宝设备并完成识别</p>
</div>
<div class="text-center py-6">
<div id="deviceIconContainer" class="w-32 h-32 mx-auto mb-4 bg-gray-100 rounded-full flex items-center justify-center">
<i class="fa fa-battery-three-quarters text-5xl text-gray-400"></i>
</div>
<p id="deviceStatus" class="text-gray-600 mb-4">等待连接设备...</p>
<div id="connectionProgress" class="w-full bg-gray-200 rounded-full h-2.5 mb-4 hidden">
<div id="connectionProgressBar" class="bg-secondary h-2.5 rounded-full transition-all duration-300" style="width: 0%"></div>
</div>
</div>
<div id="deviceInfo" class="p-4 bg-gray-50 rounded-lg border border-gray-200 hidden">
<h3 class="font-medium text-dark mb-2">设备信息</h3>
<div class="grid grid-cols-2 gap-4 text-sm">
<div>
<p class="text-gray-500">设备型号</p>
<p id="deviceModel" class="font-medium">--</p>
</div>
<div>
<p class="text-gray-500">序列号</p>
<p id="deviceSerial" class="font-medium">--</p>
</div>
<div>
<p class="text-gray-500">固件版本</p>
<p id="deviceFirmware" class="font-medium">--</p>
</div>
<div>
<p class="text-gray-500">电池状态</p>
<p id="deviceBattery" class="font-medium">--</p>
</div>
</div>
</div>
<div class="flex space-x-4 pt-4">
<button id="backToStep1" class="flex-1 bg-gray-200 text-gray-700 py-3 px-4 rounded-lg font-medium hover:bg-gray-300 transition-colors">
<i class="fa fa-arrow-left mr-2"></i>
<span>返回</span>
</button>
<button id="identifyDevice" class="flex-1 bg-secondary text-white py-3 px-4 rounded-lg font-medium hover:bg-green-600 transition-colors">
<span>确认设备</span>
<i class="fa fa-check ml-2"></i>
</button>
</div>
</div>
<!-- 步骤3: 获取密钥 -->
<div id="step3Content" class="space-y-6 hidden">
<div class="text-center mb-6">
<h2 class="text-2xl font-bold text-dark mb-2">获取信息密钥</h2>
<p class="text-gray-500">正在为您的设备生成访问密钥</p>
</div>
<div id="keyGeneration" class="text-center py-8">
<div class="inline-block p-4 rounded-full bg-blue-50 mb-6">
<i class="fa fa-key text-4xl text-primary animate-pulse-slow"></i>
</div>
<p class="text-gray-600 mb-4">正在生成密钥...</p>
<div class="w-full bg-gray-200 rounded-full h-2.5 mb-4">
<div id="keyProgressBar" class="bg-primary h-2.5 rounded-full transition-all duration-300" style="width: 0%"></div>
</div>
<p id="keyProgressText" class="text-sm text-gray-500">处理中,请稍候...</p>
</div>
<div id="keyResult" class="p-6 bg-gray-50 rounded-lg border border-gray-200 hidden">
<div class="flex items-start justify-between mb-4">
<div>
<h3 class="font-medium text-dark">信息密钥</h3>
<p class="text-sm text-gray-500">此密钥用于访问充电宝的信息接口</p>
</div>
<span class="px-2 py-1 bg-green-100 text-green-800 text-xs font-medium rounded-full">
已生成
</span>
</div>
<div class="relative mb-4">
<div id="keyValue" class="bg-white p-4 rounded-lg border border-gray-200 font-mono text-sm break-all select-all">
-- 密钥将显示在这里 --
</div>
<button id="copyKey" class="absolute top-2 right-2 bg-gray-100 hover:bg-gray-200 text-gray-700 p-1.5 rounded transition-colors">
<i class="fa fa-copy"></i>
</button>
</div>
<div class="text-sm text-gray-500 space-y-2">
<p><i class="fa fa-info-circle text-primary mr-1"></i> 密钥有效期为7天,请妥善保管</p>
<p><i class="fa fa-exclamation-circle text-accent mr-1"></i> 请勿向他人泄露您的密钥</p>
</div>
</div>
<div class="flex space-x-4 pt-4">
<button id="backToStep2" class="flex-1 bg-gray-200 text-gray-700 py-3 px-4 rounded-lg font-medium hover:bg-gray-300 transition-colors">
<i class="fa fa-arrow-left mr-2"></i>
<span>返回</span>
</button>
<button id="finishProcess" class="flex-1 bg-gradient-primary text-white py-3 px-4 rounded-lg font-medium hover:opacity-90 transition-opacity">
<span>完成</span>
<i class="fa fa-check ml-2"></i>
</button>
</div>
</div>
</div>
</main>
<!-- 帮助模态框 -->
<div id="helpModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-xl max-w-md w-full max-h-[80vh] overflow-y-auto m-4">
<div class="p-6 border-b border-gray-200">
<div class="flex justify-between items-center">
<h3 class="text-xl font-bold text-dark">使用帮助</h3>
<button id="closeHelp" class="text-gray-500 hover:text-gray-700">
<i class="fa fa-times"></i>
</button>
</div>
</div>
<div class="p-6 space-y-4">
<div>
<h4 class="font-medium text-dark mb-2">如何获取充电宝信息密钥?</h4>
<ol class="list-decimal pl-5 text-gray-600 space-y-2 text-sm">
<li>输入您的账号信息进行身份验证</li>
<li>将充电宝连接到设备并完成识别</li>
<li>系统将自动生成信息密钥</li>
<li>复制密钥用于访问充电宝的信息接口</li>
</ol>
</div>
<div>
<h4 class="font-medium text-dark mb-2">密钥有效期是多久?</h4>
<p class="text-gray-600 text-sm">每个生成的密钥有效期为7天,过期后需要重新生成。</p>
</div>
<div>
<h4 class="font-medium text-dark mb-2">遇到问题?</h4>
<p class="text-gray-600 text-sm">请联系客服热线:400-123-4567 或发送邮件至 support@powerbank.com</p>
</div>
</div>
</div>
</div>
<!-- 底部信息 -->
<footer class="bg-white border-t border-gray-200 mt-12 py-6">
<div class="container mx-auto px-4 text-center text-gray-500 text-sm">
<p>© 2023 充电宝授权系统 版权所有</p>
<p class="mt-1">版本 v1.0.0</p>
</div>
</footer>
<script>
// DOM 元素
const step1 = document.getElementById('step1');
const step2 = document.getElementById('step2');
const step3 = document.getElementById('step3');
const step1Content = document.getElementById('step1Content');
const step2Content = document.getElementById('step2Content');
const step3Content = document.getElementById('step3Content');
const progressBar = document.getElementById('progressBar');
const authForm = document.getElementById('authForm');
const togglePassword = document.getElementById('togglePassword');
const passwordInput = document.getElementById('password');
const backToStep1 = document.getElementById('backToStep1');
const backToStep2 = document.getElementById('backToStep2');
const identifyDevice = document.getElementById('identifyDevice');
const deviceStatus = document.getElementById('deviceStatus');
const deviceInfo = document.getElementById('deviceInfo');
const connectionProgress = document.getElementById('connectionProgress');
const connectionProgressBar = document.getElementById('connectionProgressBar');
const deviceModel = document.getElementById('deviceModel');
const deviceSerial = document.getElementById('deviceSerial');
const deviceFirmware = document.getElementById('deviceFirmware');
const deviceBattery = document.getElementById('deviceBattery');
const keyProgressBar = document.getElementById('keyProgressBar');
const keyProgressText = document.getElementById('keyProgressText');
const keyGeneration = document.getElementById('keyGeneration');
const keyResult = document.getElementById('keyResult');
const keyValue = document.getElementById('keyValue');
const copyKey = document.getElementById('copyKey');
const finishProcess = document.getElementById('finishProcess');
const helpBtn = document.getElementById('helpBtn');
const helpModal = document.getElementById('helpModal');
const closeHelp = document.getElementById('closeHelp');
const statusBar = document.getElementById('statusBar');
const statusIcon = document.getElementById('statusIcon');
const statusMessage = document.getElementById('statusMessage');
// 显示状态消息
function showStatus(message, isError = false) {
statusMessage.textContent = message;
statusIcon.className = isError ? 'fa fa-exclamation-circle text-danger mr-3' : 'fa fa-info-circle text-primary mr-3';
statusBar.className = isError ? 'mb-8 p-4 bg-red-50 border border-red-200 rounded-lg' : 'mb-8 p-4 bg-blue-50 border border-blue-200 rounded-lg';
statusBar.classList.remove('hidden');
// 3秒后自动隐藏
setTimeout(() => {
statusBar.classList.add('hidden');
}, 3000);
}
// 切换密码可见性
togglePassword.addEventListener('click', () => {
const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
passwordInput.setAttribute('type', type);
togglePassword.querySelector('i').classList.toggle('fa-eye');
togglePassword.querySelector('i').classList.toggle('fa-eye-slash');
});
// 步骤1表单提交
authForm.addEventListener('submit', (e) => {
e.preventDefault();
const username = document.getElementById('username').value;
const password = passwordInput.value;
if (!username || !password) {
showStatus('请输入用户名和密码', true);
return;
}
// 模拟认证过程
const submitBtn = document.getElementById('authSubmit');
const originalText = submitBtn.innerHTML;
submitBtn.disabled = true;
submitBtn.innerHTML = '<i class="fa fa-spinner fa-spin mr-2"></i>验证中...';
setTimeout(() => {
// 模拟认证成功
goToStep(2);
submitBtn.disabled = false;
submitBtn.innerHTML = originalText;
showStatus('身份验证成功,正在进入设备识别阶段');
}, 1500);
});
// 切换到指定步骤
function goToStep(step) {
// 隐藏所有步骤内容
step1Content.classList.add('hidden');
step2Content.classList.add('hidden');
step3Content.classList.add('hidden');
// 重置所有步骤样式
[step1, step2, step3].forEach(el => {
el.querySelector('div').classList.remove('bg-primary', 'text-white');
el.querySelector('div').classList.add('bg-gray-300', 'text-gray-600');
el.querySelector('p').classList.remove('text-primary');
el.querySelector('p').classList.add('text-gray-500');
});
// 设置当前步骤样式
if (step >= 1) {
step1.querySelector('div').classList.remove('bg-gray-300', 'text-gray-600');
step1.querySelector('div').classList.add('bg-primary', 'text-white');
step1.querySelector('p').classList.remove('text-gray-500');
step1.querySelector('p').classList.add('text-primary');
}
if (step >= 2) {
step2.querySelector('div').classList.remove('bg-gray-300', 'text-gray-600');
step2.querySelector('div').classList.add('bg-primary', 'text-white');
step2.querySelector('p').classList.remove('text-gray-500');
step2.querySelector('p').classList.add('text-primary');
}
if (step >= 3) {
step3.querySelector('div').classList.remove('bg-gray-300', 'text-gray-600');
step3.querySelector('div').classList.add('bg-primary', 'text-white');
step3.querySelector('p').classList.remove('text-gray-500');
step3.querySelector('p').classList.add('text-primary');
}
// 更新进度条
progressBar.style.width = `${(step - 1) * 50}%`;
// 显示当前步骤内容
if (step === 1) step1Content.classList.remove('hidden');
if (step === 2) step2Content.classList.remove('hidden');
if (step === 3) step3Content.classList.remove('hidden');
}
// 返回步骤1
backToStep1.addEventListener('click', () => {
goToStep(1);
});
// 返回步骤2
backToStep2.addEventListener('click', () => {
goToStep(2);
});
// 识别设备
identifyDevice.addEventListener('click', () => {
// 模拟设备连接过程
identifyDevice.disabled = true;
identifyDevice.innerHTML = '<i class="fa fa-spinner fa-spin mr-2"></i>识别中...';
deviceStatus.textContent = '正在识别设备...';
connectionProgress.classList.remove('hidden');
let progress = 0;
const progressInterval = setInterval(() => {
progress += 5;
connectionProgressBar.style.width = `${progress}%`;
if (progress >= 100) {
clearInterval(progressInterval);
// 显示设备信息
deviceModel.textContent = 'PowerBank Pro X10';
deviceSerial.textContent = 'PB202305120045';
deviceFirmware.textContent = 'v2.3.1';
deviceBattery.textContent = '87%';
deviceStatus.textContent = '设备识别成功';
deviceInfo.classList.remove('hidden');
// 延迟进入下一步
setTimeout(() => {
goToStep(3);
identifyDevice.disabled = false;
identifyDevice.innerHTML = '<span>确认设备</span><i class="fa fa-check ml-2"></i>';
generateKey();
showStatus('设备识别成功,正在生成信息密钥');
}, 1000);
}
}, 100);
});
// 生成密钥
function generateKey() {
let progress = 0;
const progressInterval = setInterval(() => {
progress += 5;
keyProgressBar.style.width = `${progress}%`;
if (progress <= 30) {
keyProgressText.textContent = '正在验证设备权限...';
} else if (progress <= 60) {
keyProgressText.textContent = '正在生成加密密钥...';
} else if (progress <= 90) {
keyProgressText.textContent = '正在完成密钥配置...';
} else {
keyProgressText.textContent = '密钥生成完成';
}
if (progress >= 100) {
clearInterval(progressInterval);
// 生成随机密钥
const key = generateRandomKey();
keyValue.textContent = key;
// 显示结果
setTimeout(() => {
keyGeneration.classList.add('hidden');
keyResult.classList.remove('hidden');
}, 500);
}
}, 150);
}
// 生成随机密钥
function generateRandomKey() {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let key = '';
for (let i = 0; i < 32; i++) {
key += chars.charAt(Math.floor(Math.random() * chars.length));
if ((i + 1) % 8 === 0 && i !== 31) {
key += '-';
}
}
return key;
}
// 复制密钥
copyKey.addEventListener('click', () => {
const key = keyValue.textContent;
navigator.clipboard.writeText(key).then(() => {
const originalIcon = copyKey.innerHTML;
copyKey.innerHTML = '<i class="fa fa-check"></i>';
setTimeout(() => {
copyKey.innerHTML = originalIcon;
}, 2000);
showStatus('密钥已复制到剪贴板');
}).catch(err => {
showStatus('复制失败,请手动复制', true);
console.error('复制失败:', err);
});
});
// 完成流程
finishProcess.addEventListener('click', () => {
if (confirm('操作已完成,是否返回初始页面?')) {
// 重置所有状态
goToStep(1);
authForm.reset();
passwordInput.setAttribute('type', 'password');
togglePassword.querySelector('i').classList.remove('fa-eye');
togglePassword.querySelector('i').classList.add('fa-eye-slash');
deviceInfo.classList.add('hidden');
connectionProgress.classList.add('hidden');
connectionProgressBar.style.width = '0%';
keyGeneration.classList.remove('hidden');
keyResult.classList.add('hidden');
keyProgressBar.style.width = '0%';
keyProgressText.textContent = '处理中,请稍候...';
showStatus('已返回初始页面,可以开始新的授权流程');
}
});
// 帮助模态框
helpBtn.addEventListener('click', () => {
helpModal.classList.remove('hidden');
});
closeHelp.addEventListener('click', () => {
helpModal.classList.add('hidden');
});
// 点击模态框外部关闭
helpModal.addEventListener('click', (e) => {
if (e.target === helpModal) {
helpModal.classList.add('hidden');
}
});
// 初始化页面
document.addEventListener('DOMContentLoaded', () => {
goToStep(1);
});
</script>
</body>
</html>