2 changed files with 314 additions and 153 deletions
@ -0,0 +1,193 @@ |
|||
<template> |
|||
<div class="login-container"> |
|||
<!-- 背景图 --> |
|||
<div class="background-image"></div> |
|||
<!-- 登录表单 --> |
|||
<div class="login-form"> |
|||
<div class="login_logo"> |
|||
<img :src="logoSvg" class="logo_size"/> |
|||
<div class="company_name">长春黄金研究院有限公司</div> |
|||
</div> |
|||
<el-form> |
|||
<el-form-item label="账号"> |
|||
<el-input v-model="username" placehold="请输入用户名"> |
|||
<template #prefix> |
|||
<img :src="userIconSvg" class="icon" alt=""/> |
|||
</template> |
|||
</el-input> |
|||
</el-form-item> |
|||
<el-form-item label="密码"> |
|||
<el-input v-model="password" placehold="请输入密码"> |
|||
<template #prefix> |
|||
<img :src="pwdIconSvg" class="icon" alt=""/> |
|||
</template> |
|||
</el-input> |
|||
</el-form-item> |
|||
</el-form> |
|||
|
|||
<!-- 用户名输入框 --> |
|||
<!-- <div class="login-user-input">--> |
|||
<!-- <div class="user_name">用户名</div>--> |
|||
<!-- <img class="user_name_icon" :src="userIconSvg"/>--> |
|||
<!-- <input type="text" v-model="username" placeholder="用户名" class="input-field" />--> |
|||
<!-- </div>--> |
|||
<!-- <!– 密码输入框 –>--> |
|||
<!-- <div class="login-pwd-input">--> |
|||
<!-- <div class="user_name">密码</div>--> |
|||
<!-- <img class="pwd_icon" :src="pwdIconSvg"/>--> |
|||
<!-- <input type="password" v-model="password" placeholder="密码" class="input-field" />--> |
|||
<!-- </div>--> |
|||
<!-- 登录按钮 --> |
|||
<button @click="handleLogin" class="login-button">登录</button> |
|||
</div> |
|||
|
|||
</div> |
|||
</template> |
|||
|
|||
<script setup lang="ts"> |
|||
import { ref } from "vue"; |
|||
import { useRouter } from "vue-router"; |
|||
import { showToast } from "vant"; |
|||
import logoSvg from '@/assets/logo.svg' |
|||
import userIconSvg from '@/assets/user_icon.svg' |
|||
import pwdIconSvg from '@/assets/pwdw_icon.svg' |
|||
import { getCurrentUser, login, type User } from "@/services/user/userManager"; |
|||
import { useUserStore } from "@/stores/user"; |
|||
|
|||
const router = useRouter(); |
|||
// 定义用户名和密码的响应式变量 |
|||
const username = ref(""); |
|||
const password = ref(""); |
|||
|
|||
const userStore = useUserStore(); |
|||
// 处理登录的函数 |
|||
const handleLogin = async () => { |
|||
if(!username.value || !password.value){ |
|||
showToast('请输入用户名或密码!'); |
|||
return; |
|||
} |
|||
const res = await login({ username: username.value, password: password.value }); |
|||
if (res.success) { |
|||
sessionStorage.setItem("token", res.data); |
|||
const response = await getCurrentUser(); |
|||
if (response.success) { |
|||
const { username, nickname, role } = response.data; |
|||
userStore.setUser({ username, nickname, role } as User); |
|||
} |
|||
router.push("/home"); |
|||
} else { |
|||
showToast(res.msg); |
|||
} |
|||
}; |
|||
</script> |
|||
|
|||
<style lang="scss" scoped> |
|||
@use "@/assets/style/mixin.scss" as *; |
|||
.icon { |
|||
width: 20px; |
|||
} |
|||
.login-container { |
|||
position: relative; |
|||
width: 100vw; |
|||
height: 100vh; |
|||
overflow: hidden; |
|||
background: linear-gradient(180deg, rgba(250, 252, 255, 0.51) 0%, rgba(255, 255, 255, 0.52) 100%); |
|||
.login_logo{ |
|||
.logo_size{ |
|||
width: 2.875rem; |
|||
height: 2.875rem; |
|||
margin-top:2.875rem; |
|||
margin-left: 12rem; |
|||
} |
|||
.company_name{ |
|||
color: #8799AB; |
|||
font-size: 1.25rem; |
|||
margin-top:1.5rem; |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
.background-image { |
|||
position: absolute; |
|||
top: 0; |
|||
left: 0; |
|||
width: 100%; |
|||
height: 100%; |
|||
background-image: url('https://via.placeholder.com/1920x1080'); /* 替换为你自己的背景图 URL */ |
|||
background-size: cover; |
|||
background-position: center; |
|||
filter: blur(5px); |
|||
z-index: -1; |
|||
} |
|||
|
|||
.login-form { |
|||
position: absolute; |
|||
top: 50%; |
|||
left: 50%; |
|||
width:27.125rem; |
|||
transform: translate(-50%, -50%); |
|||
background-color: rgba(255, 255, 255, 0.8); |
|||
padding: 20px; |
|||
border-radius: 10px; |
|||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); |
|||
text-align: center; |
|||
} |
|||
|
|||
.input-field { |
|||
width:19.75rem; |
|||
height: 2.75rem; |
|||
border: 1px solid #ccc; |
|||
border-radius: 5px; |
|||
margin-left: 3.625rem; |
|||
padding-left: 1.625rem; |
|||
} |
|||
|
|||
.login-button { |
|||
width: 19.75rem; |
|||
height: 3rem; |
|||
background-color: #007bff; |
|||
color: white; |
|||
border: none; |
|||
border-radius: 5px; |
|||
cursor: pointer; |
|||
margin-top: 2rem; |
|||
margin-left: 2rem; |
|||
} |
|||
|
|||
|
|||
|
|||
.login-button:hover { |
|||
background-color: #0056b3; |
|||
} |
|||
|
|||
.login-user-input{ |
|||
width: 10.2rem; |
|||
margin-top: 3rem; |
|||
.user_name{ |
|||
color: #2C3E59; |
|||
font-size: 1rem; |
|||
|
|||
} |
|||
.user_name_icon{ |
|||
position: absolute; |
|||
margin-left: 4rem; |
|||
margin-top: 0.85rem; |
|||
width: 1.25rem; |
|||
height: 1.25rem; |
|||
} |
|||
} |
|||
|
|||
.login-pwd-input{ |
|||
width: 9.6rem; |
|||
margin-top: 2rem; |
|||
.pwd_icon{ |
|||
position: absolute; |
|||
margin-left: 4rem; |
|||
margin-top: 0.75rem; |
|||
width: 1.25rem; |
|||
height: 1.25rem; |
|||
} |
|||
} |
|||
|
|||
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue