2024-01-07 18:14:35 +08:00
|
|
|
|
<template>
|
2025-03-26 11:29:47 +08:00
|
|
|
|
<div class="login-bg">
|
2025-06-02 14:07:33 +08:00
|
|
|
|
<div class="login-container">
|
|
|
|
|
|
<div class="login-header">
|
|
|
|
|
|
<img class="logo mr10" src="../assets/img/logo.svg" alt="" />
|
|
|
|
|
|
<div class="login-title">综合系统</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-form :model="param" :rules="rules" ref="login" size="large">
|
|
|
|
|
|
<el-form-item prop="username">
|
|
|
|
|
|
<el-input v-model="param.username" placeholder="用户名或邮箱">
|
|
|
|
|
|
<template #prepend>
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<User />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="password">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
placeholder="密码"
|
|
|
|
|
|
v-model="param.password"
|
|
|
|
|
|
@keyup.enter="submitForm(login)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #prepend>
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Lock />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<!-- <div class="pwd-tips">
|
2025-03-26 11:29:47 +08:00
|
|
|
|
<el-checkbox class="pwd-checkbox" v-model="checked" label="记住密码" />
|
|
|
|
|
|
<el-link type="primary" @click="$router.push('/reset-pwd')">忘记密码</el-link>
|
|
|
|
|
|
</div> -->
|
2025-06-02 14:07:33 +08:00
|
|
|
|
<el-button
|
|
|
|
|
|
class="login-btn"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
@click="onLogin"
|
|
|
|
|
|
>登录</el-button
|
|
|
|
|
|
>
|
|
|
|
|
|
<!-- <p class="login-text">
|
2025-03-26 11:29:47 +08:00
|
|
|
|
没有账号?<el-link type="primary" @click="$router.push('/register')">立即注册</el-link>
|
|
|
|
|
|
</p> -->
|
2025-06-02 14:07:33 +08:00
|
|
|
|
</el-form>
|
|
|
|
|
|
</div>
|
2024-06-01 17:27:16 +08:00
|
|
|
|
</div>
|
2024-01-07 18:14:35 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-06-04 14:03:00 +08:00
|
|
|
|
import { ref, reactive, inject, onMounted } from "vue";
|
2025-06-02 14:07:33 +08:00
|
|
|
|
import { useRouter } from "vue-router";
|
|
|
|
|
|
import { ElMessage } from "element-plus";
|
|
|
|
|
|
import { loginService } from "@/api/user.js";
|
|
|
|
|
|
import { GetUserInfoService } from "@/api/user.js";
|
2024-06-10 12:29:23 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
// 从本地存储获取登录参数
|
2025-06-02 14:07:33 +08:00
|
|
|
|
const lgStr = localStorage.getItem("login-param");
|
2025-03-26 11:29:47 +08:00
|
|
|
|
const defParam = lgStr ? JSON.parse(lgStr) : null;
|
|
|
|
|
|
const globalData = inject("globalData");
|
|
|
|
|
|
// 记住密码状态
|
|
|
|
|
|
const checked = ref(lgStr ? true : false);
|
|
|
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
// 登录表单数据
|
|
|
|
|
|
const param = reactive({
|
2025-06-02 14:07:33 +08:00
|
|
|
|
username: defParam ? defParam.username : "",
|
|
|
|
|
|
password: defParam ? defParam.password : "",
|
2024-06-08 15:43:14 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-06-10 12:57:21 +08:00
|
|
|
|
onMounted(async () => {
|
2025-06-04 14:03:00 +08:00
|
|
|
|
// 保存登录参数到本地存储
|
2025-06-10 12:57:21 +08:00
|
|
|
|
let res = getMyUserInfo(localStorage.getItem("userId"));
|
|
|
|
|
|
if(res.code === 0){
|
|
|
|
|
|
// 如果已经登录,跳转到用户页面
|
|
|
|
|
|
router.push("/user");
|
|
|
|
|
|
}else{
|
|
|
|
|
|
window.location.href = "https://sv.ljsea.top/#/login?site=gs-vp"; //https://sv.ljsea.top/
|
|
|
|
|
|
}
|
2025-06-04 14:03:00 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
// 表单验证规则
|
2024-06-08 15:43:14 +08:00
|
|
|
|
const rules = {
|
|
|
|
|
|
username: [
|
2025-06-02 14:07:33 +08:00
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请输入用户名",
|
|
|
|
|
|
trigger: "blur",
|
|
|
|
|
|
},
|
2024-06-08 15:43:14 +08:00
|
|
|
|
],
|
2025-03-26 11:29:47 +08:00
|
|
|
|
password: [
|
2025-06-02 14:07:33 +08:00
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请输入密码",
|
|
|
|
|
|
trigger: "blur",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-06-08 15:43:14 +08:00
|
|
|
|
};
|
2025-03-26 11:29:47 +08:00
|
|
|
|
// 表单引用
|
|
|
|
|
|
const login = ref(null);
|
|
|
|
|
|
|
|
|
|
|
|
//表单数据
|
|
|
|
|
|
var loginData = ref({
|
2025-06-02 14:07:33 +08:00
|
|
|
|
username: "",
|
|
|
|
|
|
email: "",
|
|
|
|
|
|
password: "",
|
|
|
|
|
|
ip: "",
|
2024-06-08 15:43:14 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
//登录接口调用
|
|
|
|
|
|
const onLogin = async () => {
|
2025-06-02 14:07:33 +08:00
|
|
|
|
console.log("params:", param);
|
|
|
|
|
|
|
|
|
|
|
|
loginData.value.username = param.username;
|
|
|
|
|
|
loginData.value.password = param.password;
|
|
|
|
|
|
let result = await loginService(loginData);
|
|
|
|
|
|
console.log("login result:", result);
|
|
|
|
|
|
if (result.code !== 0) {
|
|
|
|
|
|
//alert(result.message);
|
|
|
|
|
|
ElMessage.error("登录失败!用户名或密码错误");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
globalData.token = result.data;
|
|
|
|
|
|
localStorage.setItem("token", result.data.access_token);
|
|
|
|
|
|
localStorage.setItem("userId", result.data.user_id);
|
|
|
|
|
|
localStorage.setItem("username", result.data.username);
|
2025-06-02 18:39:17 +08:00
|
|
|
|
localStorage.setItem("refresh_token", result.data.refresh_token);
|
|
|
|
|
|
|
2025-06-02 14:07:33 +08:00
|
|
|
|
await getMyUserInfo(result.data.user_id);
|
|
|
|
|
|
//token.value= result.data;
|
2024-06-08 15:43:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
const getMyUserInfo = async (id) => {
|
2025-06-02 14:07:33 +08:00
|
|
|
|
let result = {};
|
|
|
|
|
|
try {
|
|
|
|
|
|
let tokenData = {
|
|
|
|
|
|
token: localStorage.getItem("token"),
|
|
|
|
|
|
id: id,
|
|
|
|
|
|
};
|
|
|
|
|
|
result = await GetUserInfoService(tokenData);
|
|
|
|
|
|
if (result.code === 0) {
|
|
|
|
|
|
//console.log("token data:",this.tokenData)
|
|
|
|
|
|
localStorage.setItem("video_func", result.data.VideoFunc);
|
|
|
|
|
|
localStorage.setItem("device_func", result.data.DeviceFunc);
|
|
|
|
|
|
localStorage.setItem("cid_func", result.data.CIDFunc);
|
|
|
|
|
|
localStorage.setItem("role", result.data.Role);
|
|
|
|
|
|
//alert("video_func:" + localStorage.getItem("video_func")+" type:" +typeof(localStorage.getItem("video_func")));
|
2025-06-04 14:03:00 +08:00
|
|
|
|
router.push("/user");
|
2025-06-02 14:07:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e);
|
2024-11-07 21:06:00 +08:00
|
|
|
|
}
|
2025-06-10 12:57:21 +08:00
|
|
|
|
return result;
|
2024-06-08 15:43:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
// 获取标签存储并清空标签
|
|
|
|
|
|
</script>
|
2024-07-08 10:38:05 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
<style scoped>
|
|
|
|
|
|
.login-bg {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100vh;
|
|
|
|
|
|
/* background: url(../assets/img/login-bg.jpg) center/cover no-repeat; */
|
|
|
|
|
|
}
|
2024-06-08 15:43:14 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
.login-header {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
margin-bottom: 40px;
|
|
|
|
|
|
}
|
2024-06-08 15:43:14 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
.logo {
|
|
|
|
|
|
width: 35px;
|
|
|
|
|
|
}
|
2024-06-08 15:43:14 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
.login-title {
|
|
|
|
|
|
font-size: 22px;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
}
|
2024-06-08 15:43:14 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
.login-container {
|
|
|
|
|
|
width: 450px;
|
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
padding: 40px 50px 50px;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
}
|
2024-06-01 18:00:07 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
.pwd-tips {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
margin: -10px 0 10px;
|
|
|
|
|
|
color: #787878;
|
|
|
|
|
|
}
|
2024-12-04 20:02:00 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
.pwd-checkbox {
|
|
|
|
|
|
height: auto;
|
|
|
|
|
|
}
|
2024-12-04 20:20:43 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
.login-btn {
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
}
|
2024-12-04 20:02:00 +08:00
|
|
|
|
|
2025-03-26 11:29:47 +08:00
|
|
|
|
.login-tips {
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: #999;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-text {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: #787878;
|
2024-06-08 15:43:14 +08:00
|
|
|
|
}
|
2025-06-02 14:07:33 +08:00
|
|
|
|
</style>
|