jiangchengfeiyi-Web/src/views/Login.vue

86 lines
2.9 KiB
Vue
Raw Normal View History

2024-10-23 09:55:22 +00:00
<template>
<div class="wrapper">
<div style="margin: 200px auto; background-color: #fff; width: 800px; height: 400px; border-radius: 10px">
<div >
<img
class="image"
style="height: 400px;width: 300px;float: left;"
src="../img/Login/login_top.png"
/>
</div>
<div style="height: 400px;width: 430px;float: left;margin:30px 0 0 40px;">
<div style="margin: 20px 0; text-align: center; font-size: 24px"><b>匠承非遗后台管理系统</b></div>
<el-form :model="user" ref="userForm">
<el-form-item prop="username">
<h2>账号</h2>
<el-input size="medium" style="margin: 10px 0" prefix-icon="el-icon-user" v-model="username"></el-input>
</el-form-item>
<el-form-item prop="password">
<h2>密码</h2>
<el-input size="medium" style="margin: 10px 0;" prefix-icon="el-icon-lock" show-password v-model="password"></el-input>
</el-form-item>
<div style="margin: 10px 0; text-align: right">
<div style="display: block;
2025-01-12 02:16:36 +00:00
font-size: 15px;
width: 80%;
margin: 50px auto 0 auto;
text-align: center;
border-radius: 20px;
background-color: rgb(172, 115, 82);
line-height: 40px;
" @click="Login">登录</div>
2024-10-23 09:55:22 +00:00
</div>
</el-form>
</div>
</div>
</div>
</template>
<script setup lang="ts">
2025-01-12 02:16:36 +00:00
import { ref } from 'vue'
2024-10-23 09:55:22 +00:00
import { ElMessage } from 'element-plus'
2025-01-12 02:16:36 +00:00
import { SuccessInfo, ErrorInfo, WarnInfo, CommInfo } from '@/utils/messageInfo';
2024-10-23 09:55:22 +00:00
import {useRouter} from 'vue-router'
2024-10-27 10:08:43 +00:00
import myAxios from '@/api/myAxios';
2024-10-27 10:51:02 +00:00
import { userStore } from '../store/userStore';
2024-10-23 09:55:22 +00:00
const user = ref({})
const username = ref('')
const password = ref('')
const router = useRouter()
2024-10-27 10:08:43 +00:00
const store = userStore()
2024-12-03 18:26:08 +00:00
2024-10-26 05:32:42 +00:00
const Login = async ()=>{
2024-12-08 02:40:37 +00:00
if(username.value === '' || password.value === '') {
2025-01-12 02:16:36 +00:00
ErrorInfo('检查账号或密码是否成功填写')
2024-12-08 02:40:37 +00:00
return;
}
2024-10-26 05:32:42 +00:00
const res: any = await myAxios.post("/user/login",{
userAccount: username.value,
userPassword: password.value
})
2025-01-12 02:16:36 +00:00
// console.log(res.data)
2024-10-26 05:32:42 +00:00
if(res.data.code === 1 && res ?.data) {
2025-01-12 02:16:36 +00:00
SuccessInfo('登陆成功')
2024-10-27 10:08:43 +00:00
//将用户信息放入pinia
2024-10-28 09:56:03 +00:00
await store.getLoginUser(res.data.data)
//跳转个人中心
2024-10-26 05:32:42 +00:00
await router.replace('/PersonalCenter')
2024-12-08 02:40:37 +00:00
} else {
2025-01-12 02:16:36 +00:00
WarnInfo(res.data.message)
2024-12-08 02:40:37 +00:00
return; //空返回结束函数
2024-10-26 05:32:42 +00:00
}
}
2024-10-23 09:55:22 +00:00
</script>
<style scoped>
.wrapper{
height: 100vh;
2025-03-06 00:50:58 +00:00
background-image:url(https://carbon2.obs.cn-north-4.myhuaweicloud.com:443/feiyi%2Ftest%2F0%2FzGMkHxQk-login.png);
2024-10-23 09:55:22 +00:00
background-size: 100% 100%;
background-repeat: no-repeat;
overflow: hidden;
}
</style>