117 lines
3.5 KiB
HTML
117 lines
3.5 KiB
HTML
<style>
|
|
body {
|
|
background-color: #f5f5f5;
|
|
}
|
|
.layui-container {
|
|
width: 100% !important;
|
|
padding: 20px;
|
|
background-color: #ffffff;
|
|
}
|
|
h2 {
|
|
color: #333;
|
|
font-size: 24px;
|
|
}
|
|
.layui-table {
|
|
width: 100%;
|
|
margin-top: 20px;
|
|
}
|
|
.layui-table tbody tr:nth-child(odd) {
|
|
background-color: #f9f9f9;
|
|
}
|
|
.layui-table tbody tr:nth-child(even) {
|
|
background-color: #eaf6f6;
|
|
}
|
|
.stats-container {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-top: 20px;
|
|
}
|
|
.stats-container p {
|
|
margin: 0 20px;
|
|
font-size: 14px;
|
|
}
|
|
.stats-container span {
|
|
color: #2de5cf;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="layui-container">
|
|
<h2>用户列表</h2>
|
|
|
|
<table id="userTable" lay-filter="userTable"></table>
|
|
|
|
<div class="stats-container">
|
|
<p>总用户数量: <span id="totalCount">0</span></p>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
layui.use(['jquery', 'table', 'layer'], function() {
|
|
const $ = layui.jquery;
|
|
const table = layui.table;
|
|
const layer = layui.layer;
|
|
|
|
// 加载用户列表
|
|
function loadUserList() {
|
|
table.render({
|
|
elem: '#userTable',
|
|
url: '/custom_admin/home/user-list/',
|
|
method: 'post',
|
|
page: true, // 开启分页
|
|
limit: 10, // 每页显示的数量
|
|
cols: [[
|
|
{field: 'username', title: '用户名', width: '15%'},
|
|
{field: 'phone', title: '手机号', width: '15%'},
|
|
{field: 'email', title: '邮箱', width: '15%'},
|
|
{field: 'points', title: '积分', width: '10%'},
|
|
{field: 'created_at', title: '注册时间', width: '15%'},
|
|
{field: 'login_count', title: '登录次数', width: '10%'},
|
|
{field: 'source', title: '来源', width: '10%'},
|
|
{title: '操作', width: '10%', toolbar: '#actionToolbar'}
|
|
]],
|
|
done: function(res) {
|
|
$('#totalCount').text(res.count); // 更新总用户数
|
|
}
|
|
});
|
|
}
|
|
|
|
// 删除用户功能
|
|
table.on('tool(userTable)', function(obj) {
|
|
const data = obj.data;
|
|
const layEvent = obj.event;
|
|
|
|
if (layEvent === 'delete') {
|
|
deleteUser(data.id);
|
|
}
|
|
});
|
|
|
|
function deleteUser(id) {
|
|
layer.confirm('确定删除该用户吗?', function(index) {
|
|
axios.delete(`/api/delete-user/${id}/`)
|
|
.then(res => {
|
|
if (res.data.code === 200) {
|
|
layer.msg('删除成功');
|
|
loadUserList();
|
|
} else {
|
|
layer.msg('删除失败: ' + res.data.message);
|
|
}
|
|
})
|
|
.catch(() => {
|
|
layer.msg('请求失败');
|
|
});
|
|
layer.close(index);
|
|
});
|
|
}
|
|
|
|
loadUserList();
|
|
});
|
|
</script>
|
|
|
|
<script type="text/html" id="actionToolbar">
|
|
<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">删除</button>
|
|
</script>
|
|
|
|
|