初版:教务抢课系统 jwxt(从线上实例导出)
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
{% extends "base_tailwind.html" %}
|
||||
|
||||
{% block title %}登录 - {{ brand_name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="min-h-[70vh] flex items-center justify-center">
|
||||
<div class="w-full max-w-md">
|
||||
<!-- 登录卡片 -->
|
||||
<div class="glass rounded-3xl p-8 layer-4 list-item-enter" style="animation-delay: 0ms;">
|
||||
<!-- Logo -->
|
||||
<div class="text-center mb-8">
|
||||
<div class="w-16 h-16 bg-black dark:bg-white rounded-2xl flex items-center justify-center text-white dark:text-black font-bold text-2xl mx-auto mb-4">
|
||||
S
|
||||
</div>
|
||||
<h1 class="text-2xl font-bold text-neutral-900 dark:text-white">欢迎回来</h1>
|
||||
<p class="text-neutral-500 dark:text-neutral-400 mt-2">登录您的账号继续使用</p>
|
||||
</div>
|
||||
|
||||
<!-- 登录表单 -->
|
||||
<form id="loginForm" onsubmit="handleLogin(event)" class="space-y-5">
|
||||
<div>
|
||||
<label class="input-label">用户名</label>
|
||||
<input type="text" name="username" id="username" class="input-field" placeholder="请输入用户名" required autofocus>
|
||||
</div>
|
||||
<div>
|
||||
<label class="input-label">密码</label>
|
||||
<input type="password" name="password" id="password" class="input-field" placeholder="请输入密码" required>
|
||||
</div>
|
||||
|
||||
<div id="errorMessage" class="hidden p-3 bg-red-50 dark:bg-red-900/20 border border-red-100 dark:border-red-800 rounded-xl text-sm text-red-800 dark:text-red-200">
|
||||
</div>
|
||||
|
||||
<!-- 协议勾选 -->
|
||||
<label class="flex items-start gap-2.5 cursor-pointer select-none group" id="termsLabel">
|
||||
<div class="relative flex-shrink-0 mt-0.5">
|
||||
<input type="checkbox" id="agreeTerms" class="sr-only" onchange="updateCheckbox(this)">
|
||||
<div id="checkboxBox" class="w-[18px] h-[18px] rounded border-2 border-neutral-300 dark:border-neutral-600 transition-all flex items-center justify-center">
|
||||
<svg id="checkIcon" class="w-2.5 h-2.5 text-white dark:text-black hidden" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
<span class="text-xs text-neutral-500 dark:text-neutral-400 leading-relaxed">
|
||||
我已阅读并同意
|
||||
<a href="{{ url_for('main.terms') }}" target="_blank" onclick="event.stopPropagation()" class="text-neutral-800 dark:text-neutral-200 font-medium underline underline-offset-2 hover:text-black dark:hover:text-white">用户服务协议</a>
|
||||
和
|
||||
<a href="{{ url_for('main.privacy') }}" target="_blank" onclick="event.stopPropagation()" class="text-neutral-800 dark:text-neutral-200 font-medium underline underline-offset-2 hover:text-black dark:hover:text-white">隐私政策</a>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<button type="submit" id="submitBtn" class="w-full btn-primary py-3.5 rounded-full text-sm font-bold">
|
||||
登录
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- 分割线 -->
|
||||
<div class="relative my-6">
|
||||
<div class="absolute inset-0 flex items-center">
|
||||
<div class="w-full border-t border-neutral-200 dark:border-neutral-800"></div>
|
||||
</div>
|
||||
<div class="relative flex justify-center text-sm">
|
||||
<span class="px-4 bg-white dark:bg-dark-card text-neutral-500">还没有账号?</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 注册按钮 -->
|
||||
<a href="{{ url_for('main.register') }}" class="block w-full py-3.5 rounded-full text-sm font-bold text-center border-2 border-neutral-200 dark:border-neutral-800 text-neutral-700 dark:text-neutral-300 hover:border-neutral-400 dark:hover:border-neutral-600 transition">
|
||||
立即注册
|
||||
</a>
|
||||
|
||||
<!-- 购买按钮 -->
|
||||
<a href="{{ url_for('main.buy') }}" class="block w-full py-3.5 rounded-full text-sm font-bold text-center border-2 border-neutral-200 dark:border-neutral-800 text-neutral-700 dark:text-neutral-300 hover:border-neutral-400 dark:hover:border-neutral-600 transition mt-3">
|
||||
购买注册码
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- 返回首页 -->
|
||||
<div class="text-center mt-6">
|
||||
<a href="{{ url_for('main.buy') }}" class="text-sm text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition flex items-center justify-center gap-1">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path>
|
||||
</svg>
|
||||
返回首页
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
function updateCheckbox(input) {
|
||||
const box = document.getElementById('checkboxBox');
|
||||
const icon = document.getElementById('checkIcon');
|
||||
const isDark = document.documentElement.classList.contains('dark');
|
||||
if (input.checked) {
|
||||
box.classList.remove('border-neutral-300', 'dark:border-neutral-600');
|
||||
box.classList.add('bg-black', 'border-black', 'dark:bg-white', 'dark:border-white');
|
||||
icon.classList.remove('hidden');
|
||||
} else {
|
||||
box.classList.add('border-neutral-300', 'dark:border-neutral-600');
|
||||
box.classList.remove('bg-black', 'border-black', 'dark:bg-white', 'dark:border-white');
|
||||
icon.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLogin(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const username = document.getElementById('username').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
const errorDiv = document.getElementById('errorMessage');
|
||||
|
||||
// 验证协议勾选
|
||||
if (!document.getElementById('agreeTerms').checked) {
|
||||
errorDiv.textContent = '请先阅读并同意用户服务协议和隐私政策';
|
||||
errorDiv.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
// 禁用按钮
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.innerHTML = '<span class="inline-block w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"></span>登录中...';
|
||||
errorDiv.classList.add('hidden');
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('username', username);
|
||||
formData.append('password', password);
|
||||
|
||||
const response = await fetch('{{ url_for('main.login') }}', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (response.redirected) {
|
||||
window.location.href = response.url;
|
||||
return;
|
||||
}
|
||||
|
||||
const html = await response.text();
|
||||
|
||||
// 检查是否有错误消息
|
||||
if (html.includes('用户名或密码错误') || html.includes('alert-danger')) {
|
||||
errorDiv.textContent = '用户名或密码错误';
|
||||
errorDiv.classList.remove('hidden');
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = '登录';
|
||||
} else {
|
||||
// 登录成功,刷新页面
|
||||
window.location.href = '{{ url_for('main.dashboard') }}';
|
||||
}
|
||||
} catch (error) {
|
||||
errorDiv.textContent = '网络错误,请稍后重试';
|
||||
errorDiv.classList.remove('hidden');
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = '登录';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user