初始化v1
This commit is contained in:
163
target/classes/templates/merchant/users.html
Normal file
163
target/classes/templates/merchant/users.html
Normal file
@@ -0,0 +1,163 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>用户管理 - 商家后台</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/merchant/dashboard.html">
|
||||
<i class="bi bi-shop"></i> 商家后台
|
||||
</a>
|
||||
<div class="navbar-nav ms-auto">
|
||||
<a class="nav-link" href="/merchant/dashboard.html">首页</a>
|
||||
<a class="nav-link" href="/merchant/products.html">商品管理</a>
|
||||
<a class="nav-link" href="/merchant/orders.html">订单管理</a>
|
||||
<a class="nav-link" href="/merchant/inventory.html">库存管理</a>
|
||||
<a class="nav-link" href="/merchant/statistics.html">数据统计</a>
|
||||
<a class="nav-link" href="/merchant/announcements.html">公告管理</a>
|
||||
<a class="nav-link" href="/merchant/messages.html">留言管理</a>
|
||||
<a class="nav-link" href="/merchant/reviews.html">评价管理</a>
|
||||
<a class="nav-link active" href="/merchant/users.html">用户管理</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container mt-4 mb-5">
|
||||
<h2 class="mb-4"><i class="bi bi-people"></i> 用户管理</h2>
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div id="usersList"></div>
|
||||
<nav aria-label="用户列表分页">
|
||||
<ul class="pagination justify-content-center" id="pagination"></ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="/static/js/sidebar-replacer.js"></script>
|
||||
<script>
|
||||
// 检查登录状态
|
||||
async function checkLogin() {
|
||||
try {
|
||||
const response = await fetch('/merchant/profile', {
|
||||
credentials: 'include'
|
||||
});
|
||||
const data = await response.json();
|
||||
if (data.code !== 200 || !data.data) {
|
||||
window.location.href = '/merchant/login.html';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
window.location.href = '/merchant/login.html';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let currentPage = 1;
|
||||
const pageSize = 10;
|
||||
|
||||
// 页面加载
|
||||
checkLogin().then(isLoggedIn => {
|
||||
if (isLoggedIn) {
|
||||
loadUsers(1);
|
||||
}
|
||||
});
|
||||
|
||||
// 加载用户列表
|
||||
async function loadUsers(pageNum) {
|
||||
try {
|
||||
currentPage = pageNum;
|
||||
const response = await fetch(`/merchant/users?pageNum=${pageNum}&pageSize=${pageSize}`, {
|
||||
credentials: 'include'
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
const container = document.getElementById('usersList');
|
||||
const pagination = document.getElementById('pagination');
|
||||
|
||||
if (data.code === 200 && data.data) {
|
||||
const pageResponse = data.data;
|
||||
const users = pageResponse.list || [];
|
||||
|
||||
if (users.length === 0) {
|
||||
container.innerHTML = '<div class="alert alert-info">暂无用户</div>';
|
||||
pagination.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>用户名</th>
|
||||
<th>姓名</th>
|
||||
<th>手机号</th>
|
||||
<th>邮箱</th>
|
||||
<th>注册时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${users.map(user => `
|
||||
<tr>
|
||||
<td><strong>${user.username || '-'}</strong></td>
|
||||
<td>${user.name || '-'}</td>
|
||||
<td>${user.phone || '-'}</td>
|
||||
<td>${user.email || '-'}</td>
|
||||
<td>${user.createTime ? new Date(user.createTime).toLocaleString('zh-CN') : '-'}</td>
|
||||
</tr>
|
||||
`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// 生成分页
|
||||
const totalPages = pageResponse.pages || 1;
|
||||
let paginationHtml = '';
|
||||
|
||||
// 上一页
|
||||
paginationHtml += `<li class="page-item ${currentPage === 1 ? 'disabled' : ''}">
|
||||
<a class="page-link" href="javascript:void(0)" onclick="loadUsers(${currentPage - 1})">上一页</a>
|
||||
</li>`;
|
||||
|
||||
// 页码
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
if (i === 1 || i === totalPages || (i >= currentPage - 2 && i <= currentPage + 2)) {
|
||||
paginationHtml += `<li class="page-item ${i === currentPage ? 'active' : ''}">
|
||||
<a class="page-link" href="javascript:void(0)" onclick="loadUsers(${i})">${i}</a>
|
||||
</li>`;
|
||||
} else if (i === currentPage - 3 || i === currentPage + 3) {
|
||||
paginationHtml += `<li class="page-item disabled">
|
||||
<span class="page-link">...</span>
|
||||
</li>`;
|
||||
}
|
||||
}
|
||||
|
||||
// 下一页
|
||||
paginationHtml += `<li class="page-item ${currentPage === totalPages ? 'disabled' : ''}">
|
||||
<a class="page-link" href="javascript:void(0)" onclick="loadUsers(${currentPage + 1})">下一页</a>
|
||||
</li>`;
|
||||
|
||||
pagination.innerHTML = paginationHtml;
|
||||
} else {
|
||||
container.innerHTML = '<div class="alert alert-warning">加载用户列表失败:' + (data.message || '未知错误') + '</div>';
|
||||
pagination.innerHTML = '';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
document.getElementById('usersList').innerHTML = '<div class="alert alert-danger">加载用户列表失败,请刷新页面重试</div>';
|
||||
document.getElementById('pagination').innerHTML = '';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user