fix: 登录/注册支持 redirect 参数,未登录跳转自动携带来源页

- login.js/register.js 登录成功后优先跳转 redirect 参数指定页面
- 新增 common.RedirectToLogin 辅助函数,自动携带当前路径
- 替换所有 9 处硬编码 /auth/login 重定向
This commit is contained in:
2026-05-31 01:23:09 +08:00
parent 9d84d6bf25
commit a62039e6bb
8 changed files with 39 additions and 15 deletions

View File

@ -15,6 +15,13 @@
if (!loginForm) return;
// 读取 redirect 参数(登录成功后跳转目标)
function getRedirect() {
var m = window.location.search.match(/[?&]redirect=([^&]+)/);
if (m) return decodeURIComponent(m[1]);
return '/';
}
function checkFormValidity() {
var email = emailInput.value.trim();
var password = passwordInput.value;
@ -81,7 +88,7 @@
} else if (xhr.status === 200 && resp && resp.success) {
window.MetaLab.toast(toast, '登录成功', false);
setTimeout(function () {
window.location.href = '/';
window.location.href = getRedirect();
}, 800);
} else {
loginInProgress = false;
@ -112,7 +119,7 @@
if (xhr.status === 200 && resp && resp.success) {
window.MetaLab.toast(toast, resp.message || '账号已恢复,欢迎回来', false);
setTimeout(function () {
window.location.href = '/';
window.location.href = getRedirect();
}, 800);
} else {
loginInProgress = false;