140 lines
6.2 KiB
HTML
140 lines
6.2 KiB
HTML
{% extends "base_tailwind.html" %}
|
|
|
|
{% block title %}个人信息 - {{ brand_name }}{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<style>
|
|
.info-label { color: #6b7280; }
|
|
.dark .info-label { color: #9ca3af; }
|
|
.info-value { font-weight: 500; }
|
|
|
|
@keyframes fadeSlideIn {
|
|
from { opacity: 0; transform: translateY(8px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
.row-animate { animation: fadeSlideIn 0.3s ease both; }
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div>
|
|
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4 mb-6 list-item-enter" style="animation-delay: 0ms;">
|
|
<div>
|
|
<h2 class="text-2xl font-bold flex items-center gap-2">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/>
|
|
<circle cx="12" cy="7" r="4"/>
|
|
</svg>
|
|
个人信息
|
|
</h2>
|
|
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">查看学籍基本信息</p>
|
|
</div>
|
|
<button onclick="refreshInfo()"
|
|
class="px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm font-medium hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors flex items-center gap-2">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
|
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<polyline points="23 4 23 10 17 10"/>
|
|
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>
|
|
</svg>
|
|
刷新
|
|
</button>
|
|
</div>
|
|
|
|
<div id="loadingIndicator" class="text-center py-12 list-item-enter" style="animation-delay: 100ms;">
|
|
<div class="w-10 h-10 border-2 border-black dark:border-white border-t-transparent rounded-full animate-spin mx-auto mb-4"></div>
|
|
<p class="text-gray-500 dark:text-gray-400">正在加载个人信息...</p>
|
|
</div>
|
|
|
|
<div id="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden list-item-enter">
|
|
<p id="errorText" class="text-red-500"></p>
|
|
</div>
|
|
|
|
<div id="infoContainer" class="hidden list-item-enter" style="animation-delay: 150ms;">
|
|
<div class="glass rounded-2xl p-6">
|
|
<div id="infoGrid" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script>
|
|
// ── Session 健康检查 ──
|
|
async function initSession() {
|
|
try {
|
|
const res = await fetch('/api/jwxt/ping');
|
|
const data = await res.json();
|
|
if (!data.success) { console.warn('Session ping 失败:', data.message); return false; }
|
|
if (data.refreshed) console.log('🔄 Session 已自动刷新');
|
|
return true;
|
|
} catch (e) { console.error('Session ping 异常:', e); return false; }
|
|
}
|
|
|
|
const LABEL_MAP = {
|
|
'xh': '学号', 'xm': '姓名', 'xbm': '性别', 'csrq': '出生日期',
|
|
'mzm': '民族', 'zym': '专业', 'jg': '籍贯', 'bjm': '班级',
|
|
'yxm': '院系', 'nj': '年级', 'xz': '学制', 'rxrq': '入学日期',
|
|
'sfzh': '身份证号', 'lxsj': '联系电话', 'email': '电子邮箱',
|
|
'jtdz': '家庭地址', 'BJ': '班级', 'NJ': '年级', 'ZY': '专业',
|
|
'YX': '院系', 'XM': '姓名', 'XH': '学号', 'XB': '性别',
|
|
};
|
|
|
|
async function refreshInfo() {
|
|
document.getElementById('loadingIndicator').classList.remove('hidden');
|
|
document.getElementById('errorMessage').classList.add('hidden');
|
|
document.getElementById('infoContainer').classList.add('hidden');
|
|
|
|
try {
|
|
const res = await fetch('/api/jwxt/personal-info');
|
|
const data = await res.json();
|
|
|
|
document.getElementById('loadingIndicator').classList.add('hidden');
|
|
|
|
if (!data.success) {
|
|
document.getElementById('errorText').textContent = data.message || '查询失败';
|
|
document.getElementById('errorMessage').classList.remove('hidden');
|
|
return;
|
|
}
|
|
|
|
renderInfo(data.info || {});
|
|
document.getElementById('infoContainer').classList.remove('hidden');
|
|
} catch (e) {
|
|
document.getElementById('loadingIndicator').classList.add('hidden');
|
|
document.getElementById('errorText').textContent = '网络错误: ' + e.message;
|
|
document.getElementById('errorMessage').classList.remove('hidden');
|
|
}
|
|
}
|
|
|
|
function renderInfo(info) {
|
|
const grid = document.getElementById('infoGrid');
|
|
if (!info || !Object.keys(info).length) {
|
|
grid.innerHTML = '<p class="text-center text-gray-400 col-span-full">暂无数据</p>';
|
|
return;
|
|
}
|
|
const entries = [];
|
|
for (const [key, value] of Object.entries(info)) {
|
|
const label = LABEL_MAP[key] || key;
|
|
if (key.startsWith('_') || value === null || value === '' || typeof value === 'object') continue;
|
|
if (key.toLowerCase().includes('password') || key.toLowerCase().includes('pwd')) continue;
|
|
entries.push({ label, value });
|
|
}
|
|
if (!entries.length) {
|
|
grid.innerHTML = '<p class="text-center text-gray-400 col-span-full">暂无有效字段</p>';
|
|
return;
|
|
}
|
|
grid.innerHTML = entries.map((e, i) => `
|
|
<div class="row-animate flex flex-col gap-1 p-3 rounded-xl bg-gray-50/50 dark:bg-gray-800/30" style="animation-delay:${i * 30}ms;">
|
|
<span class="info-label text-xs">${e.label}</span>
|
|
<span class="info-value text-sm">${e.value}</span>
|
|
</div>
|
|
`).join('');
|
|
}
|
|
|
|
initSession().then(sessionOk => {
|
|
if (!sessionOk) console.warn('教务 Session 可能已失效');
|
|
refreshInfo();
|
|
});
|
|
</script>
|
|
{% endblock %}
|