<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <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">

    <style>
        :root {
            --primary-color: #5B5FDE;
            --secondary-color: #0EA5E9;
            --accent-color: #FF6B6B;
            --error-color: #F43F5E;
            --success-color: #10B981;
            --warning-color: #F59E0B;
            --info-color: #3B82F6;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background: linear-gradient(135deg, #5B5FDE 0%, #0EA5E9 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            padding: 20px;
            position: relative;
            overflow: hidden;
        }

        /* 背景装饰圆圈 */
        body::before {
            content: '';
            position: absolute;
            width: 500px;
            height: 500px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            top: -200px;
            right: -200px;
            animation: float 6s ease-in-out infinite;
        }

        body::after {
            content: '';
            position: absolute;
            width: 300px;
            height: 300px;
            background: rgba(255, 255, 255, 0.08);
            border-radius: 50%;
            bottom: -100px;
            left: -100px;
            animation: float 8s ease-in-out infinite;
        }

        @keyframes float {
            0%, 100% { transform: translateY(0px) rotate(0deg); }
            50% { transform: translateY(-20px) rotate(5deg); }
        }

        .login-container {
            position: relative;
            z-index: 1;
            width: 100%;
            max-width: 1800px;
            display: flex;
            background: white;
            border-radius: 24px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
            overflow: hidden;
        }

        /* 左侧装饰区域 */
        .login-decoration {
            flex: 0.9;
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            padding: 60px 50px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            color: white;
            position: relative;
            overflow: hidden;
        }

        .login-decoration::before {
            content: '';
            position: absolute;
            width: 300px;
            height: 300px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            top: -80px;
            left: -80px;
        }

        .login-decoration::after {
            content: '';
            position: absolute;
            width: 220px;
            height: 220px;
            background: rgba(255, 255, 255, 0.08);
            border-radius: 50%;
            bottom: -60px;
            right: -60px;
        }

        .decoration-content {
            position: relative;
            z-index: 1;
            text-align: center;
        }

        .decoration-icon {
            font-size: 140px;
            margin-bottom: 40px;
            animation: pulse 2s ease-in-out infinite;
        }

        @keyframes pulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.05); }
        }

        .decoration-content h2 {
            font-size: 42px;
            font-weight: 700;
            margin-bottom: 20px;
            text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .decoration-content p {
            font-size: 18px;
            opacity: 0.95;
            line-height: 1.6;
        }

        /* 右侧表单区域 */
        .login-form-section {
            flex: 1.3;
            padding: 60px 120px;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .form-header {
            margin-bottom: 40px;
        }

        .form-header h3 {
            font-size: 32px;
            font-weight: 700;
            color: #1F2937;
            margin-bottom: 12px;
        }

        .form-header p {
            color: #6B7280;
            font-size: 16px;
        }

        .form-group {
            margin-bottom: 25px;
        }

        .form-label {
            display: block;
            font-size: 15px;
            font-weight: 600;
            color: #374151;
            margin-bottom: 8px;
        }

        .input-wrapper {
            position: relative;
        }

        .input-icon {
            position: absolute;
            left: 18px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--primary-color);
            font-size: 20px;
            z-index: 1;
        }

        .form-control {
            width: 100%;
            padding: 16px 18px 16px 52px;
            border: 2px solid #E5E7EB;
            border-radius: 12px;
            font-size: 16px;
            transition: all 0.3s;
            background-color: #F9FAFB;
        }

        .form-control:focus {
            outline: none;
            border-color: var(--primary-color);
            background-color: white;
            box-shadow: 0 0 0 4px rgba(91, 95, 222, 0.1);
        }

        .form-control::placeholder {
            color: #9CA3AF;
        }

        .btn-login {
            width: 100%;
            padding: 16px;
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            border: none;
            border-radius: 12px;
            color: white;
            font-size: 17px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 4px 15px rgba(91, 95, 222, 0.3);
        }

        .btn-login:hover:not(:disabled) {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(91, 95, 222, 0.4);
        }

        .btn-login:active:not(:disabled) {
            transform: translateY(0);
        }

        .btn-login:disabled {
            opacity: 0.7;
            cursor: not-allowed;
        }

        .alert {
            padding: 14px 18px;
            border-radius: 12px;
            margin-bottom: 20px;
            font-size: 15px;
            display: flex;
            align-items: center;
            gap: 10px;
            animation: slideDown 0.3s ease;
        }

        @keyframes slideDown {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .alert-success {
            background-color: #D1FAE5;
            color: var(--success-color);
            border: 1px solid var(--success-color);
        }

        .alert-danger {
            background-color: #FEE2E2;
            color: var(--error-color);
            border: 1px solid var(--error-color);
        }

        .alert i {
            font-size: 18px;
        }

        .login-footer {
            text-align: center;
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #E5E7EB;
        }

        .login-footer small {
            color: #6B7280;
            font-size: 14px;
        }

        .spinner-border {
            width: 1.2rem;
            height: 1.2rem;
            border-width: 2px;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .login-decoration {
                display: none;
            }

            .login-container {
                max-width: 450px;
            }

            .login-form-section {
                padding: 40px 30px;
            }
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="login-container">
            <!-- 左侧装饰区域 -->
            <div class="login-decoration">
                <div class="decoration-content">
                    <div class="decoration-icon">
                        <i class="bi bi-shield-lock-fill"></i>
                    </div>
                    <h2>CoreWing</h2>
                    <p>后台管理系统</p>
                    <p style="margin-top: 20px; opacity: 0.85;">
                        安全 · 高效 · 智能
                    </p>
                </div>
            </div>

            <!-- 右侧表单区域 -->
            <div class="login-form-section">
                <div class="form-header">
                    <h3>欢迎回来</h3>
                    <p>请登录您的账号以继续</p>
                </div>

                <!-- 提示消息 -->
                <div v-if="message.text" :class="'alert alert-' + message.type" role="alert">
                    <i :class="'bi bi-' + (message.type === 'success' ? 'check-circle-fill' : 'exclamation-circle-fill')"></i>
                    <span>{{ message.text }}</span>
                </div>

                <!-- 登录表单 -->
                <form @submit.prevent="handleLogin">
                    <div class="form-group">
                        <label class="form-label">用户名</label>
                        <div class="input-wrapper">
                            <i class="bi bi-person-fill input-icon"></i>
                            <input
                                type="text"
                                class="form-control"
                                v-model="loginForm.username"
                                placeholder="请输入用户名"
                                required
                                autocomplete="username">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="form-label">密码</label>
                        <div class="input-wrapper">
                            <i class="bi bi-lock-fill input-icon"></i>
                            <input
                                type="password"
                                class="form-control"
                                v-model="loginForm.password"
                                placeholder="请输入密码"
                                required
                                autocomplete="current-password">
                        </div>
                    </div>

                    <button
                        type="submit"
                        class="btn-login"
                        :disabled="loading">
                        <span v-if="loading">
                            <span class="spinner-border spinner-border-sm" role="status" style="margin-right: 8px;"></span>
                            登录中...
                        </span>
                        <span v-else>
                            <i class="bi bi-box-arrow-in-right" style="margin-right: 8px;"></i>
                            登录
                        </span>
                    </button>
                </form>

                <div class="login-footer">
                    <small>默认管理员账号：admin / admin123</small>
                </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>

    <script>
        const { createApp } = Vue;

        createApp({
            data() {
                return {
                    loginForm: {
                        username: '',
                        password: ''
                    },
                    loading: false,
                    message: {
                        text: '',
                        type: 'success' // success, danger
                    }
                }
            },
            methods: {
                async handleLogin() {
                    // 表单验证
                    if (!this.loginForm.username || !this.loginForm.password) {
                        this.showMessage('请填写完整的登录信息', 'danger');
                        return;
                    }

                    this.loading = true;
                    this.message.text = '';

                    try {
                        const response = await axios.post('/sys/user/login', this.loginForm);

                        if (response.data.code === 200) {
                            // 登录成功
                            this.showMessage('登录成功，正在跳转...', 'success');

                            // 保存 token 和用户信息
                            localStorage.setItem('token', response.data.data.token);
                            localStorage.setItem('userId', response.data.data.userId);
                            localStorage.setItem('username', response.data.data.username);
                            localStorage.setItem('realName', response.data.data.realName || '');

                            // 2秒后跳转到主页
                            setTimeout(() => {
                                window.location.href = '/admin/index.html';
                            }, 2000);
                        } else {
                            // 登录失败
                            this.showMessage(response.data.message || '登录失败', 'danger');
                        }
                    } catch (error) {
                        console.error('登录错误:', error);
                        this.showMessage(
                            error.response?.data?.message || '登录失败，请稍后重试',
                            'danger'
                        );
                    } finally {
                        this.loading = false;
                    }
                },

                showMessage(text, type) {
                    this.message.text = text;
                    this.message.type = type;

                    // 3秒后自动清除消息（错误消息）
                    if (type === 'danger') {
                        setTimeout(() => {
                            this.message.text = '';
                        }, 3000);
                    }
                }
            },
            mounted() {
                // 检查是否已登录
                const token = localStorage.getItem('token');
                if (token) {
                    // 如果已有 token，尝试跳转到主页
                    // window.location.href = '/admin/loading.html';
                }
            }
        }).mount('#app');
    </script>
</body>
</html>
