192 lines
25 KiB
HTML
192 lines
25 KiB
HTML
{% extends "base_tailwind.html" %}
|
|
|
|
{% block title %}用户管理 - {{ brand_name }}{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
|
|
<style>
|
|
.modal-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; opacity: 0; pointer-events: none; transition: opacity 0.24s ease; }
|
|
.modal-overlay.open { opacity: 1; pointer-events: auto; }
|
|
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
|
|
.modal-panel { position: relative; width: 100%; max-width: 28rem; opacity: 0; transform: scale(0.95) translateY(8px); transition: opacity 0.24s ease, transform 0.26s cubic-bezier(0.22,1,0.36,1); }
|
|
.modal-overlay.open .modal-panel { opacity: 1; transform: scale(1) translateY(0); }
|
|
.modal-panel-lg { max-width: 48rem; }
|
|
.pagination { display: flex; gap: 0.25rem; justify-content: center; align-items: center; padding: 0; margin: 0; list-style: none; }
|
|
.page-item { list-style: none; }
|
|
.page-link { display: inline-flex; align-items: center; justify-content: center; min-width: 2.25rem; height: 2.25rem; padding: 0 0.75rem; border-radius: 0.5rem; font-size: 0.875rem; font-weight: 500; background: rgba(255,255,255,0.6); border: 1px solid rgba(0,0,0,0.08); color: #333; cursor: pointer; transition: all 0.2s; text-decoration: none; }
|
|
.page-link:hover { background: rgba(0,0,0,0.05); }
|
|
.dark .page-link { background: rgba(23,23,23,0.8); border-color: rgba(255,255,255,0.08); color: #e5e5e5; }
|
|
.dark .page-link:hover { background: rgba(255,255,255,0.05); }
|
|
.page-item.active .page-link { background: #111; color: #fff; border-color: #111; }
|
|
.dark .page-item.active .page-link { background: #fff; color: #000; border-color: #fff; }
|
|
.page-item.disabled .page-link { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
|
|
.loading-spinner { width: 40px; height: 40px; border: 3px solid rgba(0,0,0,0.1); border-top-color: currentColor; border-radius: 50%; animation: spin 0.8s linear infinite; }
|
|
.dark .loading-spinner { border-color: rgba(255,255,255,0.15); border-top-color: currentColor; }
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
@media (prefers-reduced-motion: reduce) { .loading-spinner { animation: none !important; border: 3px solid currentColor; opacity: 0.3; } }
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="space-y-6">
|
|
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4 list-item-enter" style="animation-delay:0ms">
|
|
<h2 class="text-2xl font-bold flex items-center gap-2"><i class="bi bi-people"></i> 用户管理</h2>
|
|
<button class="btn-primary px-5 py-2.5 rounded-full text-sm font-bold inline-flex items-center gap-2" onclick="showModal('createUserModal')"><i class="bi bi-person-plus"></i> 添加用户</button>
|
|
</div>
|
|
|
|
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay:50ms">
|
|
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
|
|
<div>
|
|
<h5 class="font-bold mb-2 flex items-center gap-2"><i class="bi bi-shield-check"></i> Session 状态</h5>
|
|
<div class="flex gap-4 flex-wrap">
|
|
<span class="text-green-600 dark:text-green-400 flex items-center gap-1"><i class="bi bi-check-circle-fill"></i> 有效: <strong id="sessionValid">-</strong></span>
|
|
<span class="text-red-500 dark:text-red-400 flex items-center gap-1"><i class="bi bi-x-circle-fill"></i> 过期: <strong id="sessionInvalid">-</strong></span>
|
|
<span class="text-neutral-500 dark:text-neutral-400 flex items-center gap-1"><i class="bi bi-question-circle-fill"></i> 未知: <strong id="sessionUnknown">-</strong></span>
|
|
</div>
|
|
</div>
|
|
<div class="flex gap-2">
|
|
<button class="btn-outline text-sm px-4 py-2" onclick="batchCheckSession()"><i class="bi bi-search"></i> 批量检查</button>
|
|
<button class="btn-outline text-sm px-4 py-2" onclick="showModal('batchRefreshModal')"><i class="bi bi-arrow-clockwise"></i> 批量刷新</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4 list-item-enter" style="animation-delay:100ms">
|
|
<div class="glass rounded-2xl p-5 layer-2 flex items-center justify-between">
|
|
<div><p class="text-sm text-neutral-500 dark:text-neutral-400">总用户数</p><p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="totalUsers">-</p></div>
|
|
<div class="w-10 h-10 rounded-xl bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center text-blue-600 dark:text-blue-400"><i class="bi bi-people text-lg"></i></div>
|
|
</div>
|
|
<div class="glass rounded-2xl p-5 layer-2 flex items-center justify-between">
|
|
<div><p class="text-sm text-neutral-500 dark:text-neutral-400">总任务数</p><p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="totalTasks">-</p></div>
|
|
<div class="w-10 h-10 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center text-amber-600 dark:text-amber-400"><i class="bi bi-list-task text-lg"></i></div>
|
|
</div>
|
|
<div class="glass rounded-2xl p-5 layer-2 flex items-center justify-between">
|
|
<div><p class="text-sm text-neutral-500 dark:text-neutral-400">运行中</p><p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="runningTasks">-</p></div>
|
|
<div class="w-10 h-10 rounded-xl bg-green-100 dark:bg-green-900/30 flex items-center justify-center text-green-600 dark:text-green-400"><i class="bi bi-play-circle text-lg"></i></div>
|
|
</div>
|
|
<div class="glass rounded-2xl p-5 layer-2 flex items-center justify-between">
|
|
<div><p class="text-sm text-neutral-500 dark:text-neutral-400">成功任务</p><p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="successTasks">-</p></div>
|
|
<div class="w-10 h-10 rounded-xl bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center text-purple-600 dark:text-purple-400"><i class="bi bi-check-circle text-lg"></i></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay:150ms">
|
|
<div class="flex justify-between items-center mb-4">
|
|
<h5 class="font-bold flex items-center gap-2"><i class="bi bi-list"></i> 用户列表</h5>
|
|
<button class="btn-outline text-sm px-4 py-2" onclick="loadUsers()"><i class="bi bi-arrow-clockwise"></i> 刷新</button>
|
|
</div>
|
|
<div id="loadingIndicator" class="text-center py-12">
|
|
<div class="loading-spinner mx-auto mb-3 text-neutral-900 dark:text-white"></div>
|
|
<p class="text-neutral-500 dark:text-neutral-400">加载中...</p>
|
|
</div>
|
|
<div id="emptyState" class="text-center py-12" style="display:none">
|
|
<div class="w-16 h-16 mx-auto mb-4 rounded-2xl bg-neutral-100 dark:bg-neutral-800 flex items-center justify-center text-neutral-400"><i class="bi bi-inbox text-2xl"></i></div>
|
|
<p class="text-neutral-500 dark:text-neutral-400">暂无用户</p>
|
|
</div>
|
|
<div id="usersTableContainer" class="overflow-x-auto" style="display:none">
|
|
<table class="data-table">
|
|
<thead><tr><th>ID</th><th>用户名</th><th>学号</th><th>Session</th><th>角色</th><th>状态</th><th>创建时间</th><th>操作</th></tr></thead>
|
|
<tbody id="usersTableBody"></tbody>
|
|
</table>
|
|
</div>
|
|
<nav id="pagination" class="mt-4" style="display:none"><ul class="pagination" id="paginationList"></ul></nav>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="createUserModal" class="modal-overlay" onclick="if(event.target===this)hideModal('createUserModal')">
|
|
<div class="modal-backdrop" onclick="hideModal('createUserModal')"></div>
|
|
<div class="modal-panel">
|
|
<div class="glass rounded-2xl p-6 layer-4">
|
|
<div class="flex justify-between items-center mb-6">
|
|
<h3 class="text-xl font-bold text-neutral-900 dark:text-white flex items-center gap-2"><i class="bi bi-person-plus"></i> 添加用户</h3>
|
|
<button onclick="hideModal('createUserModal')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition"><i class="bi bi-x-lg"></i></button>
|
|
</div>
|
|
<form id="createUserForm" class="space-y-4">
|
|
<div><label class="input-label">用户名(学号)</label><input type="text" class="input-field" id="newUsername" required></div>
|
|
<div><label class="input-label">密码</label><input type="password" class="input-field" id="newPassword" required></div>
|
|
<div class="flex items-center gap-2"><input type="checkbox" id="newIsAdmin" class="w-4 h-4 rounded border-neutral-300 dark:border-neutral-600 accent-neutral-900 dark:accent-white"><label for="newIsAdmin" class="text-sm text-neutral-700 dark:text-neutral-300">设为管理员</label></div>
|
|
</form>
|
|
<div class="flex gap-3 mt-6">
|
|
<button type="button" onclick="hideModal('createUserModal')" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">取消</button>
|
|
<button type="button" onclick="submitCreateUser()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition"><i class="bi bi-check-circle"></i> 创建</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="batchRefreshModal" class="modal-overlay" onclick="if(event.target===this)hideModal('batchRefreshModal')">
|
|
<div class="modal-backdrop" onclick="hideModal('batchRefreshModal')"></div>
|
|
<div class="modal-panel modal-panel-lg">
|
|
<div class="glass rounded-2xl p-6 layer-4 max-h-[90vh] overflow-y-auto">
|
|
<div class="flex justify-between items-center mb-6">
|
|
<h3 class="text-xl font-bold text-neutral-900 dark:text-white flex items-center gap-2"><i class="bi bi-arrow-clockwise"></i> 批量刷新 Session</h3>
|
|
<button onclick="hideModal('batchRefreshModal')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition"><i class="bi bi-x-lg"></i></button>
|
|
</div>
|
|
<div class="glass rounded-xl p-4 mb-4 bg-blue-50 dark:bg-blue-900/20 text-blue-800 dark:text-blue-200 text-sm"><i class="bi bi-info-circle"></i> 请选择刷新选项。强制刷新会忽略当前有效的 session,重新登录所有账号。</div>
|
|
<div class="flex items-center gap-2 mb-4"><input type="checkbox" id="batchForceRefresh" class="w-4 h-4 rounded border-neutral-300 dark:border-neutral-600 accent-neutral-900 dark:accent-white"><label for="batchForceRefresh" class="text-sm text-neutral-700 dark:text-neutral-300"><strong>强制刷新</strong>(即使 session 有效也重新登录)</label></div>
|
|
<div class="mb-4"><label class="input-label">密码映射(JSON 格式,可选)</label><textarea class="input-field" id="batchPasswordMap" rows="5" placeholder="{"学号1": "密码1", "学号2": "密码2"}"></textarea><p class="text-xs text-neutral-500 mt-1">如果不提供密码映射,将只检查状态,无法刷新过期的 session</p></div>
|
|
<div id="batchRefreshResult" style="display:none">
|
|
<div class="border-t border-neutral-200 dark:border-neutral-700 pt-4 mb-4">
|
|
<h6 class="font-bold mb-2">刷新结果</h6>
|
|
<div class="flex gap-3 mb-3 flex-wrap">
|
|
<span class="text-green-600 dark:text-green-400">未过期: <strong id="resultValid">0</strong></span>
|
|
<span class="text-blue-600 dark:text-blue-400">刷新成功: <strong id="resultRefreshed">0</strong></span>
|
|
<span class="text-red-500 dark:text-red-400">登录失败: <strong id="resultFailed">0</strong></span>
|
|
</div>
|
|
<div class="overflow-y-auto" style="max-height:300px">
|
|
<table class="data-table"><thead><tr><th>用户</th><th>状态</th><th>消息</th></tr></thead><tbody id="batchRefreshDetails"></tbody></table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="flex gap-3">
|
|
<button type="button" onclick="hideModal('batchRefreshModal')" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">关闭</button>
|
|
<button type="button" id="btnCheckOnly" onclick="batchCheckOnly()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition"><i class="bi bi-search"></i> 仅检查</button>
|
|
<button type="button" id="btnDoBatchRefresh" onclick="doBatchRefresh()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition"><i class="bi bi-arrow-clockwise"></i> 开始刷新</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="singleRefreshModal" class="modal-overlay" onclick="if(event.target===this)hideModal('singleRefreshModal')">
|
|
<div class="modal-backdrop" onclick="hideModal('singleRefreshModal')"></div>
|
|
<div class="modal-panel">
|
|
<div class="glass rounded-2xl p-6 layer-4">
|
|
<div class="flex justify-between items-center mb-6">
|
|
<h3 class="text-xl font-bold text-neutral-900 dark:text-white flex items-center gap-2"><i class="bi bi-arrow-clockwise"></i> 刷新用户 Session</h3>
|
|
<button onclick="hideModal('singleRefreshModal')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition"><i class="bi bi-x-lg"></i></button>
|
|
</div>
|
|
<div class="space-y-4">
|
|
<div><label class="input-label">用户</label><input type="text" class="input-field" id="singleRefreshUsername" readonly><input type="hidden" id="singleRefreshUserId"></div>
|
|
<div><label class="input-label">教务系统密码</label><input type="password" class="input-field" id="singleRefreshPassword" placeholder="请输入密码"></div>
|
|
<div class="flex items-center gap-2"><input type="checkbox" id="singleForceRefresh" class="w-4 h-4 rounded border-neutral-300 dark:border-neutral-600 accent-neutral-900 dark:accent-white"><label for="singleForceRefresh" class="text-sm text-neutral-700 dark:text-neutral-300">强制刷新(即使 session 有效)</label></div>
|
|
<div id="singleRefreshResult"></div>
|
|
</div>
|
|
<div class="flex gap-3 mt-6">
|
|
<button type="button" onclick="hideModal('singleRefreshModal')" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">取消</button>
|
|
<button type="button" id="btnDoSingleRefresh" onclick="doSingleRefresh()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition"><i class="bi bi-arrow-clockwise"></i> 刷新</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script>
|
|
let currentPage=1,allUsers=[];
|
|
function showModal(id){const m=document.getElementById(id);m.classList.add('open');document.body.style.overflow='hidden';}
|
|
function hideModal(id){const m=document.getElementById(id);m.classList.remove('open');document.body.style.overflow='';}
|
|
async function loadStats(){try{const d=await apiRequest('/api/admin/stats');if(d.success){document.getElementById('totalUsers').textContent=d.stats.total_users;document.getElementById('totalTasks').textContent=d.stats.total_tasks;document.getElementById('runningTasks').textContent=d.stats.running_tasks;document.getElementById('successTasks').textContent=d.stats.success_tasks;if(d.stats.session_stats){document.getElementById('sessionValid').textContent=d.stats.session_stats.valid||0;document.getElementById('sessionInvalid').textContent=d.stats.session_stats.invalid||0;document.getElementById('sessionUnknown').textContent=d.stats.session_stats.unknown||0;}}}catch(e){console.error(e);}}
|
|
async function loadUsers(page=1){currentPage=page;document.getElementById('loadingIndicator').style.display='block';document.getElementById('emptyState').style.display='none';document.getElementById('usersTableContainer').style.display='none';document.getElementById('pagination').style.display='none';try{const d=await apiRequest(`/api/admin/users/list?page=${page}&per_page=20`);document.getElementById('loadingIndicator').style.display='none';if(!d.success||!d.users||d.users.length===0){document.getElementById('emptyState').style.display='block';return;}allUsers=d.users;renderUsersTable(d.users);renderPagination(d.total,d.pages,page);document.getElementById('usersTableContainer').style.display='block';document.getElementById('pagination').style.display='block';}catch(e){document.getElementById('loadingIndicator').style.display='none';showToast('加载失败','error');}}
|
|
function renderUsersTable(users){const tbody=document.getElementById('usersTableBody');tbody.innerHTML=users.map(u=>`<tr><td>${u.id}</td><td><strong>${escapeHtml(u.username)}</strong></td><td>${u.jwxt_username?escapeHtml(u.jwxt_username):'<span class="text-neutral-400">-</span>'}</td><td>${u.session_status==='valid'?'<span class="status-badge status-success" title="更新时间: '+(u.session_updated_at?formatTime(u.session_updated_at):'未知')+'">有效</span>':u.session_status==='invalid'?'<span class="status-badge status-danger">过期</span>':'<span class="status-badge status-pending">未知</span>'}</td><td>${u.is_admin?'<span class="status-badge status-danger">管理员</span>':'<span class="status-badge status-pending">普通用户</span>'}</td><td>${u.is_active?'<span class="status-badge status-success">激活</span>':'<span class="status-badge status-pending">禁用</span>'}</td><td class="text-sm text-neutral-500">${formatTime(u.created_at)}</td><td><button class="btn-outline text-xs px-2 py-1" onclick="viewUserTasks(${u.id})" title="查看任务"><i class="bi bi-list-task"></i></button><button class="btn-outline text-xs px-2 py-1 ml-1" onclick="refreshUserSession(${u.id},'${u.jwxt_username||u.username}')" title="刷新Session"><i class="bi bi-arrow-clockwise"></i></button></td></tr>`).join('');}
|
|
function renderPagination(total,pages,current){const ul=document.getElementById('paginationList');let h='';h+=`<li class="page-item ${current===1?'disabled':''}"><a class="page-link" href="#" onclick="loadUsers(${current-1});return false;">上一页</a></li>`;for(let i=1;i<=pages;i++){if(i===1||i===pages||(i>=current-2&&i<=current+2)){h+=`<li class="page-item ${i===current?'active':''}"><a class="page-link" href="#" onclick="loadUsers(${i});return false;">${i}</a></li>`;}else if(i===current-3||i===current+3){h+=`<li class="page-item disabled"><span class="page-link">...</span></li>`;}}h+=`<li class="page-item ${current===pages?'disabled':''}"><a class="page-link" href="#" onclick="loadUsers(${current+1});return false;">下一页</a></li>`;ul.innerHTML=h;}
|
|
async function submitCreateUser(){const u=document.getElementById('newUsername').value.trim(),p=document.getElementById('newPassword').value,a=document.getElementById('newIsAdmin').checked;if(!u||!p){showToast('请填写完整信息','warning');return;}try{const d=await apiRequest('/api/admin/users/create',{method:'POST',body:JSON.stringify({username:u,password:p,is_admin:a})});if(d.success){showToast('用户创建成功','success');hideModal('createUserModal');document.getElementById('createUserForm').reset();loadUsers();loadStats();}else{showToast(d.message||'创建失败','error');}}catch(e){showToast('网络错误','error');}}
|
|
function viewUserTasks(id){window.location.href=`/tasks?user_id=${id}`;}
|
|
document.addEventListener('DOMContentLoaded',()=>{loadStats();loadUsers();});
|
|
async function batchCheckSession(){if(!confirm('开始批量检查所有用户的 Session 状态?'))return;showToast('正在检查 Session 状态...','info');try{const d=await apiRequest('/api/admin/session/batch_check',{method:'POST',body:JSON.stringify({})});if(d.success){const r=d.results;showToast(`检查完成:有效${r.valid}个,过期${r.invalid}个,未配置${r.no_account}个`,'success');loadStats();loadUsers();}else{showToast(d.message||'检查失败','error');}}catch(e){showToast('网络错误','error');}}
|
|
async function batchCheckOnly(){const btn=document.getElementById('btnCheckOnly');btn.disabled=true;btn.innerHTML='<i class="bi bi-search"></i> 检查中...';try{const d=await apiRequest('/api/admin/session/batch_check',{method:'POST',body:JSON.stringify({})});if(d.success){const results=d.results;document.getElementById('resultValid').textContent=results.valid;document.getElementById('resultRefreshed').textContent=0;document.getElementById('resultFailed').textContent=results.invalid+results.no_jwxt;const tbody=document.getElementById('batchRefreshDetails');tbody.innerHTML=results.details.map(d=>`<tr><td>${escapeHtml(d.username)}</td><td>${d.status==='valid'?'<span class="status-badge status-success">有效</span>':d.status==='no_jwxt'?'<span class="status-badge status-pending">未配置</span>':'<span class="status-badge status-danger">过期</span>'}</td><td class="text-sm text-neutral-500">${escapeHtml(d.message)||'-'}</td></tr>`).join('');document.getElementById('batchRefreshResult').style.display='block';loadStats();}}catch(e){showToast('检查失败','error');}finally{btn.disabled=false;btn.innerHTML='<i class="bi bi-search"></i> 仅检查';}}
|
|
async function doBatchRefresh(){const force=document.getElementById('batchForceRefresh').checked;const passwordMapText=document.getElementById('batchPasswordMap').value.trim();let passwordMap={};if(passwordMapText){try{passwordMap=JSON.parse(passwordMapText);}catch(e){showToast('密码映射 JSON 格式错误','warning');return;}}const btn=document.getElementById('btnDoBatchRefresh');btn.disabled=true;btn.innerHTML='<i class="bi bi-arrow-clockwise"></i> 刷新中...';try{const d=await apiRequest('/api/admin/session/batch_refresh',{method:'POST',body:JSON.stringify({force:force,password_map:passwordMap})});if(d.success){const results=d.results;document.getElementById('resultValid').textContent=results.valid;document.getElementById('resultRefreshed').textContent=results.refreshed;document.getElementById('resultFailed').textContent=results.failed+results.no_password;const tbody=document.getElementById('batchRefreshDetails');tbody.innerHTML=results.details.map(d=>`<tr><td>${escapeHtml(d.username)}</td><td>${d.status==='valid'?'<span class="status-badge status-success">有效</span>':d.status==='refreshed'?'<span class="status-badge status-info">已刷新</span>':d.status==='no_password'?'<span class="status-badge status-warning">无密码</span>':'<span class="status-badge status-danger">失败</span>'}</td><td class="text-sm text-neutral-500">${escapeHtml(d.message)||'-'}</td></tr>`).join('');document.getElementById('batchRefreshResult').style.display='block';showToast(`刷新完成:有效${results.valid}个,刷新${results.refreshed}个,失败${results.failed}个`,'success');loadStats();loadUsers();}else{showToast(d.message||'刷新失败','error');}}catch(e){showToast('网络错误','error');}finally{btn.disabled=false;btn.innerHTML='<i class="bi bi-arrow-clockwise"></i> 开始刷新';}}
|
|
function refreshUserSession(userId,username){document.getElementById('singleRefreshUserId').value=userId;document.getElementById('singleRefreshUsername').value=username;document.getElementById('singleRefreshPassword').value='';document.getElementById('singleForceRefresh').checked=false;document.getElementById('singleRefreshResult').innerHTML='';showModal('singleRefreshModal');}
|
|
async function doSingleRefresh(){const userId=document.getElementById('singleRefreshUserId').value;const password=document.getElementById('singleRefreshPassword').value.trim();const force=document.getElementById('singleForceRefresh').checked;if(!password){document.getElementById('singleRefreshResult').innerHTML='<div class="glass rounded-xl p-3 bg-amber-50 dark:bg-amber-900/20 text-amber-800 dark:text-amber-200 text-sm">请输入密码</div>';return;}const btn=document.getElementById('btnDoSingleRefresh');btn.disabled=true;btn.innerHTML='<i class="bi bi-arrow-clockwise"></i> 刷新中...';try{const d=await apiRequest(`/api/admin/users/${userId}/session/refresh`,{method:'POST',body:JSON.stringify({jwxt_password:password,force:force})});if(d.success){document.getElementById('singleRefreshResult').innerHTML=`<div class="glass rounded-xl p-3 bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 text-sm">${d.message}</div>`;setTimeout(()=>{hideModal('singleRefreshModal');loadStats();loadUsers();},1500);}else{document.getElementById('singleRefreshResult').innerHTML=`<div class="glass rounded-xl p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 text-sm">${d.message}</div>`;}}catch(e){document.getElementById('singleRefreshResult').innerHTML='<div class="glass rounded-xl p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 text-sm">刷新失败</div>';}finally{btn.disabled=false;btn.innerHTML='<i class="bi bi-arrow-clockwise"></i> 刷新';}}
|
|
</script>
|
|
{% endblock %}
|