🐛 fixed the third-party login bug

This commit is contained in:
landaiqing
2024-08-30 21:52:48 +08:00
parent d91e683e87
commit 2c6ad81720
11 changed files with 254 additions and 72 deletions

4
components.d.ts vendored
View File

@@ -8,7 +8,6 @@ export {}
declare module 'vue' { declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
AButton: typeof import('ant-design-vue/es')['Button'] AButton: typeof import('ant-design-vue/es')['Button']
AButtonGroup: typeof import('ant-design-vue/es')['ButtonGroup']
ACard: typeof import('ant-design-vue/es')['Card'] ACard: typeof import('ant-design-vue/es')['Card']
ACheckbox: typeof import('ant-design-vue/es')['Checkbox'] ACheckbox: typeof import('ant-design-vue/es')['Checkbox']
AConfigProvider: typeof import('ant-design-vue/es')['ConfigProvider'] AConfigProvider: typeof import('ant-design-vue/es')['ConfigProvider']
@@ -22,8 +21,6 @@ declare module 'vue' {
AMenu: typeof import('ant-design-vue/es')['Menu'] AMenu: typeof import('ant-design-vue/es')['Menu']
AMenuItem: typeof import('ant-design-vue/es')['MenuItem'] AMenuItem: typeof import('ant-design-vue/es')['MenuItem']
AQrcode: typeof import('ant-design-vue/es')['QRCode'] AQrcode: typeof import('ant-design-vue/es')['QRCode']
ASelect: typeof import('ant-design-vue/es')['Select']
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
ATabPane: typeof import('ant-design-vue/es')['TabPane'] ATabPane: typeof import('ant-design-vue/es')['TabPane']
ATabs: typeof import('ant-design-vue/es')['Tabs'] ATabs: typeof import('ant-design-vue/es')['Tabs']
ATooltip: typeof import('ant-design-vue/es')['Tooltip'] ATooltip: typeof import('ant-design-vue/es')['Tooltip']
@@ -47,7 +44,6 @@ declare module 'vue' {
RouterView: typeof import('vue-router')['RouterView'] RouterView: typeof import('vue-router')['RouterView']
SafetyOutlined: typeof import('@ant-design/icons-vue')['SafetyOutlined'] SafetyOutlined: typeof import('@ant-design/icons-vue')['SafetyOutlined']
TabletOutlined: typeof import('@ant-design/icons-vue')['TabletOutlined'] TabletOutlined: typeof import('@ant-design/icons-vue')['TabletOutlined']
TestTheme: typeof import('./src/views/TestTheme.vue')['default']
UserOutlined: typeof import('@ant-design/icons-vue')['UserOutlined'] UserOutlined: typeof import('@ant-design/icons-vue')['UserOutlined']
WechatOutlined: typeof import('@ant-design/icons-vue')['WechatOutlined'] WechatOutlined: typeof import('@ant-design/icons-vue')['WechatOutlined']
} }

View File

@@ -1,6 +1,6 @@
<template> <template>
<div class="cards" style="transform: rotateX(-10.2deg) rotateY(-17.8deg);"> <div class="cards" style="transform: rotateX(-10.2deg) rotateY(-17.8deg);">
<h3>Movies</h3> <h3>Album</h3>
<h1>Popular</h1> <h1>Popular</h1>
<div class="card card__one"> <div class="card card__one">
<div class="card__bg" style="background-position: -8.01px 4.59px;"></div> <div class="card__bg" style="background-position: -8.01px 4.59px;"></div>

View File

@@ -1,11 +1,13 @@
import {useAuthStore} from '@/store/modules/userStore.ts'; import {useAuthStore} from '@/store/modules/userStore.ts';
import {useThemeStore} from "@/store/modules/themeStore.ts"; import {useThemeStore} from "@/store/modules/themeStore.ts";
import {langStore} from "@/store/modules/langStore.ts"; import {langStore} from "@/store/modules/langStore.ts";
import {useClientStore} from "@/store/modules/clientStore.ts";
export default function useStore() { export default function useStore() {
return { return {
user: useAuthStore(), user: useAuthStore(),
theme: useThemeStore(), theme: useThemeStore(),
lang: langStore(), lang: langStore(),
client: useClientStore(),
}; };
} }

View File

@@ -0,0 +1,31 @@
import {defineStore} from 'pinia';
import {ref} from "vue";
export const useClientStore = defineStore(
'clientId',
() => {
const clientId = ref<string>();
function setClientId(id: string) {
clientId.value = id;
}
function getClientId() {
return clientId.value;
}
return {
clientId,
setClientId,
getClientId
};
},
{
// 开启数据持久化
persist: {
key: 'clientId',
storage: localStorage,
paths: ["clientId"],
}
}
);

View File

@@ -91,6 +91,20 @@
:events="resetPasswordRotateEvent" :events="resetPasswordRotateEvent"
/> />
</div> </div>
<div class="area">
<ul class="circles">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -190,9 +204,7 @@ const countDown = () => {
} else { } else {
localStorage.setItem('start_time_send_captcha', String(nowTime)); localStorage.setItem('start_time_send_captcha', String(nowTime));
} }
state.countDownTime = surplus; state.countDownTime = surplus;
if (timer) { if (timer) {
clearInterval(timer); clearInterval(timer);
} }
@@ -258,7 +270,7 @@ async function resetPasswordSubmit() {
} }
/** /**
* 刷新验证码 节流 * 刷新验证码 防抖
*/ */
const refreshCaptcha = useDebounceFn(getRotateCaptcha, 3000); const refreshCaptcha = useDebounceFn(getRotateCaptcha, 3000);

View File

@@ -4,16 +4,16 @@
//background-color: rgb(238, 255, 238); //background-color: rgb(238, 255, 238);
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
/* 加载背景图 */ ///* 加载背景图 */
background-image: url("@/assets/images/background.png"); //background-image: url("@/assets/images/background.png");
/* 背景图垂直、水平均居中 */ ///* 背景图垂直、水平均居中 */
background-position: center center; //background-position: center center;
/* 背景图不平铺 */ ///* 背景图不平铺 */
background-repeat: no-repeat; //background-repeat: no-repeat;
/* 当内容高度大于图片高度时背景图像的位置相对于viewport固定 */ ///* 当内容高度大于图片高度时背景图像的位置相对于viewport固定 */
background-attachment: fixed; //background-attachment: fixed;
/* 让背景图基于容器大小伸缩 */ ///* 让背景图基于容器大小伸缩 */
background-size: cover; //background-size: cover;
z-index: -1; z-index: -1;
.forget-left { .forget-left {
@@ -107,4 +107,131 @@
background-color: rgba(0, 0, 0, 0.5); background-color: rgba(0, 0, 0, 0.5);
} }
.area {
background: #b9f187;
background: -webkit-linear-gradient(to left, #b9f187, #90d952, #70c13a, #52a82e) !important;
width: 100%;
height: 100vh;
z-index: -1;
overflow: hidden;
position: fixed;
top: 0;
left: 0;
}
.circles {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
.circles li {
position: absolute;
display: block;
list-style: none;
width: 20px;
height: 20px;
background: rgba(255, 255, 255, 0.5);
animation: animate 25s linear infinite;
bottom: -150px;
}
.circles li:nth-child(1) {
left: 25%;
width: 80px;
height: 80px;
animation-delay: 0s;
}
.circles li:nth-child(2) {
left: 10%;
width: 20px;
height: 20px;
animation-delay: 2s;
animation-duration: 12s;
}
.circles li:nth-child(3) {
left: 70%;
width: 20px;
height: 20px;
animation-delay: 4s;
}
.circles li:nth-child(4) {
left: 40%;
width: 60px;
height: 60px;
animation-delay: 0s;
animation-duration: 18s;
}
.circles li:nth-child(5) {
left: 65%;
width: 20px;
height: 20px;
animation-delay: 0s;
}
.circles li:nth-child(6) {
left: 75%;
width: 110px;
height: 110px;
animation-delay: 3s;
}
.circles li:nth-child(7) {
left: 35%;
width: 150px;
height: 150px;
animation-delay: 7s;
}
.circles li:nth-child(8) {
left: 50%;
width: 25px;
height: 25px;
animation-delay: 15s;
animation-duration: 45s;
}
.circles li:nth-child(9) {
left: 20%;
width: 15px;
height: 15px;
animation-delay: 2s;
animation-duration: 35s;
}
.circles li:nth-child(10) {
left: 85%;
width: 150px;
height: 150px;
animation-delay: 0s;
animation-duration: 11s;
}
@keyframes animate {
0% {
transform: translateY(0) rotate(0deg);
opacity: 1;
border-radius: 0;
}
100% {
transform: translateY(-1000px) rotate(720deg);
opacity: 0;
border-radius: 50%;
}
}
} }

View File

@@ -73,25 +73,23 @@ async function getQQRedirectUrl() {
* 获取client_id * 获取client_id
*/ */
async function getClientId() { async function getClientId() {
const id: string | null = localStorage.getItem('client_id'); const client = useStore().client;
if (!id) {
const res: any = await generateClientId(); const res: any = await generateClientId();
if (res.code === 0 && res.data) { if (res.code === 0 && res.data) {
localStorage.setItem('client_id', res.data); client.setClientId(res.data);
}
} }
} }
/** /**
* 获取本地client_id * 获取本地client_id
*/ */
function getLocalClientId(): string | null { function getLocalClientId() {
const clientID: string | null = localStorage.getItem('client_id'); const client = useStore().client;
if (clientID) { if (client.getClientId()) {
return clientID; return client.getClientId();
} else { } else {
getClientId(); getClientId();
return localStorage.getItem('client_id'); return client.getClientId();
} }
} }
@@ -126,7 +124,11 @@ function openGithubUrl() {
setTimeout(() => { setTimeout(() => {
router.push('/main'); router.push('/main');
}, 1000); }, 1000);
} else {
message.error(t('login.loginError'));
window.removeEventListener("message", messageHandler);
} }
} }
}; };
window.addEventListener("message", messageHandler); window.addEventListener("message", messageHandler);
@@ -164,6 +166,9 @@ function openGiteeUrl() {
setTimeout(() => { setTimeout(() => {
router.push('/main'); router.push('/main');
}, 1000); }, 1000);
} else {
message.error(t('login.loginError'));
window.removeEventListener("message", messageHandler);
} }
} }
}; };
@@ -201,7 +206,11 @@ function openQQUrl() {
setTimeout(() => { setTimeout(() => {
router.push('/main'); router.push('/main');
}, 1000); }, 1000);
} else {
message.error(t('login.loginError'));
window.removeEventListener("message", messageHandler);
} }
} }
}; };
window.addEventListener("message", messageHandler); window.addEventListener("message", messageHandler);

View File

@@ -19,6 +19,7 @@
.login-left { .login-left {
width: 50%; width: 50%;
background: transparent;
} }
.login-right { .login-right {

View File

@@ -1,20 +1,19 @@
<template> <template>
<div> <div>
<h1>Welcome to Main Page</h1> <h1>Welcome to Main Page</h1>
<AButton @click="handleClick">获取用户数据</AButton> <!-- <AButton @click="handleClick">获取用户数据</AButton>-->
{{ data }}
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {useRequest} from "alova/client"; // import {useRequest} from "alova/client";
import {getUserInfo} from "@/api/user"; // import {getUserInfo} from "@/api/user";
//
const {data, send} = useRequest(getUserInfo, { // const {data, send} = useRequest(getUserInfo, {
immediate: false // immediate: false
}); // });
const handleClick = () => { // const handleClick = () => {
send(); // send();
}; // };
</script> </script>
<style scoped> <style scoped>

View File

@@ -75,12 +75,10 @@ const status = ref<string>('loading');
* 获取client_id * 获取client_id
*/ */
async function getClientId() { async function getClientId() {
const id: string | null = localStorage.getItem('client_id'); const client = useStore().client;
if (!id) {
const res: any = await generateClientId(); const res: any = await generateClientId();
if (res.code === 0 && res.data) { if (res.code === 0 && res.data) {
localStorage.setItem('client_id', res.data); client.setClientId(res.data);
}
} }
} }
@@ -89,13 +87,13 @@ async function getClientId() {
* 获取二维码 * 获取二维码
*/ */
async function getQrCode() { async function getQrCode() {
const clientId: string | null = localStorage.getItem('client_id'); const client = useStore().client;
if (!clientId) { if (!client.getClientId()) {
status.value = 'expired'; status.value = 'expired';
await getClientId(); await getClientId();
await getQrCode(); await getQrCode();
} else { } else {
const res: any = await generateQrCode(clientId); const res: any = await generateQrCode(client.getClientId() as string);
if (res.code === 0 && res.data) { if (res.code === 0 && res.data) {
status.value = 'active'; status.value = 'active';
qrcode.value = res.data; qrcode.value = res.data;
@@ -108,13 +106,13 @@ async function getQrCode() {
/** /**
* 获取本地client_id * 获取本地client_id
*/ */
function getLocalClientId(): string | null { function getLocalClientId() {
const clientID: string | null = localStorage.getItem('client_id'); const client = useStore().client;
if (clientID) { if (client.getClientId()) {
return clientID; return client.getClientId();
} else { } else {
getClientId(); getClientId();
return localStorage.getItem('client_id'); return client.getClientId();
} }
} }

View File

@@ -59,19 +59,6 @@ async function getGiteeRedirectUrl() {
} }
} }
/**
* 获取client_id
*/
async function getClientId() {
const id: string | null = localStorage.getItem('client_id');
if (!id) {
const res: any = await generateClientId();
if (res.code === 0 && res.data) {
localStorage.setItem('client_id', res.data);
}
}
}
/** /**
* Get the redirect url of QQ OAuth * Get the redirect url of QQ OAuth
*/ */
@@ -83,16 +70,27 @@ async function getQQRedirectUrl() {
} }
} }
/**
* 获取client_id
*/
async function getClientId() {
const client = useStore().client;
const res: any = await generateClientId();
if (res.code === 0 && res.data) {
client.setClientId(res.data);
}
}
/** /**
* 获取本地client_id * 获取本地client_id
*/ */
function getLocalClientId(): string | null { function getLocalClientId() {
const clientID: string | null = localStorage.getItem('client_id'); const client = useStore().client;
if (clientID) { if (client.getClientId()) {
return clientID; return client.getClientId();
} else { } else {
getClientId(); getClientId();
return localStorage.getItem('client_id'); return client.getClientId();
} }
} }
@@ -127,6 +125,9 @@ function openGithubUrl() {
setTimeout(() => { setTimeout(() => {
router.push('/main'); router.push('/main');
}, 1000); }, 1000);
} else {
message.error(t('login.loginError'));
window.removeEventListener("message", messageHandler);
} }
} }
}; };
@@ -165,6 +166,9 @@ function openGiteeUrl() {
setTimeout(() => { setTimeout(() => {
router.push('/main'); router.push('/main');
}, 1000); }, 1000);
}else {
message.error(t('login.loginError'));
window.removeEventListener("message", messageHandler);
} }
} }
}; };
@@ -202,6 +206,9 @@ function openQQUrl() {
setTimeout(() => { setTimeout(() => {
router.push('/main'); router.push('/main');
}, 1000); }, 1000);
}else {
message.error(t('login.loginError'));
window.removeEventListener("message", messageHandler);
} }
} }
}; };