refactor(login): 重构登录页面并优化账号绑定逻辑

- 调整页面布局,使内容居中显示
- 移除不必要的键盘事件监听代码
- 抽离 handleBind 和 processLogin 函数,提高代码复用性
- 修改按钮点击事件处理方式,使用 onclick 属性
This commit is contained in:
2024-12-22 11:45:07 +08:00
parent 7893eade44
commit 1ec871cd90

View File

@@ -162,55 +162,47 @@ function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua =
<meta name="keywords" content="<?= $_CONFIG['game_name'] ?>,<?= $_CONFIG['game_description'] ?>">
<link rel="stylesheet" href="static/css/login.css?v=1.1.6" />
<script>
document.onkeydown = document.onkeyup = document.onkeypress = function (event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && e.keyCode == 123) {
e.returnValue = false;
return false;
}
function handleBind(account, linuxdo_account) {
return fetch("/linuxdo?act=bind&account=" + account + "&connect_id=" + linuxdo_account).then(res => {
const { password } = res.data
location.href = "/play?account=" + document.getElementById("linuxdo").value + "&token=" + password;
})
}
function processLogin(params = {}, connect_id) {
const formData = new FormData();
formData.append("serverId", "1");
Object.entries(params).forEach(([key, value]) => formData.append(key, value));
fetch("/api?act=reg", { method: "POST", body: formData }).then(res => {
if (res.code == '0') {
handleBind(res.data.account, connect_id)
} else {
showTips(res.msg, 6, 'error');
return
})
})
}
function registerDirect() {
const linuxdo_account = document.getElementById("linuxdo").value;
processLogin({ type: "1", account: linuxdo_account, password: "1", password2: "1" }, linuxdo_account)
}
function linkAccount() {
const account = document.getElementById("account").value;
const password = document.getElementById("password").value;
const linuxdo_account = document.getElementById("linuxdo").value;
processLogin({ type: "0", account, password, }, linuxdo_account)
}
</script>
</head>
<body oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
<?php if (empty($row)) { ?>
<div style="width:400px">
<div style="width:400px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);display:flex;justify-content:center;align-items:center;flex-direction:column;">
当前尚未有你的游戏账号,请选择<br>
<a onclick="registerDirect" style="cursor:pointer"><b>Linuxdo账号绑定</b></a></br>
<input type="hidden" id="linuxdo" value="<?= $userInfo['user_username'] ?>">
<script>
function handleBind(account, linuxdo_account) {
return fetch("/linuxdo?act=bind&account=" + account + "&connect_id=" + linuxdo_account).then(res => {
const { password } = res.data
location.href = "/play?account=" + document.getElementById("linuxdo").value + "&token=" + password;
})
}
function processLogin(params = {}, connect_id) {
const formData = new FormData();
formData.append("serverId", "1");
Object.entries(params).forEach(([key, value]) => formData.append(key, value));
fetch("/api?act=reg", { method: "POST", body: formData }).then(res => {
if (res.code == '0') {
handleBind(res.data.account, connect_id)
} else {
showTips(res.msg, 6, 'error');
return
})
})
}
function registerDirect() {
const linuxdo_account = document.getElementById("linuxdo").value;
processLogin({ type: "1", account: linuxdo_account, password: "1", password2: "1" }, linuxdo_account)
}
function linkAccount() {
const account = document.getElementById("account").value;
const password = document.getElementById("password").value;
const linuxdo_account = document.getElementById("linuxdo").value;
processLogin({ type: "0", account, password, }, linuxdo_account)
}
</script>
<br>
如果已有账号,请输入账号和密码<br>
<input type="text" id="account" placeholder="请输入账号" onKeyUp="value = value.replace(/[\W]/g, '')"
@@ -218,7 +210,7 @@ function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua =
<br>
<input type="password" id="password" placeholder="请输入密码">
<br>
<button type="submit" @click="linkAccount">绑定并登录</button>
<button type="submit" onclick="linkAccount">绑定并登录</button>
</div>
<?php } ?>
</body>