<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">

    <link href="/assets/css/dashboard.css" rel="stylesheet">
</head>
<body id="app">
<div class="main-container">
    <div class="welcome-card">
        <h2>
            <i class="bi bi-emoji-smile"></i>
            你好，{{ userInfo.realName || userInfo.username }}！
        </h2>
        <p class="mb-0 mt-2">欢迎使用 CoreWing 后台管理系统</p>
    </div>

    <div class="row">
        <div class="col-md-4 mb-4">
            <div class="stat-card primary">
                <i class="bi bi-people-fill"></i>
                <h3>1,234</h3>
                <p>用户数</p>
            </div>
        </div>
        <div class="col-md-4 mb-4">
            <div class="stat-card success">
                <i class="bi bi-file-earmark-text-fill"></i>
                <h3>567</h3>
                <p>设备数</p>
            </div>
        </div>
        <div class="col-md-4 mb-4">
            <div class="stat-card warning">
                <i class="bi bi-graph-up"></i>
                <h3>89%</h3>
                <p>固件数</p>
            </div>
        </div>
    </div>
</div>
<!-- Vue 3 -->
<script src="https://cdn.jsdelivr.net/npm/vue@3.3.4/dist/vue.global.prod.js"></script>

<!-- Axios -->
<script src="https://cdn.jsdelivr.net/npm/axios@1.4.0/dist/axios.min.js"></script>

<!-- Bootstrap 5 JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

<!-- 引入封装的 axiosRequest.js -->
<script src="/assets/js/axiosRequest.js"></script>
<script>
    const {createApp} = Vue;

    createApp({
        data() {
            return {
                userInfo: {
                    username: '',
                    realName: '',
                    userId: ''
                }
            }
        },
        methods: {
            async loadUserInfo() {
                // 从 localStorage 获取用户信息
                this.userInfo.username = localStorage.getItem('username') || '';
                this.userInfo.realName = localStorage.getItem('realName') || '';
                this.userInfo.userId = localStorage.getItem('userId') || '';
                const token = localStorage.getItem("token");
                if (token) {
                    try {
                        const response = await request.get('/sys/user/info');
                        if (response.code === 200) {
                            const user = response.data;
                            this.userInfo.username = user.username;
                            this.userInfo.realName = user.realName || user.username;
                            this.userInfo.userId = user.id;
                        }
                    } catch (error) {
                        console.error('获取用户信息失败:', error);
                    }
                }
            },
        },
        mounted() {
            // 加载用户信息
            this.loadUserInfo();
        }
    }).mount('#app');
</script>
</body>
</html>