进行了一些小优化
This commit is contained in:
1 parent
10b3e6dd9f
commit
f5c60cd425
5 files changed
+127
-24
No files matched your search
+13
-13
@@ -36,7 +36,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
function showToast(text, type) {
|
||||
function notify(text, type) {
|
||||
if (!text) return;
|
||||
window.notyf(escapeHtml(text), type || 'info');
|
||||
}
|
||||
@@ -69,7 +69,7 @@
|
||||
box.dataset.loading = '0';
|
||||
box.dataset.loaded = '0';
|
||||
box.innerHTML = '<button type="button" data-auth-refresh-qr>二维码加载失败,点击重试</button>';
|
||||
showToast(error.message, 'danger');
|
||||
notify(error.message, 'danger');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -78,14 +78,14 @@
|
||||
window.setTimeout(function () {
|
||||
request('check-qrcode-login', { token: token }).then(function (result) {
|
||||
if (result.logged_in) {
|
||||
showToast('登录成功', 'success');
|
||||
notify('登录成功', 'success');
|
||||
window.location.assign(result.redirect || window.location.href);
|
||||
return;
|
||||
}
|
||||
if (result.status === 'expired') {
|
||||
box.dataset.loaded = '0';
|
||||
box.innerHTML = '<button type="button" data-auth-refresh-qr>二维码已过期,点击刷新</button>';
|
||||
showToast('二维码已过期,请刷新后重试', 'warning');
|
||||
notify('二维码已过期,请刷新后重试', 'warning');
|
||||
return;
|
||||
}
|
||||
pollQr(box, token, count + 1);
|
||||
@@ -98,11 +98,11 @@
|
||||
var button = form.querySelector('button[type="submit"]');
|
||||
if (button) button.disabled = true;
|
||||
request('weixingzh-code', data).then(function (result) {
|
||||
showToast('登录成功', 'success');
|
||||
notify('登录成功', 'success');
|
||||
window.location.assign(result.redirect || window.location.href);
|
||||
}).catch(function (error) {
|
||||
if (button) button.disabled = false;
|
||||
showToast(error.message, 'danger');
|
||||
notify(error.message, 'danger');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@
|
||||
var form = button.closest('form');
|
||||
var target = form && form.querySelector('[name="target"]');
|
||||
if (!target || !target.value.trim()) {
|
||||
showToast('请先填写邮箱或手机号', 'warning');
|
||||
notify('请先填写邮箱或手机号', 'warning');
|
||||
return;
|
||||
}
|
||||
button.disabled = true;
|
||||
@@ -167,7 +167,7 @@
|
||||
verifyCaptcha(payload.scene, function (verified) {
|
||||
if (!verified) {
|
||||
button.disabled = false;
|
||||
showToast('请先完成人机验证', 'warning');
|
||||
notify('请先完成人机验证', 'warning');
|
||||
return;
|
||||
}
|
||||
payload = formData(form);
|
||||
@@ -175,11 +175,11 @@
|
||||
payload.target = target.value.trim();
|
||||
payload.channel = (form.querySelector('[name="channel"]') || {}).value || '';
|
||||
request('code', payload).then(function (result) {
|
||||
showToast(result.message || '验证码已发送', 'success');
|
||||
notify(result.message || '验证码已发送', 'success');
|
||||
startCountdown(button, result.countdown || 60);
|
||||
}).catch(function (error) {
|
||||
button.disabled = false;
|
||||
showToast(error.message, 'danger');
|
||||
notify(error.message, 'danger');
|
||||
}).finally(function () {
|
||||
resetCaptcha(payload.scene);
|
||||
});
|
||||
@@ -194,10 +194,10 @@
|
||||
}
|
||||
setBusy(form, true);
|
||||
request(action, payload).then(function (result) {
|
||||
showToast(result.message || '操作成功', 'success');
|
||||
notify(result.message || '操作成功', 'success');
|
||||
if (result.redirect) window.setTimeout(function () { window.location.assign(result.redirect); }, 350);
|
||||
}).catch(function (error) {
|
||||
showToast(error.message, 'danger');
|
||||
notify(error.message, 'danger');
|
||||
setBusy(form, false);
|
||||
});
|
||||
}
|
||||
@@ -255,7 +255,7 @@
|
||||
function validateForm(form) {
|
||||
if (!form.checkValidity || form.checkValidity()) return true;
|
||||
var field = form.querySelector(':invalid');
|
||||
showToast((field && field.validationMessage) || '请完整填写表单', 'warning');
|
||||
notify((field && field.validationMessage) || '请完整填写表单', 'warning');
|
||||
if (field && typeof field.focus === 'function') field.focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user