2025-03-19 15:09:01 +08:00
|
|
|
|
<template>
|
2025-03-19 20:01:03 +08:00
|
|
|
|
<div class="login-bg">
|
|
|
|
|
|
<div class="login-container">
|
|
|
|
|
|
<div class="login-header">
|
|
|
|
|
|
<img class="logo mr10" src="../../assets/img/logo.svg" alt="" />
|
2025-06-10 12:59:48 +08:00
|
|
|
|
<div class="login-title">统一登录平台</div>
|
2025-03-19 20:01:03 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<el-form :model="param" :rules="rules" ref="login" size="large">
|
2025-09-27 13:36:35 +08:00
|
|
|
|
<template v-if="login_type === 'pwd'">
|
2025-03-19 20:01:03 +08:00
|
|
|
|
<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"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #prepend>
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Lock />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<div class="pwd-tips">
|
|
|
|
|
|
<el-checkbox
|
|
|
|
|
|
class="pwd-checkbox"
|
|
|
|
|
|
v-model="checked"
|
|
|
|
|
|
label="记住密码"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<el-link type="primary" @click="$router.push('/reset-pwd')"
|
|
|
|
|
|
>忘记密码</el-link
|
|
|
|
|
|
>
|
2025-09-27 13:36:35 +08:00
|
|
|
|
<el-link type="primary" @click="toggleLoginType"
|
|
|
|
|
|
>验证码登录</el-link
|
|
|
|
|
|
>
|
2025-03-19 15:09:01 +08:00
|
|
|
|
</div>
|
2025-09-27 13:36:35 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<!-- 邮箱验证码登录表单(切换后显示) -->
|
|
|
|
|
|
<template v-else>
|
|
|
|
|
|
<!-- 邮箱输入 -->
|
|
|
|
|
|
<el-form-item prop="email">
|
|
|
|
|
|
<el-input v-model="code_login_form.email" placeholder="请输入邮箱">
|
|
|
|
|
|
<template #prepend>
|
|
|
|
|
|
<el-icon><Message /></el-icon>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<!-- 验证码输入 + 发送按钮 -->
|
|
|
|
|
|
<el-form-item prop="code">
|
|
|
|
|
|
<el-input v-model="code_login_form.code" placeholder="请输入验证码">
|
|
|
|
|
|
<template #prepend>
|
|
|
|
|
|
<el-icon><VerificationCode /></el-icon>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template #append>
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
:disabled="countdown > 0"
|
|
|
|
|
|
@click="sendCode"
|
|
|
|
|
|
class="code-btn"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ countdown > 0 ? `${countdown}s后重发` : "发送验证码" }}
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<!-- 切换链接(无记住密码) -->
|
|
|
|
|
|
<div class="pwd-tips">
|
|
|
|
|
|
<el-link type="primary" @click="toggleLoginType"
|
|
|
|
|
|
>密码登录</el-link>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
2025-03-19 20:01:03 +08:00
|
|
|
|
<el-button
|
|
|
|
|
|
class="login-btn"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
@click="onLogin"
|
|
|
|
|
|
>登录</el-button
|
|
|
|
|
|
>
|
|
|
|
|
|
<p class="login-text">
|
|
|
|
|
|
没有账号?<el-link type="primary" @click="$router.push('/register')"
|
|
|
|
|
|
>立即注册</el-link
|
|
|
|
|
|
>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</el-form>
|
2025-04-27 13:09:57 +08:00
|
|
|
|
<div>
|
2025-04-28 15:37:10 +08:00
|
|
|
|
<!-- 第三登录 -->
|
|
|
|
|
|
<el-divider content-position="center">第三方登录</el-divider>
|
|
|
|
|
|
<div class="login-text">
|
2025-04-30 16:56:07 +08:00
|
|
|
|
<el-row :gutter="12" >
|
|
|
|
|
|
<!-- thirdPartyLogoInfoList -->
|
|
|
|
|
|
<template v-for="(item, index) in thirdPartyLogoInfoList" :key="index">
|
|
|
|
|
|
<el-col :span="8">
|
2025-05-17 16:03:42 +08:00
|
|
|
|
<el-tooltip :content="item.label" placement="top">
|
|
|
|
|
|
<img :src="item.logo" alt="" @click="thirdLogin(item.name)" />
|
|
|
|
|
|
</el-tooltip>
|
2025-04-30 16:56:07 +08:00
|
|
|
|
</el-col>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-28 15:37:10 +08:00
|
|
|
|
</el-row>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-03-19 15:09:01 +08:00
|
|
|
|
</div>
|
2025-03-19 20:01:03 +08:00
|
|
|
|
</div>
|
2025-03-19 15:09:01 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
2025-03-27 17:33:35 +08:00
|
|
|
|
<script setup lang="ts">
|
2025-09-27 13:36:35 +08:00
|
|
|
|
import { ref, reactive, inject, onMounted, h } from "vue";
|
2025-06-10 12:59:48 +08:00
|
|
|
|
import { useRouter,useRoute } from "vue-router";
|
2025-03-19 20:01:03 +08:00
|
|
|
|
import { ElMessage } from "element-plus";
|
|
|
|
|
|
import { loginService } from "@/api/user";
|
|
|
|
|
|
import { GetUserInfoService } from "@/api/user";
|
2025-05-24 20:16:47 +08:00
|
|
|
|
import { UserToken } from "@/types/user";
|
2025-10-01 14:27:41 +08:00
|
|
|
|
import { getBrowserFingerprint,getStoredFingerprint } from "@/utils/fingerprint";
|
2025-03-19 20:01:03 +08:00
|
|
|
|
import { usePermissStore } from "@/store/permiss";
|
2025-05-24 20:16:47 +08:00
|
|
|
|
import Cookies from 'js-cookie';
|
2025-09-27 13:36:35 +08:00
|
|
|
|
import {getThirdPartyUUID,getThirdPartyLoginStatus,getThirdPartyLoginUrl,sendLoginCode, loginByCode} from "@/api/user";
|
2025-10-01 14:27:41 +08:00
|
|
|
|
import { log, time } from "console";
|
|
|
|
|
|
import { pa } from "element-plus/es/locale";
|
2025-03-19 15:09:01 +08:00
|
|
|
|
// 从本地存储获取登录参数
|
2025-03-19 20:01:03 +08:00
|
|
|
|
const lgStr = localStorage.getItem("login-param");
|
2025-03-19 15:09:01 +08:00
|
|
|
|
const defParam = lgStr ? JSON.parse(lgStr) : null;
|
|
|
|
|
|
const globalData = inject("globalData");
|
|
|
|
|
|
const permiss = usePermissStore();
|
|
|
|
|
|
// 记住密码状态
|
|
|
|
|
|
const checked = ref(lgStr ? true : false);
|
2025-09-27 13:36:35 +08:00
|
|
|
|
const login_type = ref("pwd"); //登录方式 pwd:密码登录 qr:扫码登录
|
|
|
|
|
|
const countdown = ref(0); //倒计时
|
2025-03-19 15:09:01 +08:00
|
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
2025-06-10 12:59:48 +08:00
|
|
|
|
const route = useRoute();
|
2025-03-19 15:09:01 +08:00
|
|
|
|
// 登录表单数据
|
|
|
|
|
|
const param = reactive({
|
2025-03-19 20:01:03 +08:00
|
|
|
|
username: defParam ? defParam.username : "",
|
|
|
|
|
|
password: defParam ? defParam.password : "",
|
2025-10-01 14:27:41 +08:00
|
|
|
|
fingerprint: '' // 浏览器指纹
|
2025-03-19 15:09:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-27 13:36:35 +08:00
|
|
|
|
//验证码登录表单数据
|
|
|
|
|
|
const code_login_form = ref({
|
|
|
|
|
|
email: '',
|
|
|
|
|
|
code: '',
|
|
|
|
|
|
login_type: 1, // 1: 邮箱验证码登录 2: 手机验证码登录
|
2025-10-01 14:27:41 +08:00
|
|
|
|
fingerprint: '' // 浏览器指纹
|
2025-09-27 13:36:35 +08:00
|
|
|
|
});
|
2025-04-27 13:09:57 +08:00
|
|
|
|
|
2025-03-19 15:09:01 +08:00
|
|
|
|
// 表单验证规则
|
|
|
|
|
|
const rules = {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
username: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请输入用户名",
|
|
|
|
|
|
trigger: "blur",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
password: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请输入密码",
|
|
|
|
|
|
trigger: "blur",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2025-03-19 15:09:01 +08:00
|
|
|
|
};
|
|
|
|
|
|
// 表单引用
|
|
|
|
|
|
const login = ref(null);
|
2025-05-08 14:18:21 +08:00
|
|
|
|
const maxLoginRepeatRequest = 60; //最大请求次数
|
2025-04-28 15:37:10 +08:00
|
|
|
|
const currentLoginRequest = ref(0); //当前请求次数
|
2025-09-11 20:50:24 +08:00
|
|
|
|
const timer = ref(null); //定时器
|
2025-03-19 15:09:01 +08:00
|
|
|
|
|
2025-04-30 16:56:07 +08:00
|
|
|
|
const thirdPartyLogoInfoList = ref([
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "github",
|
2025-05-06 13:58:58 +08:00
|
|
|
|
logo: "https://www.ljsea.top/wp-content/uploads/2025/05/github-48-logo.png",
|
2025-05-17 16:03:42 +08:00
|
|
|
|
label: "GitHub",
|
2025-04-30 16:56:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "gitee",
|
|
|
|
|
|
logo: "https://www.ljsea.top/wp-content/uploads/2025/04/gitee.png",
|
2025-05-17 16:03:42 +08:00
|
|
|
|
label: "Gitee",
|
2025-04-30 16:56:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "qq",
|
2025-05-06 13:58:58 +08:00
|
|
|
|
logo: "https://www.ljsea.top/wp-content/uploads/2025/05/icons8-qq-48.png",
|
2025-05-17 16:03:42 +08:00
|
|
|
|
label: "QQ",
|
2025-04-30 16:56:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "google",
|
2025-05-06 13:58:58 +08:00
|
|
|
|
logo: "https://www.ljsea.top/wp-content/uploads/2025/05/icons8-google-48.png",
|
2025-05-17 16:03:42 +08:00
|
|
|
|
label: "Google",
|
2025-04-30 16:56:07 +08:00
|
|
|
|
},
|
2025-05-01 13:30:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
name: "facebook",
|
|
|
|
|
|
logo: "https://www.ljsea.top/wp-content/uploads/2025/05/icons8-facebook.png",
|
2025-05-17 16:03:42 +08:00
|
|
|
|
label: "Facebook",
|
2025-05-06 13:58:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "stackoverflow",
|
|
|
|
|
|
logo: "https://www.ljsea.top/wp-content/uploads/2025/05/logo-stackoverflow-48.png",
|
2025-05-17 16:03:42 +08:00
|
|
|
|
label: "StackOverflow",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "my_gitea",
|
|
|
|
|
|
logo: "https://www.ljsea.top/wp-content/uploads/2025/05/my_Gitea.png",
|
|
|
|
|
|
label: "Gitea自建",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'gitea',
|
|
|
|
|
|
logo: 'https://www.ljsea.top/wp-content/uploads/2025/05/PajamasGitea.png',
|
|
|
|
|
|
label: 'Gitea官方',
|
2025-05-18 11:24:27 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'microsoft',
|
|
|
|
|
|
logo: 'https://www.ljsea.top/wp-content/uploads/2025/05/icons8-microsoft48.png',
|
|
|
|
|
|
label: 'Microsoft',
|
2025-05-01 13:30:44 +08:00
|
|
|
|
}
|
2025-05-18 11:24:27 +08:00
|
|
|
|
|
2025-04-30 16:56:07 +08:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-19 15:09:01 +08:00
|
|
|
|
//表单数据
|
|
|
|
|
|
var loginData = ref({
|
|
|
|
|
|
username: "",
|
|
|
|
|
|
email: "",
|
|
|
|
|
|
password: "",
|
|
|
|
|
|
ip: "",
|
2025-10-01 14:27:41 +08:00
|
|
|
|
fingerprint: '' // 浏览器指纹
|
2025-03-19 15:09:01 +08:00
|
|
|
|
});
|
2025-06-10 12:59:48 +08:00
|
|
|
|
const querySite =ref("");
|
|
|
|
|
|
|
2025-10-01 14:27:41 +08:00
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
let fp = await getStoredFingerprint();
|
|
|
|
|
|
param.fingerprint = fp.fingerprint;
|
|
|
|
|
|
loginData.value.fingerprint = fp.fingerprint;
|
|
|
|
|
|
code_login_form.value.fingerprint = fp.fingerprint;
|
|
|
|
|
|
console.log("fp",fp.fingerprint);
|
2025-06-10 12:59:48 +08:00
|
|
|
|
// 获取query参数
|
|
|
|
|
|
const queryParams = route.query;
|
|
|
|
|
|
console.log('Received query parameters:', queryParams);
|
|
|
|
|
|
if(queryParams.site){
|
|
|
|
|
|
querySite.value = queryParams.site as string;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-03-19 15:09:01 +08:00
|
|
|
|
|
2025-04-27 13:09:57 +08:00
|
|
|
|
const thirdLogin = async (type) => {
|
|
|
|
|
|
//获取uuid
|
|
|
|
|
|
let uuidResp = await getThirdPartyUUID({"type": type});
|
|
|
|
|
|
if (uuidResp["code"] !== 0) {
|
|
|
|
|
|
ElMessage.error("获取UUID失败!请稍后再试");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let uuid = uuidResp["data"];
|
|
|
|
|
|
if (!uuid) {
|
|
|
|
|
|
ElMessage.error("获取UUID失败!请稍后再试");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let result={};
|
2025-04-30 16:56:07 +08:00
|
|
|
|
//平台
|
2025-05-01 13:30:44 +08:00
|
|
|
|
// for(let i = 0; i < thirdPartyLogoInfoList.value.length; i++) {
|
|
|
|
|
|
// if(thirdPartyLogoInfoList.value[i].name === type) {
|
|
|
|
|
|
// result = thirdPartyLogoInfoList.value[i];
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2025-10-02 21:55:53 +08:00
|
|
|
|
result = await getThirdPartyLoginUrl({uuid: uuid,"type": "login", "platform": type,"fingerprint": param.fingerprint});
|
2025-04-27 13:09:57 +08:00
|
|
|
|
if (result["code"] !== 0) {
|
|
|
|
|
|
ElMessage.error("获取登录地址失败!请稍后再试");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let loginUrl = result["data"];
|
|
|
|
|
|
if (!loginUrl) {
|
|
|
|
|
|
ElMessage.error("获取登录地址失败!请稍后再试");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-09-11 20:50:24 +08:00
|
|
|
|
//清除定时器,防止多次点击登录按钮
|
|
|
|
|
|
if (timer.value) {
|
|
|
|
|
|
clearInterval(timer.value);
|
|
|
|
|
|
}
|
2025-04-27 13:09:57 +08:00
|
|
|
|
//获取登录状态每2秒请求一次
|
2025-09-11 20:50:24 +08:00
|
|
|
|
timer.value = setInterval(async () => {
|
2025-04-28 15:37:10 +08:00
|
|
|
|
currentLoginRequest.value++;
|
|
|
|
|
|
if (currentLoginRequest.value > maxLoginRepeatRequest) {
|
2025-09-11 20:50:24 +08:00
|
|
|
|
clearInterval(timer.value);
|
2025-04-28 15:37:10 +08:00
|
|
|
|
ElMessage.error("登录超时,请重新登录!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-04-27 13:09:57 +08:00
|
|
|
|
let statusResp = await getThirdPartyLoginStatus({uuid: uuid});
|
|
|
|
|
|
if (statusResp["code"] !== 0) {
|
|
|
|
|
|
ElMessage.error("获取登录状态失败!请稍后再试");
|
2025-09-11 20:50:24 +08:00
|
|
|
|
clearInterval(timer.value);
|
2025-04-27 13:09:57 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-05-06 13:58:58 +08:00
|
|
|
|
if(statusResp["code"] === 9){
|
|
|
|
|
|
ElMessage.error("服务器错误,请稍后再试!");
|
2025-09-11 20:50:24 +08:00
|
|
|
|
clearInterval(timer.value);
|
2025-05-06 13:58:58 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-04-27 13:09:57 +08:00
|
|
|
|
if(statusResp["data"]["status"] === 163) {
|
|
|
|
|
|
ElMessage.error("该账号未绑定,请先绑定账号!");
|
2025-09-11 20:50:24 +08:00
|
|
|
|
clearInterval(timer.value);
|
2025-04-27 13:09:57 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let status = statusResp["data"];
|
|
|
|
|
|
if(status["status"] === 0) {
|
|
|
|
|
|
//登录成功
|
2025-09-11 20:50:24 +08:00
|
|
|
|
clearInterval(timer.value);
|
2025-05-24 20:16:47 +08:00
|
|
|
|
let userInfo:UserToken = status["user_info"];
|
|
|
|
|
|
globalData["token"] = userInfo.access_token;
|
|
|
|
|
|
localStorage.setItem("token", userInfo.access_token);
|
|
|
|
|
|
localStorage.setItem("refresh_token", userInfo.refresh_token);
|
|
|
|
|
|
localStorage.setItem("userId", userInfo.user_id.toString());
|
|
|
|
|
|
localStorage.setItem("username", userInfo.username);
|
2025-04-27 13:09:57 +08:00
|
|
|
|
let now = new Date();
|
|
|
|
|
|
localStorage.setItem("end_time", (now.setDate(now.getHours() + 12)).toString()); //过期时间
|
2025-05-24 20:16:47 +08:00
|
|
|
|
await getMyUserInfo(userInfo.user_id);
|
2025-04-27 13:09:57 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
//新标签页打开登录地址
|
2025-05-13 13:58:47 +08:00
|
|
|
|
//window.open(loginUrl, "_blank");
|
|
|
|
|
|
|
|
|
|
|
|
//新的浏览器窗口打开标签页
|
|
|
|
|
|
const width = 800;
|
|
|
|
|
|
const height = 600;
|
|
|
|
|
|
// 计算窗口在屏幕中心的位置
|
|
|
|
|
|
const left = (window.screen.width - width) / 2;
|
|
|
|
|
|
const top = (window.screen.height - height) / 2;
|
|
|
|
|
|
const features = `width=${width},height=${height},left=${left},top=${top}`;
|
|
|
|
|
|
// 创建新窗口
|
|
|
|
|
|
const newWindow = window.open(loginUrl, '_blank', features);
|
2025-04-27 13:09:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-27 13:38:14 +08:00
|
|
|
|
const check_email = (email) => {
|
|
|
|
|
|
const emailReg = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
|
|
|
|
|
|
return emailReg.test(email);
|
|
|
|
|
|
}
|
2025-09-27 13:36:35 +08:00
|
|
|
|
const sendCode = async () => {
|
2025-09-27 13:38:14 +08:00
|
|
|
|
if (code_login_form.value.email === "" || check_email(code_login_form.value.email) === false) {
|
|
|
|
|
|
ElMessage.error("请输入正确邮箱地址!");
|
2025-09-27 13:36:35 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let result = await sendLoginCode(code_login_form.value);
|
|
|
|
|
|
if (result["code"] !== 0) {
|
|
|
|
|
|
ElMessage.error(result["message"] || "发送验证码失败!请稍后再试");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
countdown.value = 60;
|
|
|
|
|
|
timer.value = setInterval(() => {
|
|
|
|
|
|
countdown.value--;
|
|
|
|
|
|
if (countdown.value <= 0) {
|
|
|
|
|
|
clearInterval(timer.value); // 清除定时器
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
ElMessage.success("验证码已发送,请注意查收!");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const HandleLoginByCode =async () => {
|
2025-09-27 13:38:14 +08:00
|
|
|
|
if(code_login_form.value.email === "" || code_login_form.value.code === "" || check_email(code_login_form.value.email) === false){
|
2025-09-27 13:36:35 +08:00
|
|
|
|
ElMessage.error("请输入邮箱和验证码!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let result = await loginByCode(code_login_form.value);
|
|
|
|
|
|
if (result["code"] !== 0) {
|
|
|
|
|
|
ElMessage.error(result["message"] || "登录失败!请稍后再试");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
let userTokenInfo: UserToken = result["data"];
|
|
|
|
|
|
globalData["token"] = result.data;
|
|
|
|
|
|
localStorage.setItem("token", userTokenInfo.access_token);
|
|
|
|
|
|
localStorage.setItem("refresh_token", userTokenInfo.refresh_token);
|
|
|
|
|
|
localStorage.setItem("userId", userTokenInfo.user_id.toString());
|
|
|
|
|
|
localStorage.setItem("username", userTokenInfo.username);
|
|
|
|
|
|
let now = new Date();
|
|
|
|
|
|
localStorage.setItem("end_time", (now.setDate(now.getHours())).toString()); //过期时间
|
|
|
|
|
|
await getMyUserInfo(userTokenInfo.user_id);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const toggleLoginType = () => {
|
|
|
|
|
|
if(login_type.value === "pwd"){
|
|
|
|
|
|
login_type.value = "code";
|
|
|
|
|
|
}else{
|
|
|
|
|
|
login_type.value = "pwd";
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2025-03-19 15:09:01 +08:00
|
|
|
|
//登录接口调用
|
|
|
|
|
|
const onLogin = async () => {
|
2025-09-27 13:36:35 +08:00
|
|
|
|
if (login_type.value !== "pwd") {
|
|
|
|
|
|
HandleLoginByCode();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-03-19 20:01:03 +08:00
|
|
|
|
console.log("params:", param);
|
2025-03-19 15:09:01 +08:00
|
|
|
|
|
2025-03-19 20:01:03 +08:00
|
|
|
|
loginData.value.username = param.username;
|
|
|
|
|
|
loginData.value.password = param.password;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
let result = await loginService(loginData);
|
|
|
|
|
|
console.log("login result:", result);
|
2025-03-27 17:33:35 +08:00
|
|
|
|
if (result["code"] !== 0) {
|
2025-03-19 15:09:01 +08:00
|
|
|
|
//alert(result.message);
|
|
|
|
|
|
ElMessage.error("登录失败!用户名或密码错误");
|
2025-03-19 20:01:03 +08:00
|
|
|
|
return;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
2025-05-24 20:16:47 +08:00
|
|
|
|
let userTokenInfo: UserToken = result["data"];
|
2025-03-27 17:33:35 +08:00
|
|
|
|
globalData["token"] = result.data;
|
2025-05-24 20:16:47 +08:00
|
|
|
|
localStorage.setItem("token", userTokenInfo.access_token);
|
|
|
|
|
|
localStorage.setItem("refresh_token", userTokenInfo.refresh_token);
|
|
|
|
|
|
localStorage.setItem("userId", userTokenInfo.user_id.toString());
|
|
|
|
|
|
localStorage.setItem("username", userTokenInfo.username);
|
2025-03-19 15:09:01 +08:00
|
|
|
|
let now = new Date();
|
2025-05-24 20:16:47 +08:00
|
|
|
|
localStorage.setItem("end_time", (now.setDate(now.getHours())).toString()); //过期时间
|
|
|
|
|
|
await getMyUserInfo(userTokenInfo.user_id);
|
2025-03-19 15:09:01 +08:00
|
|
|
|
//token.value= result.data;
|
|
|
|
|
|
|
2025-03-19 20:01:03 +08:00
|
|
|
|
};
|
2025-03-19 15:09:01 +08:00
|
|
|
|
|
|
|
|
|
|
const getMyUserInfo = async (id) => {
|
|
|
|
|
|
let result = {};
|
|
|
|
|
|
try {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
let tokenData = {
|
2025-03-19 15:09:01 +08:00
|
|
|
|
token: localStorage.getItem("token"),
|
|
|
|
|
|
id: id,
|
2025-03-19 20:01:03 +08:00
|
|
|
|
};
|
2025-03-19 15:09:01 +08:00
|
|
|
|
result = await GetUserInfoService(tokenData);
|
2025-05-24 20:16:47 +08:00
|
|
|
|
const cookie= Cookies.get("user_token");
|
|
|
|
|
|
console.log("cookie:", cookie);
|
2025-03-27 17:33:35 +08:00
|
|
|
|
if (result["code"] === 0) {
|
2025-03-19 15:09:01 +08:00
|
|
|
|
//console.log("token data:",this.tokenData)
|
2025-03-27 17:33:35 +08:00
|
|
|
|
// 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);
|
2025-05-24 20:16:47 +08:00
|
|
|
|
|
2025-03-19 15:09:01 +08:00
|
|
|
|
|
2025-03-19 20:01:03 +08:00
|
|
|
|
ElMessage.success("登录成功");
|
2025-03-27 17:33:35 +08:00
|
|
|
|
localStorage.setItem("ms_username", result["data"]["Name"]);
|
2025-03-19 20:01:03 +08:00
|
|
|
|
const keys =
|
2025-03-27 17:33:35 +08:00
|
|
|
|
permiss.defaultList[result["data"]["Role"] == "admin" ? "admin" : "user"];
|
|
|
|
|
|
localStorage.setItem("ms_imgurl", result["data"]["Avatar"]);
|
2025-03-19 20:01:03 +08:00
|
|
|
|
permiss.handleSet(keys);
|
|
|
|
|
|
localStorage.setItem("ms_keys", JSON.stringify(keys));
|
2025-04-23 15:11:16 +08:00
|
|
|
|
localStorage.setItem("ms_role", result["data"]["Role"]);
|
2025-06-10 12:59:48 +08:00
|
|
|
|
|
|
|
|
|
|
if(querySite.value === "" ){
|
|
|
|
|
|
router.push("/");
|
|
|
|
|
|
}else{
|
|
|
|
|
|
localStorage.setItem("targetSite", querySite.value);
|
|
|
|
|
|
router.push({ path: `/project-select` });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-19 20:01:03 +08:00
|
|
|
|
|
2025-03-19 15:09:01 +08:00
|
|
|
|
//alert("video_func:" + localStorage.getItem("video_func")+" type:" +typeof(localStorage.getItem("video_func")));
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 获取标签存储并清空标签
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.login-bg {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
background: url(../../assets/img/login-bg3.jpg) center/cover no-repeat;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-header {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
margin-bottom: 40px;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.logo {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
width: 35px;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-title {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
font-size: 22px;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
font-weight: bold;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-container {
|
2025-05-01 13:30:44 +08:00
|
|
|
|
width: 470px;
|
2025-03-19 20:01:03 +08:00
|
|
|
|
border-radius: 5px;
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
padding: 40px 50px 50px;
|
|
|
|
|
|
box-sizing: border-box;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.pwd-tips {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
margin: -10px 0 10px;
|
|
|
|
|
|
color: #787878;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.pwd-checkbox {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
height: auto;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-btn {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
display: block;
|
2025-05-01 13:30:44 +08:00
|
|
|
|
/* 文字水平竖直居中 */
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
2025-03-19 20:01:03 +08:00
|
|
|
|
width: 100%;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-tips {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: #999;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-text {
|
2025-03-19 20:01:03 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: #787878;
|
2025-03-19 15:09:01 +08:00
|
|
|
|
}
|
2025-04-28 15:37:10 +08:00
|
|
|
|
|
|
|
|
|
|
.login-text {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.github-btn {
|
|
|
|
|
|
background-image: url(../../assets/img/github-logo.png) !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitee-btn {
|
|
|
|
|
|
background-image: url(../../assets/img/gitee_logo.png) !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
.qq-btn {
|
|
|
|
|
|
background-image: url(https://wiki.connect.qq.com/wp-content/uploads/2016/12/Connect_logo_4.png);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-04-30 16:56:07 +08:00
|
|
|
|
.google-btn {
|
|
|
|
|
|
background-image: url(../../assets/img/google-logo_resized.png) !important;
|
|
|
|
|
|
}
|
2025-09-27 13:36:35 +08:00
|
|
|
|
.code-btn :deep(.el-button--text:not(.is-disabled)):hover {
|
|
|
|
|
|
color: #0d66d0 !important;
|
|
|
|
|
|
background: rgba(22, 119, 255, 0.05) !important;
|
|
|
|
|
|
}
|
2025-03-19 15:09:01 +08:00
|
|
|
|
</style>
|