初版:教务抢课系统 jwxt(从线上实例导出)
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
{% extends "base_tailwind.html" %}
|
||||
{% block title %}个人信息编辑 - {{ brand_name }}{% endblock %}
|
||||
{% block extra_css %}
|
||||
<style>
|
||||
@keyframes fadeSlideIn {
|
||||
from { opacity: 0; transform: translateY(8px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
.row-animate { animation: fadeSlideIn 0.3s ease both; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.row-animate { animation: none !important; opacity: 1 !important; }
|
||||
.list-item-enter { animation: none !important; opacity: 1 !important; }
|
||||
}
|
||||
</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">
|
||||
<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>
|
||||
</div>
|
||||
<div id="loadingIndicator" class="text-center py-12 hidden"><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"><p id="errorText" class="text-red-500"></p></div>
|
||||
<div id="formContainer" class="hidden">
|
||||
<div class="glass rounded-2xl p-6 max-w-2xl mx-auto">
|
||||
<form id="editForm">
|
||||
<div id="formFields"></div>
|
||||
<div class="mt-6 flex gap-3">
|
||||
<button type="submit" class="px-6 py-2.5 rounded-lg bg-black dark:bg-white text-white dark:text-black text-sm font-medium hover:opacity-85 transition-opacity">保存修改</button>
|
||||
<button type="button" onclick="loadData()" class="px-4 py-2.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm font-medium">刷新</button>
|
||||
</div>
|
||||
</form>
|
||||
<div id="resultMessage" class="mt-4 hidden"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">无可编辑字段</p></div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
async function loadData() {
|
||||
document.getElementById('loadingIndicator').classList.remove('hidden');
|
||||
document.getElementById('errorMessage').classList.add('hidden');
|
||||
document.getElementById('formContainer').classList.add('hidden');
|
||||
document.getElementById('emptyState').classList.add('hidden');
|
||||
try {
|
||||
const res = await fetch('/api/jwxt/personal-info-editable');
|
||||
const data = await res.json();
|
||||
document.getElementById('loadingIndicator').classList.add('hidden');
|
||||
if (!data.success) { showError(data.message); return; }
|
||||
const fields = data.fields || [];
|
||||
if (!fields.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
|
||||
const container = document.getElementById('formFields');
|
||||
container.innerHTML = fields.map(f => {
|
||||
if (f.readonly) return '';
|
||||
let input;
|
||||
if (f.type === 'select') {
|
||||
input = `<select name="${escAttr(f.name)}" class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">${f.options.map(o => `<option value="${escAttr(o.value)}" ${o.selected?'selected':''}>${escHtml(o.label)}</option>`).join('')}</select>`;
|
||||
} else {
|
||||
input = `<input type="text" name="${escAttr(f.name)}" value="${escAttr(f.value)}" class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">`;
|
||||
}
|
||||
return `<div class="mb-4"><label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">${escHtml(f.label)}</label>${input}</div>`;
|
||||
}).join('');
|
||||
document.getElementById('formContainer').classList.remove('hidden');
|
||||
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
|
||||
}
|
||||
document.getElementById('editForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(e.target);
|
||||
const data = Object.fromEntries(formData.entries());
|
||||
const resultEl = document.getElementById('resultMessage');
|
||||
resultEl.classList.remove('hidden');
|
||||
resultEl.innerHTML = '<p class="text-gray-500">提交中...</p>';
|
||||
try {
|
||||
const res = await fetch('/api/jwxt/personal-info/update', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(data) });
|
||||
const result = await res.json();
|
||||
resultEl.innerHTML = result.success ? '<p class="text-green-600">✅ 更新成功</p>' : '<p class="text-red-500">❌ ' + escHtml(result.message) + '</p>';
|
||||
} catch(e) { resultEl.innerHTML = '<p class="text-red-500">❌ 网络错误</p>'; }
|
||||
});
|
||||
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
|
||||
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); }
|
||||
function escAttr(s) { if(s==null) return ''; return String(s).replace(/&/g,'&').replace(/"/g,'"').replace(/</g,'<').replace(/>/g,'>'); }
|
||||
document.addEventListener('DOMContentLoaded', () => loadData());
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user