diff --git a/src/api/oauth/wechat.ts b/src/api/oauth/wechat.ts index c372ff1..b3e898b 100644 --- a/src/api/oauth/wechat.ts +++ b/src/api/oauth/wechat.ts @@ -16,19 +16,4 @@ export const generateQrCode = (clientId: string) => { } ); }; -/** - * 关闭websocket - * @param clientId - */ -export const closeWebsocket = (clientId: string) => { - return service.Get('/api/ws/delete', - { - params: { - client_id: clientId - }, - meta: { - ignoreToken: true, - }, - } - ); -}; + diff --git a/src/api/user/index.ts b/src/api/user/index.ts index ea63288..a370038 100644 --- a/src/api/user/index.ts +++ b/src/api/user/index.ts @@ -106,10 +106,9 @@ export const resetPasswordApi = (param: ResetPassword) => { * @param user_id */ export const getUserPermissions = (user_id: string) => { - return service.Get('/api/auth/permission/get_user_permissions', { - params: { - user_id: user_id - }, + return service.Post('/api/auth/permission/get_user_permissions', { + user_id: user_id, + }, { meta: { ignoreToken: false, } diff --git a/src/store/modules/clientStore.ts b/src/store/modules/clientStore.ts index 35e42e9..15f32fe 100644 --- a/src/store/modules/clientStore.ts +++ b/src/store/modules/clientStore.ts @@ -4,7 +4,7 @@ import {ref} from "vue"; export const useClientStore = defineStore( 'clientId', () => { - const clientId = ref(); + const clientId = ref(''); function setClientId(id: string) { clientId.value = id; diff --git a/src/utils/alova/service.ts b/src/utils/alova/service.ts index fd0872d..75cce7b 100644 --- a/src/utils/alova/service.ts +++ b/src/utils/alova/service.ts @@ -34,7 +34,6 @@ const {onAuthRequired, onResponseRefreshToken} = createServerTokenAuthentication } else { message.error(i18n.global.t('error.loginExpired')); localStorage.removeItem('user'); - localStorage.removeItem('clientId'); setTimeout(() => { window.location.href = '/login'; }, 2000); @@ -50,12 +49,7 @@ export const service = createAlova({ requestAdapter: axiosRequestAdapter(), l2Cache: localforageStorageAdapter, cacheLogger: import.meta.env.VITE_NODE_ENV === 'development', - cacheFor: { - // GET: { - // mode: "restore", - // expire: 1000 * 60 * 60 * 24 * 7 // 7天过期 - // } - }, + cacheFor: {}, // 设置全局的请求拦截器 beforeRequest: onAuthRequired(async (method: any) => { if (!method.meta?.ignoreToken) { @@ -74,7 +68,6 @@ export const service = createAlova({ const {code} = response.data; if (code === 403) { localStorage.removeItem('user'); - localStorage.removeItem('clientId'); message.open({ type: 'error', content: i18n.global.t('error.loginExpired'), diff --git a/src/views/Login/LoginFooter.vue b/src/views/Login/LoginFooter.vue index 4a2f210..d2e30db 100644 --- a/src/views/Login/LoginFooter.vue +++ b/src/views/Login/LoginFooter.vue @@ -36,12 +36,13 @@ const {t} = useI18n(); const githubRedirectUrl = ref(''); const giteeRedirectUrl = ref(''); const qqRedirectUrl = ref(''); +const client = useStore().client; /** * Get the redirect url of Github OAuth */ async function getGithubRedirectUrl() { - const clientId: string = getLocalClientId() as string; + const clientId: string = await getLocalClientId() as string; const res: any = await getGithubUrl(clientId); if (res.code === 0 && res.data) { githubRedirectUrl.value = res.data; @@ -62,7 +63,7 @@ async function getGiteeRedirectUrl() { * Get the redirect url of QQ OAuth */ async function getQQRedirectUrl() { - const clientId: string = getLocalClientId() as string; + const clientId: string = await getLocalClientId() as string; const res: any = await getQQUrl(clientId); if (res.code === 0 && res.data) { qqRedirectUrl.value = res.data; @@ -73,7 +74,6 @@ 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); @@ -83,12 +83,11 @@ async function getClientId() { /** * 获取本地client_id */ -function getLocalClientId() { - const client = useStore().client; - if (client.getClientId()) { +async function getLocalClientId() { + if (client.getClientId() !== '' && client.getClientId() !== null) { return client.getClientId(); } else { - getClientId(); + await getClientId(); return client.getClientId(); } } diff --git a/src/views/QRLogin/QRLoginFooter.vue b/src/views/QRLogin/QRLoginFooter.vue index 0a4a950..bf7f5ab 100644 --- a/src/views/QRLogin/QRLoginFooter.vue +++ b/src/views/QRLogin/QRLoginFooter.vue @@ -31,6 +31,7 @@ import {getQQUrl} from "@/api/oauth/qq.ts"; import {useDebounceFn} from "@vueuse/core"; import {generateClientId, getUserDevice} from "@/api/oauth"; +const client = useStore().client; const router = useRouter(); const {t} = useI18n(); @@ -42,7 +43,7 @@ const qqRedirectUrl = ref(''); * Get the redirect url of Github OAuth */ async function getGithubRedirectUrl() { - const clientId: string = getLocalClientId() as string; + const clientId: string = await getLocalClientId() as string; const res: any = await getGithubUrl(clientId); if (res.code === 0 && res.data) { githubRedirectUrl.value = res.data; @@ -63,7 +64,7 @@ async function getGiteeRedirectUrl() { * Get the redirect url of QQ OAuth */ async function getQQRedirectUrl() { - const clientId: string = getLocalClientId() as string; + const clientId: string = await getLocalClientId() as string; const res: any = await getQQUrl(clientId); if (res.code === 0 && res.data) { qqRedirectUrl.value = res.data; @@ -74,7 +75,6 @@ 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); @@ -84,12 +84,11 @@ async function getClientId() { /** * 获取本地client_id */ -function getLocalClientId() { - const client = useStore().client; - if (client.getClientId()) { +async function getLocalClientId() { + if (client.getClientId() !== '' && client.getClientId() !== null) { return client.getClientId(); } else { - getClientId(); + await getClientId(); return client.getClientId(); } }