refactor: 初步可用

This commit is contained in:
手瓜一十雪
2024-11-15 17:35:09 +08:00
parent db3d435402
commit d445dc6644
5 changed files with 1006 additions and 25 deletions

View File

@@ -37,6 +37,7 @@ export class QQLoginManager {
}); });
if (LoginResponse.status == 200) { if (LoginResponse.status == 200) {
let LoginResponseJson = await LoginResponse.json(); let LoginResponseJson = await LoginResponse.json();
//console.log(LoginResponseJson);
if (LoginResponseJson.code == 0) { if (LoginResponseJson.code == 0) {
return true; return true;
} }

View File

@@ -36,14 +36,7 @@ const formData = reactive({
const handleLoginSuccess = async (credential) => { const handleLoginSuccess = async (credential) => {
localStorage.setItem('auth', credential); localStorage.setItem('auth', credential);
const loginManager = new QQLoginManager(credential); await checkLoginStatus();
const isQQLoggedIn = await loginManager.checkQQLoginStatus();
if (isQQLoggedIn) {
await router.push({ path: '/config' });
} else {
await router.push({ path: '/qqlogin' });
}
MessagePlugin.success('登录成功');
}; };
const handleLoginFailure = (message) => { const handleLoginFailure = (message) => {
@@ -52,30 +45,46 @@ const handleLoginFailure = (message) => {
const checkLoginStatus = async () => { const checkLoginStatus = async () => {
const storedCredential = localStorage.getItem('auth'); const storedCredential = localStorage.getItem('auth');
if (storedCredential) { if (!storedCredential) {
const loginManager = new QQLoginManager(storedCredential); return;
const isQQLoggedIn = await loginManager.checkQQLoginStatus(); }
if (isQQLoggedIn) { const loginManager = new QQLoginManager(storedCredential);
await router.push({ path: '/dashboard/basic-info' }); const isWenUiLoggedIn = await loginManager.checkWebUiLogined();
} else { console.log('isWenUiLoggedIn', isWenUiLoggedIn);
await router.push({ path: '/qqlogin' }); if (!isWenUiLoggedIn) {
} return;
}
const isQQLoggedIn = await loginManager.checkQQLoginStatus();
if (isQQLoggedIn) {
await router.push({ path: '/dashboard/basic-info' });
} else {
await router.push({ path: '/qqlogin' });
}
};
const loginWithToken = async (token) => {
const loginManager = new QQLoginManager('');
const credential = await loginManager.loginWithToken(token);
if (credential) {
await handleLoginSuccess(credential);
} else {
handleLoginFailure('登录失败请检查Token');
} }
}; };
onMounted(() => { onMounted(() => {
const url = new URL(window.location.href);
const token = url.searchParams.get("token");
if (token) {
loginWithToken(token);
}
checkLoginStatus(); checkLoginStatus();
}); });
const onSubmit = async ({ validateResult }) => { const onSubmit = async ({ validateResult }) => {
if (validateResult === true) { if (validateResult === true) {
const loginManager = new QQLoginManager(''); await loginWithToken(formData.token);
const credential = await loginManager.loginWithToken(formData.token);
if (credential) {
await handleLoginSuccess(credential);
} else {
handleLoginFailure('登录失败请检查Token');
}
} else { } else {
handleLoginFailure('请填写Token'); handleLoginFailure('请填写Token');
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="./vite.svg" /> <link rel="icon" type="image/svg+xml" href="./vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title> <title>Vite + Vue + TS</title>
<script type="module" crossorigin src="./assets/index-xw9jld-V.js"></script> <script type="module" crossorigin src="./assets/index-FfoKdZMo.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-Cz7mtj1A.css"> <link rel="stylesheet" crossorigin href="./assets/index-DedbXlpT.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>