From ecb620075983e5ccfbbfbc296121f50327b54f3f Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 10 Jul 2024 20:16:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E8=B0=83=E6=95=B4=E9=A3=9E=E4=B9=A6=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E9=80=80=E5=87=BA=E5=86=8D=E7=99=BB=E9=99=86=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.vue | 33 ++++++++- frontend/src/router/constants.ts | 1 - frontend/src/router/index.ts | 2 - frontend/src/router/routes/base.ts | 6 -- frontend/src/store/modules/user/index.ts | 3 + .../src/views/base/login-redirect/index.vue | 68 ------------------- .../src/views/login/components/larkQrCode.vue | 2 +- .../login/components/larkSuiteQrCode.vue | 4 +- 8 files changed, 36 insertions(+), 83 deletions(-) delete mode 100644 frontend/src/views/base/login-redirect/index.vue diff --git a/frontend/src/App.vue b/frontend/src/App.vue index b7a4f73281..98325424ce 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,6 +1,8 @@ @@ -24,7 +26,7 @@ import { getLocalStorage, setLocalStorage } from '@/utils/local-storage'; import { setFavicon, watchStyle, watchTheme } from '@/utils/theme'; - import { getPublicKeyRequest } from './api/modules/user'; + import { getLarkCallback, getLarkSuiteCallback, getPublicKeyRequest } from './api/modules/user'; import enUS from '@arco-design/web-vue/es/locale/lang/en-us'; import zhCN from '@arco-design/web-vue/es/locale/lang/zh-cn'; @@ -44,6 +46,8 @@ } }); + const loading = ref(false); + // 初始化平台风格和主题色 watchStyle(appStore.pageConfig.style, appStore.pageConfig); watchTheme(appStore.pageConfig.theme, appStore.pageConfig); @@ -85,6 +89,31 @@ setToken(window.atob(TOKEN), CSRF); setLoginExpires(); } + const state = ref(''); + const code = getQueryVariable('code'); + state.value = getQueryVariable('state') || ''; + if (state.value.split('#')[0] === 'fit2cloud-lark-qr') { + try { + loading.value = true; + const larkCallback = await getLarkCallback(code || ''); + userStore.qrCodeLogin(larkCallback); + setLoginExpires(); + loading.value = false; + } catch (err) { + console.log(err); + } + } + if (state.value.split('#')[0] === 'fit2cloud-lark-suite-qr') { + try { + loading.value = true; + const larkCallback = await getLarkSuiteCallback(code || ''); + userStore.qrCodeLogin(larkCallback); + setLoginExpires(); + loading.value = false; + } catch (err) { + console.log(err); + } + } await userStore.checkIsLogin(); } const { height } = useWindowSize(); diff --git a/frontend/src/router/constants.ts b/frontend/src/router/constants.ts index 6fca4e1327..b4914ee808 100644 --- a/frontend/src/router/constants.ts +++ b/frontend/src/router/constants.ts @@ -3,7 +3,6 @@ export const WHITE_LIST = [ { name: 'notFound', path: '/notFound', children: [] }, { name: 'invite', path: '/invite', children: [] }, { name: 'index', path: '/index', children: [] }, - { name: 'loginRedirect', path: '/qrcode/transition', children: [] }, { name: 'share', path: '/share', diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index d58c97cff2..5952bf26b3 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -6,7 +6,6 @@ import appRoutes from './routes'; import { INDEX_ROUTE, INVITE_ROUTE, - LOGIN_REDIRECT, NO_PROJECT, NO_RESOURCE, NOT_FOUND_RESOURCE, @@ -40,7 +39,6 @@ const router = createRouter({ NO_PROJECT, NO_RESOURCE, INDEX_ROUTE, - LOGIN_REDIRECT, ], scrollBehavior() { return { top: 0 }; diff --git a/frontend/src/router/routes/base.ts b/frontend/src/router/routes/base.ts index 63f4deb9cb..c2ff99e38a 100644 --- a/frontend/src/router/routes/base.ts +++ b/frontend/src/router/routes/base.ts @@ -75,9 +75,3 @@ export const NOT_FOUND_RESOURCE: RouteRecordRaw = { name: 'notResourceScreen', component: () => import('@/views/base/not-resource-screen/not-resource-screen.vue'), }; - -export const LOGIN_REDIRECT: RouteRecordRaw = { - path: '/qrcode/transition', - name: 'loginRedirect', - component: () => import('@/views/base/login-redirect/index.vue'), -}; diff --git a/frontend/src/store/modules/user/index.ts b/frontend/src/store/modules/user/index.ts index 4c778cb026..0345be0dd0 100644 --- a/frontend/src/store/modules/user/index.ts +++ b/frontend/src/store/modules/user/index.ts @@ -182,6 +182,9 @@ const useUserStore = defineStore('user', { async isLogin(forceSet = false) { try { const res = await userIsLogin(); + if (!res) { + return false; + } const appStore = useAppStore(); setToken(res.sessionId, res.csrfToken); this.setInfo(res); diff --git a/frontend/src/views/base/login-redirect/index.vue b/frontend/src/views/base/login-redirect/index.vue deleted file mode 100644 index 0970cc4689..0000000000 --- a/frontend/src/views/base/login-redirect/index.vue +++ /dev/null @@ -1,68 +0,0 @@ - - - diff --git a/frontend/src/views/login/components/larkQrCode.vue b/frontend/src/views/login/components/larkQrCode.vue index e3ee10abbb..59c51628fa 100644 --- a/frontend/src/views/login/components/larkQrCode.vue +++ b/frontend/src/views/login/components/larkQrCode.vue @@ -15,7 +15,7 @@ const data = await getLarkInfo(); await load(true); // const callBack = encodeURIComponent(window.location.origin); - const redirectUrL = encodeURIComponent(`${window.location.origin}#/qrcode/transition`); + const redirectUrL = encodeURIComponent(window.location.origin); // const url = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${data.agentId}&redirect_uri=${callBack}&response_type=code&state=fit2cloud-lark-qr`; const url = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${data.agentId}&redirect_uri=${redirectUrL}&response_type=code&state=fit2cloud-lark-qr`; diff --git a/frontend/src/views/login/components/larkSuiteQrCode.vue b/frontend/src/views/login/components/larkSuiteQrCode.vue index 46a9f74749..405d31ad45 100644 --- a/frontend/src/views/login/components/larkSuiteQrCode.vue +++ b/frontend/src/views/login/components/larkSuiteQrCode.vue @@ -14,9 +14,7 @@ const initActive = async () => { const data = await getLarkSuiteInfo(); await load(true); - // const callBack = encodeURIComponent(window.location.origin); - const redirectUrL = encodeURIComponent(`${window.location.origin}#/qrcode/transition`); - // const url = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${data.agentId}&redirect_uri=${callBack}&response_type=code&state=fit2cloud-lark-qr`; + const redirectUrL = encodeURIComponent(window.location.origin); const url = `https://passport.larksuite.com/suite/passport/oauth/authorize?client_id=${data.agentId}&redirect_uri=${redirectUrL}&response_type=code&state=fit2cloud-lark-suite-qr`; const QRLoginObj = window.QRLogin({