Login.vue 9.63 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
<template>
  <div class="login-container">
    <!-- 顶部装饰图标 - 左上角 -->
    <div class="top-icons">
      <img src="../assets/yd.png" alt="移动" class="top-icon" />
      <img src="../assets/cy.png" alt="创益" class="top-icon" />
    </div>

    <!-- 登录表单 - 靠左 -->
    <div class="login-form">
      <!-- Logo -->
      <div class="logo-section">
        <img src="../assets/logo.png" alt="Logo" class="logo" />
      </div>

      <div class="form-header">
        <h2>智能质检运营平台</h2>
      </div>

      <el-form :model="loginForm" :rules="rules" ref="loginFormRef" class="login-form-inner">
        <el-form-item prop="adminNum">
          <el-input
            v-model="loginForm.adminNum"
            placeholder="请输入账号"
            prefix-icon="User"
            size="large"
            class="custom-input"
          ></el-input>
        </el-form-item>

        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            type="password"
            placeholder="请输入密码"
            prefix-icon="Lock"
            show-password
            size="large"
            class="custom-input"
          ></el-input>
        </el-form-item>

        <el-form-item prop="captchaCode">
          <div class="captcha-wrapper">
            <el-input
              v-model="loginForm.captchaCode"
              placeholder="请输入验证码"
              prefix-icon="Key"
              size="large"
              class="custom-input captcha-input"
            ></el-input>
            <img :src="loginForm.code" @click="getCode" style="height: 45px;widht: 116px;">
          </div>
        </el-form-item>

        <el-form-item style="margin-top: 40px;">
          <el-button
            type="primary"
            size="large"
            style="width: 100%; height: 50px; font-size: 16px; border-radius: 25px;"
            @click="handleLogin"
            :loading="loading"
            class="login-btn"
          >
            登录
          </el-button>
        </el-form-item>

        <el-form-item style="text-align: right;">
          <el-button
            type="text"
            @click="handleForgetPassword"
            class="forgot-password"
          >
            忘记密码?
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { login , queryCode} from '../utils/api'
import suoImg from '../assets/suo.png'

const router = useRouter()
const loginFormRef = ref()
const loading = ref(false)
const currentCaptcha = ref('')

const loginForm = reactive({
  adminNum: 'huaihuayidong',
  password: 'Hhyd2025..',
  captchaCode: '',
  code: '',
  codeId: ''
})

// 验证码验证函数
const validateCaptcha = (rule, value, callback) => {
  if (!value) {
    callback(new Error('请输入验证码'))
  } else {
    callback()
  }
}

const rules = {
  adminNum: [
    { required: true, message: '请输入账号', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' }
  ],
  captchaCode: [
    { required: true, message: '请输入验证码', trigger: 'blur' },
    { validator: validateCaptcha, trigger: 'blur' }
  ]
}

const getCode = () => {
  queryCode().then(res => {
    if (res.code === 200) {
      loginForm.code = 'data:image/png;base64,'+res.data.img
      loginForm.codeId = res.data.codeId
    } else {
      ElMessage.error(res.message || '获取验证码失败');
    }
  }).catch(error => {
    ElMessage.error('请求验证码失败: ' + error.message);
  });
}
getCode()

const handleLogin = async () => {
  if (!loginFormRef.value) return

  await loginFormRef.value.validate(async (valid) => {
    if (valid) {
      loading.value = true
      try {
        const response = await login({
          adminNum: loginForm.adminNum,
          password: loginForm.password,
          captchaCode: loginForm.captchaCode, 
          codeId: loginForm.codeId
        })
        loading.value = false

        if (response.code === 200) {
          ElMessage.success('登录成功')
          // 保存token到localStorage
          localStorage.setItem('token', response.data.token)
          router.push('/upload')
        } else {
          ElMessage.error(response.msg || '登录失败')
        }
      } catch (error) {
        loading.value = false
        ElMessage.error('登录请求失败: ' + error.message)
      }
    }
  })
}

const handleForgetPassword = () => {
  ElMessageBox.alert(`
    <div style="text-align: center; padding: 20px;">
      <div style="margin-bottom: 15px;">
        <img src="${suoImg}" alt="锁" style="width: 64px; height: 64px;">
      </div>
      <div style="color: #333; font-size: 16px; font-weight: 500; margin-bottom: 10px;">
        忘记密码
      </div>
      <div style="color: #666; font-size: 14px; line-height: 1.5;">
        如需重置密码,请联系系统管理员
      </div>
    </div>
  `, '', {
    dangerouslyUseHTMLString: true,
    confirmButtonText: '确定',
    customClass: 'custom-alert-box'
  })
}
</script>

<style>
/* 确保页面没有边距 */
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>

<style scoped>
.login-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: url('../assets/bg.png') center/cover no-repeat;
  display: flex;
  align-items: center;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.top-icons {
  position: absolute;
  top: 30px;
  left: 30px;
  display: flex;
  gap: 20px;
  z-index: 10;
}

.top-icon {
  width: 126px;
  object-fit: contain;
}

.login-form {
  position: relative;
  width: 380px;
  margin-left: 80px;
  padding: 30px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  z-index: 10;
  animation: slideUp 0.6s ease-out;
}

.logo-section {
  text-align: center;
  margin-bottom: 20px;
}

.logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
}

.form-header {
  text-align: center;
  margin-bottom: 30px;
}

.form-header h2 {
  color: #333333;
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.login-form-inner {
  width: 100%;
}

.login-form-inner .el-form-item {
  margin-bottom: 20px;
}

.custom-input {
  background: #f5f5f5 !important;
  border: 1px solid #e0e0e0 !important;
  border-radius: 6px !important;
  transition: all 0.3s ease !important;
}

.custom-input:hover {
  background: #f9f9f9 !important;
  border-color: #d0d0d0 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.custom-input:deep(.el-input__wrapper) {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 15px;
}

.custom-input:deep(.el-input__inner) {
  color: #333;
  font-size: 16px;
  height: 45px;
}

.custom-input:deep(.el-input__inner::placeholder) {
  color: #666;
}

.captcha-wrapper {
  display: flex;
  gap: 10px;
  width: 100%;
  align-items: center;
}

.captcha-input {
  flex: 1;
}

.login-btn {
  background: #0068EE;
  border: none !important;
  font-weight: 600;
  letter-spacing: 1px;
  transition: all 0.3s ease !important;
}

.login-btn:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4) !important;
}

.login-btn:active {
  transform: translateY(0) !important;
}

.forgot-password {
  color: #666666 !important;
  font-size: 14px;
  transition: all 0.3s ease;
}

.forgot-password:hover {
  color: #409eff !important;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  .login-form {
    width: 90%;
    margin-left: 20px;
    padding: 25px 20px;
  }

  .top-icons {
    top: 20px;
    left: 20px;
  }

  .top-icon {
    width: 40px;
    height: 40px;
  }

  .logo {
    width: 60px;
    height: 60px;
  }

  .form-header h2 {
    font-size: 18px;
  }
}
</style>

<style>
/* 全局弹框样式 */
.custom-alert-box {
  border-radius: 8px !important;
  background: #ffffff !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
  border: 1px solid #e0e0e0 !important;
  overflow: hidden !important;
  max-width: 400px !important;
  width: 90% !important;
}

/* 隐藏头部 */
.custom-alert-box .el-message-box__header {
  display: none !important;
}

.custom-alert-box .el-message-box__content {
  padding: 0 !important;
  text-align: center !important;
}

.custom-alert-box .el-message-box__container {
  justify-content: center;
}

.custom-alert-box .el-message-box__message {
  padding: 30px 20px 20px !important;
  color: #333333 !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
  background: #ffffff !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
}

.custom-alert-box .el-message-box__btns {
  padding: 0 20px 30px !important;
  text-align: center !important;
  background: #ffffff !important;
  display: flex !important;
  justify-content: center !important;
}

.custom-alert-box .el-button {
  background: #409eff !important;
  border: 1px solid #409eff !important;
  border-radius: 4px !important;
  padding: 10px 30px !important;
  font-size: 14px !important;
  font-weight: 400 !important;
  color: #ffffff !important;
  min-width: 80px !important;
}



.custom-alert-box .el-button:hover {
  background: #66b1ff !important;
  border-color: #66b1ff !important;
}

.custom-alert-box .el-button:focus {
  background: #409eff !important;
  border-color: #409eff !important;
}
</style>