李冠威 2 months ago
commit 25b7a9fe94

@ -746,6 +746,13 @@ def delete_user(user_id):
# 删除用户的所有游戏记录
GameHistory.query.filter_by(user_id=user_id).delete()
# 先删除与该用户相关的聊天室中的所有消息
# 查找该用户创建的所有聊天室
rooms_created_by_user = ChatRoom.query.filter_by(creator_id=user_id).all()
for room in rooms_created_by_user:
# 删除该聊天室中的所有消息
ChatMessage.query.filter_by(room_id=room.id).delete()
# 删除用户的所有聊天消息
ChatMessage.query.filter_by(user_id=user_id).delete()

File diff suppressed because one or more lines are too long

@ -110,43 +110,7 @@
</div>
</div>
<!-- 排行榜管理 -->
<div v-if="activeTab === 'leaderboard'" class="tab-content">
<h2>排行榜管理</h2>
<div class="leaderboard-actions">
<button @click="confirmResetAllScores" class="danger-btn">
重置所有分数
</button>
</div>
<div class="table-wrapper">
<table class="leaderboard-table">
<thead>
<tr>
<th>排名</th>
<th>用户名</th>
<th>最高分</th>
<th>最后游戏</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="(user, index) in leaderboard" :key="user.id">
<td>{{ index + 1 }}</td>
<td>{{ user.username }}</td>
<td>{{ user.high_score }}</td>
<td>{{ formatDate(user.last_login) }}</td>
<td class="actions">
<button @click="editUser(user)" class="edit-btn">编辑</button>
<button @click="resetUserScore(user.id)" class="reset-btn">
重置分数
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- 排行榜管理已移除 -->
<!-- 游戏历史管理 -->
<div v-if="activeTab === 'history'" class="tab-content">
@ -222,7 +186,6 @@ export default {
activeTab: 'users',
tabs: [
{ id: 'users', name: '用户管理' },
{ id: 'leaderboard', name: '排行榜管理' },
{ id: 'history', name: '游戏历史' }
],
@ -231,8 +194,6 @@ export default {
filteredUsers: [],
userSearchTerm: '',
//
leaderboard: [],
//
gameHistory: [],
@ -329,7 +290,6 @@ export default {
await Promise.all([
this.loadUsers(),
this.loadLeaderboard(),
this.loadGameHistory()
])
},
@ -360,37 +320,8 @@ export default {
this.loadUsers()
},
//
async loadLeaderboard() {
try {
const response = await axios.get('/api/leaderboard')
this.leaderboard = response.data.leaderboard
} catch (error) {
console.error('加载排行榜失败:', error)
}
},
async confirmResetAllScores() {
this.showConfirmDialog = true
this.confirmDialogTitle = '重置所有分数'
this.confirmDialogMessage = '确定要重置所有用户的分数吗?此操作不可撤销!'
this.confirmDialogAction = this.resetAllScores
},
async resetAllScores() {
try {
await axios.post('/api/admin/leaderboard/reset')
this.showConfirmDialog = false
//
await this.loadUsers()
await this.loadLeaderboard()
await this.loadGameHistory()
alert('所有分数已重置')
} catch (error) {
console.error('重置分数失败:', error)
alert('重置分数失败: ' + (error.response?.data?.error || '未知错误'))
}
},
//
async resetUserScore(userId) {
this.showConfirmDialog = true
this.confirmDialogTitle = '重置用户分数'
@ -402,7 +333,6 @@ export default {
//
await this.loadUsers()
await this.loadLeaderboard()
await this.loadGameHistory()
alert('用户分数已重置')
@ -483,7 +413,6 @@ export default {
//
await this.loadUsers()
await this.loadLeaderboard()
// localStorage
const userData = JSON.parse(localStorage.getItem('user'))
@ -544,7 +473,6 @@ export default {
//
await this.loadUsers()
await this.loadLeaderboard()
await this.loadGameHistory()
alert('用户已删除')

@ -2,9 +2,6 @@
<div class="login-container">
<div class="auth-form">
<h2>登录</h2>
<div class="admin-tip">
提示可使用管理员账户用户名: admin, 密码: admin
</div>
<div class="form-group">
<label for="username">用户名</label>
<input

Loading…
Cancel
Save