修复bug
This commit is contained in:
@@ -301,70 +301,94 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAdminStore } from '@/stores/admin'
|
||||
import type { AdminMenu, AdminUser, SystemStats } from '@/types'
|
||||
import { adminAuth } from '@/utils/auth'
|
||||
import { useToast } from 'vue-toastification'
|
||||
|
||||
const router = useRouter()
|
||||
const adminStore = useAdminStore()
|
||||
const toast = useToast()
|
||||
|
||||
// 管理菜单
|
||||
const adminMenus = ref([
|
||||
{
|
||||
id: 1,
|
||||
name: '用户管理',
|
||||
description: '管理用户账号和权限',
|
||||
icon: 'UserIcon',
|
||||
route: '/admin/users'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: '账号管理',
|
||||
description: '管理网站账号和token',
|
||||
icon: 'KeyIcon',
|
||||
route: '/admin/accounts'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: '权限管理',
|
||||
description: '配置用户访问权限',
|
||||
icon: 'ShieldIcon',
|
||||
route: '/admin/permissions'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: '系统监控',
|
||||
description: '查看系统运行状态',
|
||||
icon: 'ChartIcon',
|
||||
route: '/admin/monitor'
|
||||
}
|
||||
])
|
||||
|
||||
// 统计数据
|
||||
const stats = ref({
|
||||
const adminUser = ref<AdminUser | null>(null)
|
||||
const stats = ref<SystemStats>({
|
||||
totalUsers: 0,
|
||||
totalAccounts: 0,
|
||||
todayVisits: 0,
|
||||
alerts: 0
|
||||
})
|
||||
|
||||
// 最近活动
|
||||
const recentActivities = ref([])
|
||||
const adminMenus: AdminMenu[] = [
|
||||
{
|
||||
id: 'users',
|
||||
name: '用户管理',
|
||||
description: '管理系统用户',
|
||||
icon: 'UserIcon',
|
||||
path: '/admin/users'
|
||||
},
|
||||
{
|
||||
id: 'accounts',
|
||||
name: '账号管理',
|
||||
description: '管理网站账号',
|
||||
icon: 'KeyIcon',
|
||||
path: '/admin/accounts'
|
||||
},
|
||||
{
|
||||
id: 'permissions',
|
||||
name: '权限管理',
|
||||
description: '配置访问权限',
|
||||
icon: 'ShieldIcon',
|
||||
path: '/admin/permissions'
|
||||
},
|
||||
{
|
||||
id: 'monitor',
|
||||
name: '系统监控',
|
||||
description: '监控系统状态',
|
||||
icon: 'ChartIcon',
|
||||
path: '/admin/monitor'
|
||||
}
|
||||
]
|
||||
|
||||
// 导航到菜单
|
||||
const navigateToMenu = (menu: any) => {
|
||||
router.push(menu.route)
|
||||
const navigateToMenu = (menu: AdminMenu) => {
|
||||
router.push(menu.path)
|
||||
}
|
||||
|
||||
// 管理员用户信息
|
||||
const adminUser = ref<any>(null)
|
||||
|
||||
// 退出登录
|
||||
const handleLogout = () => {
|
||||
adminAuth.logout()
|
||||
router.push('/admin/login')
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
await adminStore.logout()
|
||||
router.push('/admin/login')
|
||||
} catch (error) {
|
||||
console.error('退出登录失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载管理员信息
|
||||
const loadAdminInfo = async () => {
|
||||
try {
|
||||
// 从adminAuth获取管理员信息
|
||||
const adminInfo = adminAuth.getAdminInfo()
|
||||
if (adminInfo) {
|
||||
adminUser.value = adminInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载管理员信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载系统统计数据
|
||||
const loadStats = async () => {
|
||||
try {
|
||||
const response = await adminStore.getStats()
|
||||
if (response && response.stats) {
|
||||
stats.value = response.stats
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载系统统计失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 最近活动
|
||||
const recentActivities = ref<any[]>([])
|
||||
|
||||
// 格式化时间
|
||||
const formatTime = (time: string) => {
|
||||
const date = new Date(time)
|
||||
@@ -382,40 +406,6 @@ const formatTime = (time: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载统计数据
|
||||
const loadStats = async () => {
|
||||
try {
|
||||
console.log('开始加载统计数据...')
|
||||
const response = await adminStore.getStats()
|
||||
console.log('统计数据响应:', response)
|
||||
|
||||
if (response.success && response.data) {
|
||||
stats.value = response.data
|
||||
console.log('统计数据加载成功:', stats.value)
|
||||
} else {
|
||||
console.error('统计数据格式错误:', response)
|
||||
toast.error('统计数据格式错误')
|
||||
// 设置默认值
|
||||
stats.value = {
|
||||
totalUsers: 0,
|
||||
totalAccounts: 0,
|
||||
todayVisits: 0,
|
||||
alerts: 0
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载统计数据失败:', error)
|
||||
toast.error('加载统计数据失败')
|
||||
// 设置默认值
|
||||
stats.value = {
|
||||
totalUsers: 0,
|
||||
totalAccounts: 0,
|
||||
todayVisits: 0,
|
||||
alerts: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 加载最近活动
|
||||
const loadRecentActivities = async () => {
|
||||
try {
|
||||
@@ -423,50 +413,22 @@ const loadRecentActivities = async () => {
|
||||
const response = await adminStore.getRecentActivities()
|
||||
console.log('最近活动响应:', response)
|
||||
|
||||
if (response.success && response.data) {
|
||||
recentActivities.value = response.data.activities || []
|
||||
if (response && response.activities) {
|
||||
recentActivities.value = response.activities
|
||||
console.log('最近活动加载成功:', recentActivities.value)
|
||||
} else {
|
||||
console.error('最近活动数据格式错误:', response)
|
||||
toast.error('最近活动数据格式错误')
|
||||
recentActivities.value = []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载最近活动失败:', error)
|
||||
toast.error('加载最近活动失败')
|
||||
recentActivities.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载时获取数据
|
||||
onMounted(async () => {
|
||||
|
||||
// 检查管理员登录状态
|
||||
if (!adminAuth.isLoggedIn()) {
|
||||
router.push('/admin/login')
|
||||
return
|
||||
}
|
||||
|
||||
// 获取管理员用户信息
|
||||
const adminInfo = adminAuth.getAdminInfo()
|
||||
|
||||
if (!adminInfo) {
|
||||
// 如果没有管理员信息,清除登录状态并跳转到登录页
|
||||
adminAuth.logout()
|
||||
router.push('/admin/login')
|
||||
return
|
||||
}
|
||||
|
||||
adminUser.value = adminInfo
|
||||
|
||||
// 加载数据
|
||||
try {
|
||||
await Promise.all([
|
||||
loadStats(),
|
||||
loadRecentActivities()
|
||||
])
|
||||
} catch (error) {
|
||||
console.error('加载数据失败:', error)
|
||||
}
|
||||
await loadAdminInfo()
|
||||
await loadStats()
|
||||
await loadRecentActivities()
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user