20250918
This commit is contained in:
+53
-617
@@ -32,6 +32,9 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- 引入通用工具函数 -->
|
||||
<script src="{{ url_for('static', filename='js/utils.js') }}"></script>
|
||||
|
||||
<!-- 自定义工具类 -->
|
||||
<style type="text/tailwindcss">
|
||||
@layer utilities {
|
||||
@@ -65,48 +68,17 @@
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-secondary min-h-screen font-sans">
|
||||
<!-- 顶部导航栏 -->
|
||||
<header class="bg-white shadow-sm fixed top-0 left-0 right-0 z-10">
|
||||
<div class="container mx-auto px-4 py-3 flex justify-between items-center">
|
||||
<div class="flex items-center space-x-2">
|
||||
<i class="fa fa-car text-primary text-2xl"></i>
|
||||
<h1 class="text-xl font-bold text-gray-800">车主信息查询系统</h1>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<!-- 用户下拉菜单 -->
|
||||
<div class="relative group">
|
||||
<div class="flex items-center cursor-pointer hover:text-primary transition-colors">
|
||||
<span class="text-gray-600">欢迎 <strong>{{ session.department }}</strong> <strong>{{ session.name }}</strong></span>
|
||||
<i class="fa fa-chevron-down ml-2 text-xs transition-transform duration-300 group-hover:rotate-180"></i>
|
||||
</div>
|
||||
<!-- 下拉菜单 -->
|
||||
<div class="absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-300 transform origin-top-right scale-95 group-hover:scale-100 z-20">
|
||||
<div class="py-1">
|
||||
<a href="#" onclick="showChangePasswordModal()" class="block px-4 py-2 text-sm text-gray-700 hover:bg-primary hover:text-white transition-colors">
|
||||
<i class="fa fa-key mr-2"></i> 修改密码
|
||||
</a>
|
||||
<a href="{{ url_for('user.users_management') }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-primary hover:text-white transition-colors bg-primary/10">
|
||||
<i class="fa fa-users mr-2"></i> 用户管理
|
||||
</a>
|
||||
<a href="#" onclick="showUserProfileModal()" class="block px-4 py-2 text-sm text-gray-700 hover:bg-primary hover:text-white transition-colors">
|
||||
<i class="fa fa-user mr-2"></i> 个人信息
|
||||
</a>
|
||||
<a href="#" onclick="showLoginInfoModal()" class="block px-4 py-2 text-sm text-gray-700 hover:bg-primary hover:text-white transition-colors">
|
||||
<i class="fa fa-sign-in mr-2"></i> 后台登录信息
|
||||
</a>
|
||||
<div class="border-t border-gray-200 my-1"></div>
|
||||
<a href="{{ url_for('user.logout') }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-primary hover:text-white transition-colors">
|
||||
<i class="fa fa-sign-out mr-2"></i> 退出
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
{% 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="mb-6">
|
||||
<h2 class="text-2xl font-bold text-gray-800">用户管理</h2>
|
||||
@@ -197,6 +169,8 @@
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{% include 'footer.html' %}
|
||||
|
||||
<!-- 修改部门信息弹窗 -->
|
||||
<div id="editDepartmentModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
||||
<div class="bg-white rounded-lg shadow-xl w-full max-w-md mx-4 overflow-hidden transform transition-all animate-fade-in">
|
||||
@@ -271,177 +245,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 修改密码弹窗 -->
|
||||
<div id="changePasswordModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
||||
<div class="bg-white rounded-lg shadow-xl w-full max-w-md mx-4 overflow-hidden transform transition-all animate-fade-in">
|
||||
<div class="bg-primary text-white p-4 flex justify-between items-center">
|
||||
<h3 class="text-lg font-medium">修改密码</h3>
|
||||
<button onclick="closeChangePasswordModal()" class="text-white hover:text-gray-200 transition-colors">
|
||||
<i class="fa fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<!-- 错误信息显示区域 -->
|
||||
<div id="changePasswordError" class="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-md flex items-start hidden">
|
||||
<i class="fa fa-exclamation-circle mt-1 mr-3"></i>
|
||||
<span id="errorChangePasswordMessage"></span>
|
||||
</div>
|
||||
|
||||
<!-- 成功信息显示区域 -->
|
||||
<div id="changePasswordSuccess" class="mb-4 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-md flex items-start hidden">
|
||||
<i class="fa fa-check-circle mt-1 mr-3"></i>
|
||||
<span id="successChangePasswordMessage"></span>
|
||||
</div>
|
||||
|
||||
<form id="changePasswordForm">
|
||||
<div class="mb-4">
|
||||
<label for="old_password" class="block text-sm font-medium text-gray-700 mb-1">当前密码</label>
|
||||
<input type="password" id="old_password" class="w-full px-3 py-2 border border-gray-300 rounded-md input-focus">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="new_password" class="block text-sm font-medium text-gray-700 mb-1">新密码</label>
|
||||
<input type="password" id="new_password" class="w-full px-3 py-2 border border-gray-300 rounded-md input-focus">
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
<label for="confirm_password" class="block text-sm font-medium text-gray-700 mb-1">确认新密码</label>
|
||||
<input type="password" id="confirm_password" class="w-full px-3 py-2 border border-gray-300 rounded-md input-focus">
|
||||
</div>
|
||||
|
||||
<div class="flex space-x-4">
|
||||
<button type="submit" class="flex-1 bg-primary hover:bg-primary/90 text-white py-2 px-4 rounded-md transition-colors shadow-sm hover:shadow">
|
||||
保存修改
|
||||
</button>
|
||||
<button type="button" onclick="closeChangePasswordModal()" 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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 个人信息弹窗 -->
|
||||
<div id="userProfileModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
||||
<div class="bg-white rounded-lg shadow-xl w-full max-w-md mx-4 overflow-hidden transform transition-all animate-fade-in">
|
||||
<div class="bg-primary text-white p-4 flex justify-between items-center">
|
||||
<h3 class="text-lg font-medium">个人信息</h3>
|
||||
<button onclick="closeUserProfileModal()" class="text-white hover:text-gray-200 transition-colors">
|
||||
<i class="fa fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<!-- 错误信息显示区域 -->
|
||||
<div id="userProfileError" class="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-md flex items-start hidden">
|
||||
<i class="fa fa-exclamation-circle mt-1 mr-3"></i>
|
||||
<span id="errorUserProfileMessage"></span>
|
||||
</div>
|
||||
|
||||
<!-- 成功信息显示区域 -->
|
||||
<div id="userProfileSuccess" class="mb-4 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-md flex items-start hidden">
|
||||
<i class="fa fa-check-circle mt-1 mr-3"></i>
|
||||
<span id="successUserProfileMessage"></span>
|
||||
</div>
|
||||
|
||||
<form id="userProfileForm">
|
||||
<div class="mb-4">
|
||||
<label for="profile_username" class="block text-sm font-medium text-gray-700 mb-1">用户名</label>
|
||||
<input type="text" id="profile_username" readonly class="w-full px-3 py-2 border border-gray-300 rounded-md bg-gray-50 cursor-not-allowed">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="profile_name" class="block text-sm font-medium text-gray-700 mb-1">姓名</label>
|
||||
<input type="text" id="profile_name" class="w-full px-3 py-2 border border-gray-300 rounded-md input-focus">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="profile_phone" class="block text-sm font-medium text-gray-700 mb-1">电话</label>
|
||||
<input type="text" id="profile_phone" class="w-full px-3 py-2 border border-gray-300 rounded-md input-focus">
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
<label for="profile_department" class="block text-sm font-medium text-gray-700 mb-1">部门</label>
|
||||
<input type="text" id="profile_department" readonly class="w-full px-3 py-2 border border-gray-300 rounded-md bg-gray-50 cursor-not-allowed">
|
||||
</div>
|
||||
|
||||
<div class="flex space-x-4">
|
||||
<button type="submit" class="flex-1 bg-primary hover:bg-primary/90 text-white py-2 px-4 rounded-md transition-colors shadow-sm hover:shadow">
|
||||
保存修改
|
||||
</button>
|
||||
<button type="button" onclick="closeUserProfileModal()" 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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 后台登录信息弹窗 -->
|
||||
<div id="loginInfoModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
||||
<div class="bg-white rounded-lg shadow-xl w-full max-w-md mx-4 overflow-hidden transform transition-all animate-fade-in">
|
||||
<div class="bg-primary text-white p-4 flex justify-between items-center">
|
||||
<h3 class="text-lg font-medium">后台登录信息</h3>
|
||||
<button onclick="closeLoginInfoModal()" class="text-white hover:text-gray-200 transition-colors">
|
||||
<i class="fa fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<!-- 错误信息显示区域 -->
|
||||
<div id="loginInfoError" class="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-md flex items-start hidden">
|
||||
<i class="fa fa-exclamation-circle mt-1 mr-3"></i>
|
||||
<span id="errorLoginInfoMessage"></span>
|
||||
</div>
|
||||
|
||||
<!-- 成功信息显示区域 -->
|
||||
<div id="loginInfoSuccess" class="mb-4 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-md flex items-start hidden">
|
||||
<i class="fa fa-check-circle mt-1 mr-3"></i>
|
||||
<span id="successLoginInfoMessage"></span>
|
||||
</div>
|
||||
|
||||
<form id="loginInfoForm">
|
||||
<div class="bg-gray-50 p-4 rounded-md">
|
||||
<div class="grid grid-cols-1 gap-2 text-sm">
|
||||
<div class="text-gray-500 mb-1">登录用户名:</div>
|
||||
<input type="text" id="loginUsername" value="{{ session.username }}"
|
||||
{% if session.username != 'admin' %}readonly{% endif %}
|
||||
class="w-full px-3 py-2 border rounded-md text-gray-800 input-focus"
|
||||
{% if session.username != 'admin' %}style="background-color: #f3f4f6; cursor: not-allowed;"{% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-gray-50 p-4 rounded-md">
|
||||
<div class="grid grid-cols-1 gap-2 text-sm">
|
||||
<div class="text-gray-500 mb-1">用户密码:</div>
|
||||
<input type="password" id="loginPassword" value="" placeholder="{% if session.username == 'admin' %}输入新密码或保持为空不修改{% else %}只读,无法修改{% endif %}"
|
||||
{% if session.username != 'admin' %}readonly{% endif %}
|
||||
class="w-full px-3 py-2 border rounded-md text-gray-800 input-focus"
|
||||
{% if session.username != 'admin' %}style="background-color: #f3f4f6; cursor: not-allowed;"{% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-gray-50 p-4 rounded-md">
|
||||
<div class="grid grid-cols-1 gap-2 text-sm">
|
||||
<div class="text-gray-500 mb-1">OTP码:</div>
|
||||
<input type="text" id="loginOtpCode" value="{{ session.otp_code if 'otp_code' in session else '' }}"
|
||||
class="w-full px-3 py-2 border rounded-md text-gray-800 input-focus">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="mt-6 flex space-x-4">
|
||||
<button type="button" onclick="saveLoginInfo()" class="flex-1 bg-primary hover:bg-primary/90 text-white py-2 px-4 rounded-md transition-colors shadow-sm hover:shadow">
|
||||
保存修改
|
||||
</button>
|
||||
<button type="button" onclick="closeLoginInfoModal()" class="flex-1 border border-gray-300 text-gray-700 hover:bg-gray-50 py-2 px-4 rounded-md transition-colors">
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 用户管理相关JavaScript -->
|
||||
<script>
|
||||
// 当前页码和每页显示数量
|
||||
@@ -454,18 +257,6 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadUsers();
|
||||
|
||||
// 绑定修改密码表单提交事件
|
||||
document.getElementById('changePasswordForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
changePassword();
|
||||
});
|
||||
|
||||
// 绑定个人信息表单提交事件
|
||||
document.getElementById('userProfileForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
updateUserProfile();
|
||||
});
|
||||
|
||||
// 绑定搜索按钮点击事件
|
||||
document.getElementById('searchUsername').addEventListener('keypress', function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
@@ -487,24 +278,27 @@
|
||||
renderUsersTable();
|
||||
}
|
||||
});
|
||||
|
||||
// 绑定模态框点击外部关闭事件
|
||||
bindModalOutsideClick('editDepartmentModal');
|
||||
bindModalOutsideClick('resetPasswordModal');
|
||||
});
|
||||
|
||||
// 加载用户列表
|
||||
function loadUsers() {
|
||||
fetch('{{ url_for('user.get_users') }}')
|
||||
.then(response => response.json())
|
||||
apiRequest('{{ url_for('user.get_users') }}')
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
usersData = data.users;
|
||||
totalUsers = usersData.length;
|
||||
renderUsersTable();
|
||||
} else {
|
||||
showError('加载用户列表失败:' + (data.error || '未知错误'));
|
||||
showMessage('加载用户列表失败:' + (data.error || '未知错误'), false);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('加载用户列表时发生错误:', error);
|
||||
showError('网络错误,请稍后重试');
|
||||
showMessage('网络错误,请稍后重试', false);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -599,12 +393,12 @@
|
||||
currentPage = 1; // 重置到第一页
|
||||
renderUsersTable();
|
||||
} else {
|
||||
showError('搜索用户失败:' + (data.error || '未知错误'));
|
||||
showMessage('搜索用户失败:' + (data.error || '未知错误'), false);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('搜索用户时发生错误:', error);
|
||||
showError('网络错误,请稍后重试');
|
||||
showMessage('网络错误,请稍后重试', false);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -614,28 +408,25 @@
|
||||
const confirmMessage = `确定要${newStatus === 'active' ? '启用' : '禁用'}用户 ${username} 吗?`;
|
||||
|
||||
if (confirm(confirmMessage)) {
|
||||
fetch('{{ url_for('user.update_user_status') }}', {
|
||||
method: 'POST',
|
||||
apiRequest('{{ url_for('user.update_user_status') }}', 'POST', {
|
||||
user_id: userId,
|
||||
status: newStatus
|
||||
}, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user_id: userId,
|
||||
status: newStatus
|
||||
})
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
showSuccess(data.message || '用户状态更新成功');
|
||||
showMessage(data.message || '用户状态更新成功', true);
|
||||
loadUsers(); // 重新加载用户列表
|
||||
} else {
|
||||
showError(data.error || '用户状态更新失败');
|
||||
showMessage(data.error || '用户状态更新失败', false);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('更新用户状态时发生错误:', error);
|
||||
showError('网络错误,请稍后重试');
|
||||
showMessage('网络错误,请稍后重试', false);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -656,7 +447,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('editDepartmentModal').classList.remove('hidden');
|
||||
showModal('editDepartmentModal');
|
||||
}
|
||||
|
||||
// 关闭修改部门弹窗
|
||||
@@ -682,18 +473,18 @@
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
showSuccess(data.message || '部门信息更新成功');
|
||||
closeEditDepartmentModal();
|
||||
loadUsers(); // 重新加载用户列表
|
||||
} else {
|
||||
showError(data.error || '部门信息更新失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('更新部门信息时发生错误:', error);
|
||||
showError('网络错误,请稍后重试');
|
||||
});
|
||||
if (data.success) {
|
||||
showMessage(data.message || '部门信息更新成功', true);
|
||||
closeModal('editDepartmentModal');
|
||||
loadUsers(); // 重新加载用户列表
|
||||
} else {
|
||||
showMessage(data.error || '部门信息更新失败', false);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('更新部门信息时发生错误:', error);
|
||||
showMessage('网络错误,请稍后重试', false);
|
||||
});
|
||||
}
|
||||
|
||||
// 显示初始化密码弹窗
|
||||
@@ -727,379 +518,24 @@
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
showSuccess(data.message || '密码初始化成功');
|
||||
closeResetPasswordModal();
|
||||
} else {
|
||||
showError(data.error || '密码初始化失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('初始化密码时发生错误:', error);
|
||||
showError('网络错误,请稍后重试');
|
||||
});
|
||||
}
|
||||
|
||||
// 显示成功消息
|
||||
function showSuccess(message) {
|
||||
const messageContainer = document.getElementById('messageContainer');
|
||||
const successMessage = document.getElementById('successMessage');
|
||||
const errorMessage = document.getElementById('errorMessage');
|
||||
|
||||
successMessage.querySelector('span').textContent = message;
|
||||
successMessage.classList.remove('hidden');
|
||||
errorMessage.classList.add('hidden');
|
||||
messageContainer.classList.remove('hidden');
|
||||
|
||||
// 5秒后自动隐藏
|
||||
setTimeout(() => {
|
||||
successMessage.classList.add('hidden');
|
||||
messageContainer.classList.add('hidden');
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// 显示错误消息
|
||||
function showError(message) {
|
||||
const messageContainer = document.getElementById('messageContainer');
|
||||
const successMessage = document.getElementById('successMessage');
|
||||
const errorMessage = document.getElementById('errorMessage');
|
||||
|
||||
errorMessage.querySelector('span').textContent = message;
|
||||
errorMessage.classList.remove('hidden');
|
||||
successMessage.classList.add('hidden');
|
||||
messageContainer.classList.remove('hidden');
|
||||
|
||||
// 5秒后自动隐藏
|
||||
setTimeout(() => {
|
||||
errorMessage.classList.add('hidden');
|
||||
messageContainer.classList.add('hidden');
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// 修改密码相关函数
|
||||
function showChangePasswordModal() {
|
||||
document.getElementById('changePasswordModal').classList.remove('hidden');
|
||||
document.getElementById('old_password').focus();
|
||||
}
|
||||
|
||||
function closeChangePasswordModal() {
|
||||
document.getElementById('changePasswordModal').classList.add('hidden');
|
||||
// 重置表单
|
||||
document.getElementById('changePasswordForm').reset();
|
||||
}
|
||||
|
||||
function changePassword() {
|
||||
// 获取表单数据
|
||||
const oldPassword = document.getElementById('old_password').value;
|
||||
const newPassword = document.getElementById('new_password').value;
|
||||
const confirmPassword = document.getElementById('confirm_password').value;
|
||||
|
||||
// 隐藏之前的消息
|
||||
document.getElementById('changePasswordError').classList.add('hidden');
|
||||
document.getElementById('changePasswordSuccess').classList.add('hidden');
|
||||
|
||||
// 前端验证
|
||||
if (!oldPassword || !newPassword || !confirmPassword) {
|
||||
showChangePasswordError('请填写所有必填字段');
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPassword !== confirmPassword) {
|
||||
showChangePasswordError('两次输入的新密码不一致');
|
||||
return;
|
||||
}
|
||||
|
||||
// 异步提交修改
|
||||
fetch('{{ url_for('user.change_password') }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
'old_password': oldPassword,
|
||||
'new_password': newPassword,
|
||||
'confirm_password': confirmPassword
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// 修改成功
|
||||
showChangePasswordSuccess(data.message || '修改密码成功,请重新登录');
|
||||
|
||||
// 3秒后跳转登录页
|
||||
setTimeout(() => {
|
||||
window.location.href = '{{ url_for('user.login') }}';
|
||||
}, 3000);
|
||||
} else {
|
||||
// 显示错误信息
|
||||
showChangePasswordError(data.error || '修改密码失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('修改密码时发生错误:', error);
|
||||
showChangePasswordError('网络错误,请稍后重试');
|
||||
});
|
||||
}
|
||||
|
||||
function showChangePasswordError(message) {
|
||||
const errorContainer = document.getElementById('changePasswordError');
|
||||
const errorMessage = document.getElementById('errorChangePasswordMessage');
|
||||
errorMessage.textContent = message;
|
||||
errorContainer.classList.remove('hidden');
|
||||
document.getElementById('changePasswordSuccess').classList.add('hidden');
|
||||
// 滚动到错误信息
|
||||
errorContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
function showChangePasswordSuccess(message) {
|
||||
const successContainer = document.getElementById('changePasswordSuccess');
|
||||
const successMessage = document.getElementById('successChangePasswordMessage');
|
||||
successMessage.textContent = message;
|
||||
successContainer.classList.remove('hidden');
|
||||
document.getElementById('changePasswordError').classList.add('hidden');
|
||||
// 滚动到成功信息
|
||||
successContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
// 个人信息相关函数
|
||||
function showUserProfileModal() {
|
||||
// 获取个人信息
|
||||
fetch('{{ url_for('user.get_user_profile') }}')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const user = data.user;
|
||||
document.getElementById('profile_username').value = user.username;
|
||||
document.getElementById('profile_name').value = user.name;
|
||||
document.getElementById('profile_phone').value = user.phone;
|
||||
document.getElementById('profile_department').value = user.department;
|
||||
|
||||
document.getElementById('userProfileModal').classList.remove('hidden');
|
||||
showMessage(data.message || '密码初始化成功', true);
|
||||
closeModal('resetPasswordModal');
|
||||
} else {
|
||||
// 显示错误信息
|
||||
alert('获取个人信息失败:' + (data.error || '未知错误'));
|
||||
showMessage(data.error || '密码初始化失败', false);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取个人信息时发生错误:', error);
|
||||
alert('网络错误,请稍后重试');
|
||||
console.error('初始化密码时发生错误:', error);
|
||||
showMessage('网络错误,请稍后重试', false);
|
||||
});
|
||||
}
|
||||
|
||||
function closeUserProfileModal() {
|
||||
document.getElementById('userProfileModal').classList.add('hidden');
|
||||
// 隐藏之前的消息
|
||||
document.getElementById('userProfileError').classList.add('hidden');
|
||||
document.getElementById('userProfileSuccess').classList.add('hidden');
|
||||
}
|
||||
|
||||
function updateUserProfile() {
|
||||
// 获取表单数据
|
||||
const name = document.getElementById('profile_name').value.trim();
|
||||
const phone = document.getElementById('profile_phone').value.trim();
|
||||
|
||||
// 隐藏之前的消息
|
||||
document.getElementById('userProfileError').classList.add('hidden');
|
||||
document.getElementById('userProfileSuccess').classList.add('hidden');
|
||||
|
||||
// 前端验证
|
||||
if (!name || !phone) {
|
||||
showUserProfileError('请填写所有必填字段');
|
||||
return;
|
||||
}
|
||||
|
||||
// 异步提交修改
|
||||
fetch('{{ url_for('user.update_user_profile') }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
'name': name,
|
||||
'phone': phone
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// 更新成功
|
||||
showUserProfileSuccess(data.message || '个人信息更新成功');
|
||||
|
||||
// 3秒后关闭弹窗
|
||||
setTimeout(() => {
|
||||
closeUserProfileModal();
|
||||
// 刷新页面以更新会话信息
|
||||
location.reload();
|
||||
}, 1500);
|
||||
} else {
|
||||
// 显示错误信息
|
||||
showUserProfileError(data.error || '个人信息更新失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('更新个人信息时发生错误:', error);
|
||||
showUserProfileError('网络错误,请稍后重试');
|
||||
});
|
||||
}
|
||||
|
||||
function showUserProfileError(message) {
|
||||
const errorContainer = document.getElementById('userProfileError');
|
||||
const errorMessage = document.getElementById('errorUserProfileMessage');
|
||||
errorMessage.textContent = message;
|
||||
errorContainer.classList.remove('hidden');
|
||||
document.getElementById('userProfileSuccess').classList.add('hidden');
|
||||
// 滚动到错误信息
|
||||
errorContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
function showUserProfileSuccess(message) {
|
||||
const successContainer = document.getElementById('userProfileSuccess');
|
||||
const successMessage = document.getElementById('successUserProfileMessage');
|
||||
successMessage.textContent = message;
|
||||
successContainer.classList.remove('hidden');
|
||||
document.getElementById('userProfileError').classList.add('hidden');
|
||||
// 滚动到成功信息
|
||||
successContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
// 后台登录信息相关函数
|
||||
function showLoginInfoModal() {
|
||||
document.getElementById('loginInfoModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeLoginInfoModal() {
|
||||
document.getElementById('loginInfoModal').classList.add('hidden');
|
||||
// 隐藏之前的消息
|
||||
document.getElementById('loginInfoError').classList.add('hidden');
|
||||
document.getElementById('loginInfoSuccess').classList.add('hidden');
|
||||
}
|
||||
|
||||
function saveLoginInfo() {
|
||||
// 获取表单数据
|
||||
const username = document.getElementById('loginUsername').value.trim();
|
||||
const password = document.getElementById('loginPassword').value;
|
||||
const otpCode = document.getElementById('loginOtpCode').value.trim();
|
||||
|
||||
// 隐藏之前的消息
|
||||
document.getElementById('loginInfoError').classList.add('hidden');
|
||||
document.getElementById('loginInfoSuccess').classList.add('hidden');
|
||||
|
||||
// 前端验证
|
||||
if (!otpCode) {
|
||||
showLoginInfoError('OTP码不能为空');
|
||||
return;
|
||||
}
|
||||
|
||||
if (otpCode.length !== 6) {
|
||||
showLoginInfoError('OTP码长度必须是6位');
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果是admin用户修改密码,需要验证密码非空
|
||||
{% if session.username == 'admin' %}
|
||||
if (password === '') {
|
||||
showLoginInfoError('密码不能为空');
|
||||
return;
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
// 构建请求数据
|
||||
const data = {
|
||||
username: username,
|
||||
otp_code: otpCode
|
||||
};
|
||||
|
||||
// 如果admin用户提供了新密码,添加到请求数据中
|
||||
{% if session.username == 'admin' %}
|
||||
if (password) {
|
||||
data.password = password;
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
// 异步提交修改
|
||||
fetch('{{ url_for('user.update_login_info') }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// 更新成功
|
||||
showLoginInfoSuccess(data.message || '登录信息更新成功');
|
||||
// 更新session中的OTP码
|
||||
{% if 'session' in globals %}
|
||||
session['otp_code'] = otpCode;
|
||||
{% endif %}
|
||||
|
||||
// 3秒后关闭弹窗
|
||||
setTimeout(() => {
|
||||
closeLoginInfoModal();
|
||||
}, 1500);
|
||||
} else {
|
||||
// 显示服务器返回的错误信息
|
||||
showLoginInfoError(data.error || '登录信息更新失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('更新登录信息时发生错误:', error);
|
||||
showLoginInfoError('网络错误,请稍后重试');
|
||||
});
|
||||
}
|
||||
|
||||
function showLoginInfoError(message) {
|
||||
const errorContainer = document.getElementById('loginInfoError');
|
||||
const errorMessage = document.getElementById('errorLoginInfoMessage');
|
||||
errorMessage.textContent = message;
|
||||
errorContainer.classList.remove('hidden');
|
||||
document.getElementById('loginInfoSuccess').classList.add('hidden');
|
||||
// 滚动到错误信息
|
||||
errorContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
function showLoginInfoSuccess(message) {
|
||||
const successContainer = document.getElementById('loginInfoSuccess');
|
||||
const successMessage = document.getElementById('successLoginInfoMessage');
|
||||
successMessage.textContent = message;
|
||||
successContainer.classList.remove('hidden');
|
||||
document.getElementById('loginInfoError').classList.add('hidden');
|
||||
// 滚动到成功信息
|
||||
successContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
// 点击弹窗外部关闭弹窗
|
||||
document.getElementById('editDepartmentModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeEditDepartmentModal();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('resetPasswordModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeResetPasswordModal();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('changePasswordModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeChangePasswordModal();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('userProfileModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeUserProfileModal();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('loginInfoModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeLoginInfoModal();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user