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) {
let LoginResponseJson = await LoginResponse.json();
//console.log(LoginResponseJson);
if (LoginResponseJson.code == 0) {
return true;
}

View File

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