<template>
  <div class="login-container" :class="{ 'mobile-view': isMobile }">
    <div class="login-box">
      <div class="logo">
        <img class="logo-img" alt="格莱默打印系统" src="../../assets/imgs/logo.png" />
        <h2>格莱默打印系统</h2>
      </div>
      <!--      <p class="warning-text">禁止转借个人或他人账号</p>-->

      <div class="login-tabs">
        <span :class="{ active: activeTab === 'account' }" @click="activeTab = 'account'">
          账号登录
        </span>
        <span :class="{ active: activeTab === 'scan' }" @click="activeTab = 'scan'">
          飞书扫码
        </span>
      </div>

      <!-- 账号登录表单 -->
      <el-form class="login-form" v-if="activeTab === 'account'">
        <el-form-item>
          <el-input placeholder="kuikuiya 1020666" prefix-icon="User" />
        </el-form-item>
        <el-form-item>
          <el-input type="password" placeholder="用户密码" prefix-icon="Lock" />
        </el-form-item>
        <el-form-item class="verify-code-item">
          <div class="verify-code-input">
            <el-input placeholder="请输入验证码" style="width: 60%" />
            <span class="verify-code">zVYK</span>
          </div>
        </el-form-item>
        <el-form-item class="remember-me">
          <el-checkbox v-model="rememberMe">记住密码</el-checkbox>
          <a href="#" class="forgot-password">忘记密码</a>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="login-button">登 录</el-button>
        </el-form-item>
      </el-form>

      <!-- 飞书扫码登录 -->
      <div v-if="activeTab === 'scan'" class="scan-login">
        <p>请使用飞书扫描二维码登录</p>
        <div class="qr-code-placeholder"></div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue'

const activeTab = ref('account')
const rememberMe = ref(false)
const isMobile = ref(false)

// 响应式检测
const checkMobile = () => {
  isMobile.value = window.innerWidth <= 768
}

onMounted(() => {
  checkMobile()
  window.addEventListener('resize', checkMobile)
})

onBeforeUnmount(() => {
  window.removeEventListener('resize', checkMobile)
})
</script>

<style scoped>
/* 移动端优化 */
@media (width <= 768px) {
  .login-box {
    max-width: 350px;
    padding: 25px;
  }

  .login-tabs span {
    font-size: 14px;
  }
}

.login-container {
  display: flex;
  min-height: 100vh;
  padding: 20px;
  background: url('@/assets/imgs/login/lgbg.png') no-repeat center center;
  background-size: cover;
  transition: background 0.3s;
  justify-content: center;
  align-items: center;
}

/* 移动端样式 */
.mobile-view {
  background: none !important;
}

.login-box {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: rgb(255 255 255 / 90%);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgb(0 0 0 / 10%);
}

/* Logo样式 */
.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.logo-img {
  width: 48px;
  height: 48px;
  margin-right: 10px;
}

.logo h2 {
  margin: 0;
  color: #333;
}

/* 警告文本 */
.warning-text {
  margin-bottom: 30px;
  font-size: 12px;
  color: #999;
  text-align: center;
}

/* Tab切换 */
.login-tabs {
  display: flex;
  margin-bottom: 20px;
}

.login-tabs span {
  padding: 8px 0;
  color: #666;
  text-align: center;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  flex: 1;
}

.login-tabs span.active {
  color: #409eff;
  border-bottom-color: #409eff;
}

/* 表单样式 */
.verify-code-input {
  display: flex;
  align-items: center;
  gap: 10px;
}

.verify-code {
  width: 80px;
  padding: 8px;
  font-weight: bold;
  text-align: center;
  background: #f5f7fa;
  border-radius: 4px;
  flex-shrink: 0;
}

.remember-me {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.forgot-password {
  font-size: 12px;
  color: #409eff;
  text-decoration: none;
}

.login-button {
  width: 100%;
}

/* 扫码登录样式 */
.qr-code-placeholder {
  display: flex;
  height: 200px;
  margin-top: 20px;
  color: #999;
  background: #f5f7fa;
  border-radius: 4px;
  align-items: center;
  justify-content: center;
}

/* 基础样式 */
</style>
