fix: 全量提示改为顶部 toast 飘窗 + 修复卷王 token 失效跳转死循环 + 调整行点击防御
- 所有 showAlert 改为 showToast 顶部飘窗(首屏 / 抽取页统一,含空消息守卫) - 导出排序新增 成绩升序 / 成绩降序 两种(前后端 + 设置弹窗都支持) - 设置保存:仅连接信息真变化才 reload projects,避免非连接改动导致持续刷新失败 - 强化历史成绩弹窗排序与兜底(缺 submit_ts 时按 idx 倒序) - 行点击事件加防御:要求父节点是 #tbody,避免被无关 tr 误触发 - 卷王 token 失效时:先 fetch logout 清会话再跳 login.php,登录页也加 token 探测兜底,根治"跳不过去"死循环 - 移除 index.php / draw.php 中已无用的内联 #alert DOM - 兼容 config_get 缺 export_sort 时回退 time 的 4 模式归一化
This commit is contained in:
+26
-5
@@ -57,12 +57,33 @@
|
||||
return j.data;
|
||||
}
|
||||
|
||||
/* ---------------- Toast 顶部飘窗通知(与 app.js 一致) ---------------- */
|
||||
const TOAST_DURATION = 3500;
|
||||
const TOAST_LIMIT = 5;
|
||||
function showToast(msg, type) {
|
||||
if (msg === '' || msg == null) return;
|
||||
const el = document.getElementById('toastContainer') || (function () {
|
||||
const c = document.createElement('div');
|
||||
c.id = 'toastContainer';
|
||||
c.style.cssText = 'position:fixed;top:16px;left:50%;transform:translateX(-50%);z-index:9999;display:flex;flex-direction:column;gap:8px;pointer-events:none;max-width:calc(100vw - 32px);width:560px';
|
||||
document.body.appendChild(c);
|
||||
return c;
|
||||
})();
|
||||
while (el.children.length >= TOAST_LIMIT) el.firstChild.remove();
|
||||
const t = document.createElement('div');
|
||||
const cls = type === 'error' ? 'toast-error' : (type === 'warn' ? 'toast-warn' : (type === 'info' ? 'toast-ok' : 'toast'));
|
||||
t.className = 'toast ' + cls;
|
||||
t.innerHTML = '<span>' + esc(msg).replace(/\n/g, '<br>') + '</span>';
|
||||
t.style.cssText = 'pointer-events:auto;padding:10px 16px;border-radius:10px;font-size:13px;line-height:1.55;box-shadow:0 8px 30px rgba(15,23,42,.18);animation:toastIn .25s ease;white-space:pre-wrap;word-break:break-word';
|
||||
el.appendChild(t);
|
||||
t.addEventListener('click', () => { t.style.animation = 'toastOut .2s ease forwards'; setTimeout(() => t.remove(), 200); });
|
||||
setTimeout(() => { if (t.parentNode) { t.style.animation = 'toastOut .2s ease forwards'; setTimeout(() => t.remove(), 200); } }, TOAST_DURATION);
|
||||
}
|
||||
/** 兼容旧 showAlert 调用 → 走 toast(draw.js 内部已有 esc,此处直接复用) */
|
||||
function showAlert(msg, type) {
|
||||
const el = $('#alert');
|
||||
if (!el) return;
|
||||
if (!msg) { el.classList.add('hidden'); return; }
|
||||
el.textContent = msg;
|
||||
el.className = 'alert' + (type === 'info' ? ' info' : '');
|
||||
if (msg === '' || msg == null) return;
|
||||
const t = type === 'info' ? 'ok' : (type === 'error' ? 'error' : '');
|
||||
showToast(msg, t);
|
||||
}
|
||||
|
||||
/* ================= 抽取核心(纯函数,供测试) ================= */
|
||||
|
||||
Reference in New Issue
Block a user