wx-login/mini-web/envision/callback.html
2025-02-28 03:05:52 +08:00

70 lines
1.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1, user-scalable=no">
<title>登录中转</title>
<style>
* {
box-sizing: border-box;
}
</style>
<style>
.loading {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.8);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5em;
/* Adjust font size for mobile */
}
@media (max-width: 600px) {
.loading {
font-size: 1em;
/* Smaller font size for smaller screens */
}
}
</style>
</head>
<body>
<div class="loading">Loading Code...</div>
<script type="module">
import { loginSuccessUrl } from './config.js';
const url = new URL(window.location.href);
const state = url.searchParams.get('state');
const code = url.searchParams.get('code');
// document.body.append(state + '-----------');
// document.body.append(code);
const orgin = url.origin;
const res = await fetch(`${orgin}/api/router?path=wx&key=mplogin&state=${state}&code=${code}`)
.then(res => res.json()).catch(err => {
console.error(err);
alert('登录失败,请稍后再试');
document.body.append('登录失败,请稍后再试');
setTimeout(() => {
window.close();
}, 2000);
});
// document.body.append(JSON.stringify(res, null, 2));
if (res.code === 200) {
localStorage.setItem('token', res.data.token);
window.close()
setTimeout(() => {
window.open(loginSuccessUrl, '_blank');
}, 1000);
}
</script>
</body>
</html>