feat: add 新增验证码登录
This commit is contained in:
@@ -560,6 +560,14 @@
|
||||
<option value="mac">Mac</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="verify-code">手机验证码(收到后填写)</label>
|
||||
<input
|
||||
id="verify-code"
|
||||
placeholder="例如:123456"
|
||||
autocomplete="off"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
@@ -578,6 +586,9 @@
|
||||
<button class="secondary" id="btn-online">
|
||||
获取在线状态
|
||||
</button>
|
||||
<button class="secondary" id="btn-verify-code">
|
||||
验证验证码
|
||||
</button>
|
||||
<button class="danger" id="btn-logout">
|
||||
退出当前账号
|
||||
</button>
|
||||
@@ -760,6 +771,8 @@
|
||||
if (btnWake) btnWake.disabled = loading;
|
||||
$('btn-check-scan').disabled = loading;
|
||||
$('btn-online').disabled = loading;
|
||||
var btnVerifyCode = $('btn-verify-code');
|
||||
if (btnVerifyCode) btnVerifyCode.disabled = loading;
|
||||
$('btn-logout').disabled = loading;
|
||||
}
|
||||
|
||||
@@ -1207,6 +1220,34 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function onVerifyCode() {
|
||||
const payload = getCommonPayload();
|
||||
if (!payload) return;
|
||||
const code = (($('verify-code') && $('verify-code').value) || '').trim();
|
||||
if (!code) {
|
||||
alert('请先填写手机上的验证码');
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
log('正在提交验证码验证...');
|
||||
const data = await callApi('/auth/verify-code', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
key: payload.key,
|
||||
code,
|
||||
}),
|
||||
});
|
||||
log('验证码验证结果: ' + JSON.stringify(data), 'ok');
|
||||
updateLoginState('验证码已提交', 'pending', '请稍后点击「获取在线状态」确认是否已登录');
|
||||
} catch (e) {
|
||||
log('验证码验证失败: ' + (e.message || e), 'error');
|
||||
updateLoginState('验证码验证失败', 'offline', e.message || '');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function onLogout() {
|
||||
const payload = getCommonPayload();
|
||||
if (!payload) return;
|
||||
@@ -1262,6 +1303,10 @@
|
||||
e.preventDefault();
|
||||
onGetOnlineStatus();
|
||||
});
|
||||
$('btn-verify-code') && $('btn-verify-code').addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
onVerifyCode();
|
||||
});
|
||||
$('btn-logout').addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
onLogout();
|
||||
|
||||
Reference in New Issue
Block a user