Skip to content

Commit

Permalink
Update user-list.html
Browse files Browse the repository at this point in the history
  • Loading branch information
muskf authored Oct 3, 2024
1 parent d1c8d2a commit f7c32a0
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/main/resources/templates/dashboard/user-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="mdui-typo">
<h1>用户列表</h1>
<button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-red" onclick="removeExpiredUsers()">一键清除过期用户</button>
<button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-green" onclick="addDaysToAll()">发放补偿</button>
</div>
<div class="mdui-table-fluid">
<table class="mdui-table mdui-table-hoverable">
Expand Down Expand Up @@ -207,5 +208,52 @@ <h1>用户列表</h1>
}
);
}

function addDaysToAll() {
mdui.prompt('请输入要为所有用户增加的天数:', '批量增加天数',
function (value) {
let days = parseInt(value);
if (isNaN(days) || days <= 0) {
mdui.alert('请输入一个有效的正整数');
return;
}

fetch('/admin/listUsers', {
headers: {
'X-Admin-Password': adminPassword
}
})
.then(response => response.json())
.then(users => {
const promises = users
.filter(user => user.expire !== -1)
.map(user =>
fetch(`/admin/renew/${user.username}?day=${days}`, {
method: 'POST',
headers: {
'X-Admin-Password': adminPassword
},
})
);

return Promise.all(promises);
})
.then(() => {
mdui.alert(`已为所有非无限期用户增加 ${days} 天`);
fetchUserData(); // 重新加载用户列表
})
.catch(error => {
console.error('Error adding days to all users:', error);
mdui.alert('批量增加天数失败,请稍后再试');
});
},
function (value) {},
{
confirmText: '确认',
cancelText: '取消'
}
);
}

fetchUserData()
</script>

0 comments on commit f7c32a0

Please sign in to comment.