61 lines
2.5 KiB
HTML
61 lines
2.5 KiB
HTML
<div class="max-w-2xl mx-auto">
|
|
<div class="flex items-center mb-6">
|
|
<a href="/admin/robots" class="text-indigo-600 hover:text-indigo-800 mr-4">
|
|
<i class="fas fa-arrow-left"></i>
|
|
</a>
|
|
<h1 class="text-2xl font-bold text-gray-800">微信登录</h1>
|
|
</div>
|
|
|
|
<div class="bg-white rounded-lg shadow-md p-6">
|
|
<div class="flex justify-center mb-6">
|
|
<img src="{{.QRCode}}" alt="登录二维码" class="w-64 h-64">
|
|
</div>
|
|
<div id="status-message" class="text-sm font-medium text-gray-600 mb-6">
|
|
请扫描二维码登录...
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// 周期性检查登录状态
|
|
let checkLoginStatus = function() {
|
|
fetch(`/api/robots/{{.Robot.ID}}/status`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const statusMsg = document.getElementById('status-message');
|
|
|
|
if (data.success) {
|
|
if (data.data.status === 'online') {
|
|
statusMsg.textContent = '登录成功!正在跳转...';
|
|
statusMsg.className = 'text-sm font-medium text-green-600 mb-6';
|
|
|
|
// 登录成功后跳转
|
|
setTimeout(() => {
|
|
window.location.href = '/admin/robots/{{.Robot.ID}}/contacts';
|
|
}, 2000);
|
|
} else if (data.data.status === 'error') {
|
|
statusMsg.textContent = '发生错误:' + data.data.robot.error_message;
|
|
statusMsg.className = 'text-sm font-medium text-red-600 mb-6';
|
|
} else {
|
|
statusMsg.textContent = '请扫描二维码登录...';
|
|
statusMsg.className = 'text-sm font-medium text-gray-600 mb-6';
|
|
}
|
|
} else {
|
|
statusMsg.textContent = '状态检查失败,请刷新页面';
|
|
statusMsg.className = 'text-sm font-medium text-red-600 mb-6';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error checking status:', error);
|
|
});
|
|
};
|
|
|
|
// 页面加载后开始检查登录状态
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// 立即检查一次
|
|
checkLoginStatus();
|
|
|
|
// 然后每3秒检查一次
|
|
setInterval(checkLoginStatus, 3000);
|
|
});
|
|
</script> |