feat: add configurable delayed password relogin
This commit is contained in:
@@ -15,6 +15,11 @@ class LoginPage {
|
||||
constructor(host, page) {
|
||||
this.page = page;
|
||||
this.root = el('div', {class: 'login-layout'});
|
||||
this.autoReloginMessage = el('p', {role: 'status'});
|
||||
this.autoReloginCountdown = el('p', {'data-auto-relogin-countdown': '', role: 'timer', 'aria-live': 'off', hidden: true});
|
||||
this.autoReloginCredentials = el('p', {'data-auto-relogin-credentials': '', role: 'status', hidden: true,
|
||||
text: '缺少服务端记住的账号和密码。请勾选“记住账号和密码”并完成登录,才能自动重登原区服角色。'});
|
||||
this.autoReloginStatus = el('div', {class: 'page-summary', 'data-auto-relogin-status': ''}, this.autoReloginMessage, this.autoReloginCountdown, this.autoReloginCredentials);
|
||||
this.account = el('input', {type: 'text', name: 'game-account', autocomplete: 'username', 'aria-label': '游戏账号'});
|
||||
this.password = el('input', {type: 'password', name: 'game-password', autocomplete: 'current-password', 'aria-label': '游戏密码'});
|
||||
this.remember = el('input', {type: 'checkbox', checked: true});
|
||||
@@ -48,17 +53,36 @@ class LoginPage {
|
||||
el('div', {class: 'page-toolbar'}, el('button', {type: 'button', text: '退出登录', onClick: () => page.perform('logout').catch(page.error)}),
|
||||
el('button', {type: 'button', text: '退出并清除登录记录…', onClick: () => page.options.command('forget-login', page.account)})),
|
||||
el('p', {class: 'info-note', text: '记住的账号密码和登录会话由服务端加密保存。浏览器不会保存游戏凭据。退出或恢复会话后,策略保持关闭。'}));
|
||||
host.append(this.root);
|
||||
host.append(this.autoReloginStatus, this.root);
|
||||
}
|
||||
|
||||
update(data) {
|
||||
const login = data.login || data.details?.login || data;
|
||||
if (login.account && !this.account.value && document.activeElement !== this.account) this.account.value = login.account;
|
||||
if (login.has_saved_password !== undefined) this.password.placeholder = login.has_saved_password ? '已在服务端加密保存;留空使用已保存密码' : '输入游戏密码';
|
||||
if (login.has_saved_password !== undefined) {
|
||||
this.hasSavedPassword = login.has_saved_password;
|
||||
this.password.placeholder = login.has_saved_password ? '已在服务端加密保存;留空使用已保存密码' : '输入游戏密码';
|
||||
}
|
||||
if (Array.isArray(login.servers)) this.updateOptions(this.servers, login.servers.map(server => ({value: server.id ?? server.server_id, label: `${server.name}${server.role_name ? ` · ${server.role_name}` : ''}`})), '请先获取区服');
|
||||
if (Array.isArray(login.saved_sessions)) this.updateOptions(this.saved, login.saved_sessions.map(session => ({value: session.id ?? session.session_id, label: session.label || [session.account, session.server_name || session.server, session.role_name || session.name].filter(Boolean).join(' · ')})), '暂无已保存会话');
|
||||
this.enter.disabled = !this.servers.value;
|
||||
this.restore.disabled = !this.saved.value;
|
||||
this.updateStatus();
|
||||
}
|
||||
|
||||
updateStatus() {
|
||||
const enabled = this.page.account.config?.auto_relogin?.enabled === true;
|
||||
const status = this.page.account.summary?.auto_relogin_status;
|
||||
const message = status?.message || (enabled ? '自动重登已开启,等待服务端状态。' : '自动重登未开启。');
|
||||
if (this.autoReloginMessage.textContent !== message) this.autoReloginMessage.textContent = message;
|
||||
this.autoReloginCredentials.hidden = !enabled || this.hasSavedPassword !== false;
|
||||
const attemptAt = typeof status?.next_attempt_at === 'string' ? Date.parse(status.next_attempt_at) : NaN;
|
||||
this.autoReloginCountdown.hidden = !enabled || !Number.isFinite(attemptAt);
|
||||
if (!this.autoReloginCountdown.hidden) {
|
||||
const remaining = Math.max(0, Math.ceil((attemptAt - Date.now()) / 1000));
|
||||
const countdown = remaining ? `${remaining} 秒后自动重新登录(${chinaTime(status.next_attempt_at, {date: true})},北京时间)` : '等待服务端执行自动重登';
|
||||
if (this.autoReloginCountdown.textContent !== countdown) this.autoReloginCountdown.textContent = countdown;
|
||||
}
|
||||
}
|
||||
|
||||
updateOptions(select, options, placeholder) {
|
||||
|
||||
Reference in New Issue
Block a user