进行了一些小优化

This commit is contained in:
kate522 committed 2026-08-24 18:08:06 +08:00
1 parent 10b3e6dd9f
commit f5c60cd425
5 files changed
+127 -24

No files matched your search

+13 -13
View File
@@ -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;
}
+75
View File
@@ -27,6 +27,79 @@
tabs[next].click();
}
function initSwiperA11y(el) {
if (el.dataset.autoplay !== '1' || !once(el, 'SwiperA11y')) return;
var i18n = config.i18n || {};
var userPaused = reducedMotion;
var focusPaused = false;
var button = document.createElement('button');
button.type = 'button';
button.className = 'aksrt-widget-swiper__pause';
function setControlState() {
button.setAttribute('aria-pressed', userPaused ? 'true' : 'false');
button.setAttribute('aria-label', userPaused ? (i18n.resume || '继续自动播放') : (i18n.pause || '暂停自动播放'));
button.textContent = userPaused ? '▶' : 'Ⅱ';
}
function autoplay() {
return el.swiper && el.swiper.autoplay ? el.swiper.autoplay : null;
}
function stopAutoplay() {
var runtime = autoplay();
if (runtime && typeof runtime.stop === 'function') runtime.stop();
setControlState();
}
function pause() {
focusPaused = true;
stopAutoplay();
}
function resume() {
if (reducedMotion || userPaused || focusPaused) {
stopAutoplay();
return;
}
var runtime = autoplay();
if (runtime && typeof runtime.start === 'function') runtime.start();
setControlState();
}
button.addEventListener('click', function () {
if (userPaused && !reducedMotion) {
userPaused = false;
resume();
} else {
userPaused = true;
stopAutoplay();
}
});
el.addEventListener('focusin', pause);
el.addEventListener('focusout', function () {
window.setTimeout(function () {
if (el.contains(document.activeElement)) return;
focusPaused = false;
resume();
}, 0);
});
setControlState();
el.appendChild(button);
var attempts = 0;
function connectToSwiper() {
if (autoplay()) {
if (reducedMotion || userPaused || focusPaused) stopAutoplay();
return;
}
attempts += 1;
if (attempts < 120) window.requestAnimationFrame(connectToSwiper);
}
connectToSwiper();
}
function videoType(url) {
if (/\.m3u8(?:\?|$)/i.test(url)) return 'hls';
if (/\.flv(?:\?|$)/i.test(url)) return 'flv';
@@ -257,6 +330,8 @@
function scan(root) {
var scope = root || document;
if (scope.matches && scope.matches('.aksrt-widget-swiper')) initSwiperA11y(scope);
scope.querySelectorAll('.aksrt-widget-swiper').forEach(initSwiperA11y);
scope.querySelectorAll('.aksrt-widget-video[data-video-url]').forEach(initVideo);
scope.querySelectorAll('.aksrt-widget-toc').forEach(initToc);
scope.querySelectorAll('.aksrt-widget-quote').forEach(initQuote);