20250922
This commit is contained in:
+178
-149
@@ -4,175 +4,204 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>修改密码 - 车主信息查询系统</title>
|
||||
<!-- Tailwind CSS -->
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<!-- Font Awesome -->
|
||||
<!-- 引入Layui CSS -->
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/layui.css') }}">
|
||||
<!-- 引入Font Awesome -->
|
||||
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
|
||||
<!-- 配置Tailwind自定义颜色和字体 -->
|
||||
<!-- 引入自定义CSS -->
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/custom.css') }}">
|
||||
|
||||
<!-- 引入Layui JS -->
|
||||
<script src="{{ url_for('static', filename='layui.js') }}"></script>
|
||||
<script>
|
||||
tailwind.config = {
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
primary: '#2563eb',
|
||||
secondary: '#f3f4f6',
|
||||
'primary-light': '#dbeafe',
|
||||
'primary-dark': '#1d4ed8',
|
||||
'table-header': '#f9fafb',
|
||||
},
|
||||
fontFamily: {
|
||||
sans: ['Inter', 'system-ui', 'sans-serif'],
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
layui.use(['layer', 'form', 'element'], function(){
|
||||
var layer = layui.layer;
|
||||
var form = layui.form;
|
||||
var element = layui.element;
|
||||
});
|
||||
</script>
|
||||
<!-- 自定义工具类 -->
|
||||
<style type="text/tailwindcss">
|
||||
@layer utilities {
|
||||
.content-auto {
|
||||
content-visibility: auto;
|
||||
}
|
||||
.card-shadow {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.09);
|
||||
}
|
||||
.input-focus {
|
||||
@apply focus:border-primary focus:ring-2 focus:ring-primary/20 focus:outline-none;
|
||||
}
|
||||
.animate-fade-in {
|
||||
animation: fadeIn 0.3s ease-out forwards;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-secondary min-h-screen font-sans">
|
||||
<body>
|
||||
<!-- 引入统一的顶部导航栏 -->
|
||||
{% include 'header.html' %}
|
||||
|
||||
|
||||
<!-- 主要内容区域 -->
|
||||
<main class="container mx-auto px-4 pt-24 pb-12">
|
||||
<!-- 返回按钮 -->
|
||||
<div class="mb-6 flex justify-end">
|
||||
<a href="{{ url_for('query') }}" class="inline-flex items-center text-primary hover:text-primary-dark transition-colors">
|
||||
<i class="fa fa-arrow-left mr-2"></i> 返回主页面
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- 修改密码表单 -->
|
||||
<div class="max-w-md mx-auto bg-white rounded-lg shadow-xl p-8 animate-fade-in">
|
||||
<div class="text-center mb-6">
|
||||
<div class="w-16 h-16 bg-primary-light rounded-full flex items-center justify-center mx-auto mb-4">
|
||||
<i class="fa fa-key text-primary text-2xl"></i>
|
||||
<div class="content-container">
|
||||
<div class="content-wrapper">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<i class="fa fa-key"></i> 修改密码
|
||||
<a href="{{ url_for('query') }}" class="layui-btn layui-btn-xs layui-btn-primary" style="float: right;">
|
||||
<i class="fa fa-arrow-left"></i> 返回主页面
|
||||
</a>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- 消息提示区域 -->
|
||||
{% if error %}
|
||||
<div class="layui-bg-red message-box">
|
||||
<i class="fa fa-exclamation-circle"></i> {{ error }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if success %}
|
||||
<div class="layui-bg-green message-box">
|
||||
<i class="fa fa-check-circle"></i> {{ success }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="layui-text" style="text-align: center; margin-bottom: 20px;">
|
||||
<div style="width: 80px; height: 80px; background-color: #f2f2f2; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 15px;">
|
||||
<i class="fa fa-key" style="font-size: 40px; color: #009688;"></i>
|
||||
</div>
|
||||
<p style="color: #666;">请填写以下信息以修改您的密码</p>
|
||||
</div>
|
||||
|
||||
<!-- 表单 - 使用Layui样式 -->
|
||||
<form class="layui-form" id="changePasswordForm" action="/change_password_page" method="POST" style="max-width: 500px; margin: 0 auto;">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">旧密码</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="password" id="old_password" name="old_password" class="layui-input" placeholder="请输入旧密码" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">新密码</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="password" id="new_password" name="new_password" class="layui-input" placeholder="请输入新密码" required>
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">密码长度至少8位,包含字母和数字</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">确认新密码</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="password" id="confirm_password" name="confirm_password" class="layui-input" placeholder="请再次输入新密码" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button type="submit" class="layui-btn" lay-submit>
|
||||
<i class="fa fa-save mr-1"></i> 确认修改
|
||||
</button>
|
||||
<button type="button" onclick="window.location.href='{{ url_for('query') }}'" class="layui-btn layui-btn-primary">
|
||||
<i class="fa fa-times mr-1"></i> 取消
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<h2 class="text-2xl font-bold text-gray-800">修改密码</h2>
|
||||
<p class="text-gray-500 mt-2">请填写以下信息以修改您的密码</p>
|
||||
</div>
|
||||
|
||||
<!-- 错误信息显示区域 -->
|
||||
{% if error %}
|
||||
<div class="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-md flex items-start animate-fade-in">
|
||||
<i class="fa fa-exclamation-circle mt-1 mr-3"></i>
|
||||
<span>{{ error }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- 表单 -->
|
||||
<form id="changePasswordForm" method="POST" class="space-y-4">
|
||||
<div class="mb-4">
|
||||
<label for="old_password" class="block text-gray-700 text-sm font-medium mb-2">旧密码</label>
|
||||
<div class="relative">
|
||||
<input type="password" id="old_password" name="old_password" class="w-full px-4 py-2 border border-gray-300 rounded-md input-focus transition-colors" placeholder="请输入旧密码" required>
|
||||
<button type="button" class="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors" onclick="togglePasswordVisibility('old_password', this)">
|
||||
<i class="fa fa-eye"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="new_password" class="block text-gray-700 text-sm font-medium mb-2">新密码</label>
|
||||
<div class="relative">
|
||||
<input type="password" id="new_password" name="new_password" class="w-full px-4 py-2 border border-gray-300 rounded-md input-focus transition-colors" placeholder="请输入新密码" required>
|
||||
<button type="button" class="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors" onclick="togglePasswordVisibility('new_password', this)">
|
||||
<i class="fa fa-eye"></i>
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">密码长度至少8位,包含字母和数字</p>
|
||||
</div>
|
||||
<div class="mb-6">
|
||||
<label for="confirm_password" class="block text-gray-700 text-sm font-medium mb-2">确认新密码</label>
|
||||
<div class="relative">
|
||||
<input type="password" id="confirm_password" name="confirm_password" class="w-full px-4 py-2 border border-gray-300 rounded-md input-focus transition-colors" placeholder="请再次输入新密码" required>
|
||||
<button type="button" class="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors" onclick="togglePasswordVisibility('confirm_password', this)">
|
||||
<i class="fa fa-eye"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex space-x-3">
|
||||
<button type="submit" class="flex-1 bg-primary hover:bg-primary-dark text-white py-2 px-4 rounded-md transition-colors shadow-sm hover:shadow">
|
||||
确认修改
|
||||
</button>
|
||||
<button type="button" onclick="window.location.href='{{ url_for('query') }}'" class="flex-1 border border-gray-300 text-gray-700 hover:bg-gray-50 py-2 px-4 rounded-md transition-colors">
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- 页脚 -->
|
||||
{% include 'footer.html' %}
|
||||
|
||||
<!-- JavaScript -->
|
||||
<script>
|
||||
// 密码可见性切换
|
||||
function togglePasswordVisibility(inputId, button) {
|
||||
const input = document.getElementById(inputId);
|
||||
const icon = button.querySelector('i');
|
||||
if (input.type === 'password') {
|
||||
input.type = 'text';
|
||||
icon.classList.remove('fa-eye');
|
||||
icon.classList.add('fa-eye-slash');
|
||||
} else {
|
||||
input.type = 'password';
|
||||
icon.classList.remove('fa-eye-slash');
|
||||
icon.classList.add('fa-eye');
|
||||
}
|
||||
}
|
||||
|
||||
// 表单提交处理
|
||||
document.getElementById('changePasswordForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault(); // 阻止默认提交
|
||||
layui.use(['form', 'layer'], function() {
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
|
||||
const newPassword = document.getElementById('new_password').value;
|
||||
const confirmPassword = document.getElementById('confirm_password').value;
|
||||
const oldPassword = document.getElementById('old_password').value;
|
||||
|
||||
// 前端验证
|
||||
if (!oldPassword) {
|
||||
alert('请输入旧密码');
|
||||
return;
|
||||
// 密码可见性切换功能
|
||||
function togglePasswordVisibility(inputId) {
|
||||
var input = document.getElementById(inputId);
|
||||
var icon = document.getElementById(inputId + '_icon');
|
||||
|
||||
if (input.type === 'password') {
|
||||
input.type = 'text';
|
||||
icon.classList.remove('fa-eye');
|
||||
icon.classList.add('fa-eye-slash');
|
||||
} else {
|
||||
input.type = 'password';
|
||||
icon.classList.remove('fa-eye-slash');
|
||||
icon.classList.add('fa-eye');
|
||||
}
|
||||
}
|
||||
|
||||
if (newPassword.length < 8 || !/[a-zA-Z]/.test(newPassword) || !/[0-9]/.test(newPassword)) {
|
||||
alert('新密码长度至少8位,且必须包含字母和数字');
|
||||
return;
|
||||
// 为输入框添加密码可见性切换图标
|
||||
function addPasswordToggleIcons() {
|
||||
var passwordInputs = document.querySelectorAll('input[type="password"]');
|
||||
passwordInputs.forEach(function(input) {
|
||||
var parent = input.parentElement;
|
||||
var toggleBtn = document.createElement('i');
|
||||
toggleBtn.id = input.id + '_icon';
|
||||
toggleBtn.className = 'fa fa-eye layui-icon layui-input-icon-right password-toggle-icon';
|
||||
toggleBtn.style.position = 'absolute';
|
||||
toggleBtn.style.right = '10px';
|
||||
toggleBtn.style.top = '50%';
|
||||
toggleBtn.style.transform = 'translateY(-50%)';
|
||||
toggleBtn.style.cursor = 'pointer';
|
||||
toggleBtn.style.color = '#999';
|
||||
|
||||
// 为容器添加相对定位
|
||||
parent.style.position = 'relative';
|
||||
|
||||
// 添加点击事件
|
||||
toggleBtn.addEventListener('click', function() {
|
||||
togglePasswordVisibility(input.id);
|
||||
});
|
||||
|
||||
// 检查是否已存在图标
|
||||
if (!document.getElementById(input.id + '_icon')) {
|
||||
parent.appendChild(toggleBtn);
|
||||
// 为输入框添加右侧内边距,防止文字被图标遮挡
|
||||
input.style.paddingRight = '30px';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (newPassword !== confirmPassword) {
|
||||
alert('两次输入的新密码不一致');
|
||||
return;
|
||||
}
|
||||
// 表单验证
|
||||
form.verify({
|
||||
password: [
|
||||
/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/,
|
||||
'密码长度至少8位,且必须包含字母和数字'
|
||||
]
|
||||
});
|
||||
|
||||
// 提交表单
|
||||
this.submit();
|
||||
// 表单提交处理
|
||||
form.on('submit(changePasswordForm)', function(data) {
|
||||
const newPassword = document.getElementById('new_password').value;
|
||||
const confirmPassword = document.getElementById('confirm_password').value;
|
||||
const oldPassword = document.getElementById('old_password').value;
|
||||
|
||||
// 前端验证
|
||||
if (!oldPassword) {
|
||||
layer.msg('请输入旧密码', {icon: 5});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newPassword.length < 8 || !/[a-zA-Z]/.test(newPassword) || !/[0-9]/.test(newPassword)) {
|
||||
layer.msg('新密码长度至少8位,且必须包含字母和数字', {icon: 5});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newPassword !== confirmPassword) {
|
||||
layer.msg('两次输入的新密码不一致', {icon: 5});
|
||||
return false;
|
||||
}
|
||||
|
||||
// 提交表单前的视觉反馈
|
||||
const submitButton = document.querySelector('button[type="submit"]');
|
||||
const originalText = submitButton.innerHTML;
|
||||
|
||||
submitButton.disabled = true;
|
||||
submitButton.innerHTML = '<i class="fa fa-spinner fa-spin mr-1"></i> 提交中...';
|
||||
|
||||
// 延迟提交以显示加载状态
|
||||
setTimeout(() => {
|
||||
document.getElementById('changePasswordForm').submit();
|
||||
}, 500);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// 页面加载完成后执行
|
||||
window.onload = function() {
|
||||
// 添加密码可见性切换图标
|
||||
addPasswordToggleIcons();
|
||||
|
||||
// 重新渲染表单
|
||||
form.render();
|
||||
};
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user