refactor(系统设置): 调整飞书扫码退出再登陆失败问题

This commit is contained in:
guoyuqi 2024-07-10 20:16:28 +08:00 committed by 刘瑞斌
parent 610104eb25
commit ecb6200759
8 changed files with 36 additions and 83 deletions

View File

@ -1,6 +1,8 @@
<template>
<a-config-provider :locale="locale">
<a-spin :loading="loading">
<router-view />
</a-spin>
<!-- <global-setting /> -->
</a-config-provider>
</template>
@ -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();

View File

@ -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',

View File

@ -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 };

View File

@ -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'),
};

View File

@ -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);

View File

@ -1,68 +0,0 @@
<template>
<a-spin class="w-full" />
</template>
<script lang="ts" setup>
import { useRouter } from 'vue-router';
import { Message } from '@arco-design/web-vue';
import { getProjectInfo } from '@/api/modules/project-management/project';
import { getLarkCallback, getLarkSuiteCallback } from '@/api/modules/user';
import { useI18n } from '@/hooks/useI18n';
import { NO_PROJECT_ROUTE_NAME, NO_RESOURCE_ROUTE_NAME } from '@/router/constants';
import { useAppStore, useUserStore } from '@/store';
import useLicenseStore from '@/store/modules/setting/license';
import { setLoginExpires } from '@/utils/auth';
import { getFirstRouteNameByPermission, routerNameHasPermission } from '@/utils/permission';
const router = useRouter();
const { t } = useI18n();
const userStore = useUserStore();
const appStore = useAppStore();
const licenseStore = useLicenseStore();
async function loginConfig() {
const redirectUrl = new URL(window.location.href);
//
const params = new URLSearchParams(redirectUrl.search);
// "id"
const code = params.get('code');
const state = params.get('state');
let larkCallback;
if (state === 'fit2cloud-lark-qr') {
larkCallback = await getLarkCallback(code || '');
} else {
larkCallback = await getLarkSuiteCallback(code || '');
}
userStore.qrCodeLogin(await larkCallback);
Message.success(t('login.form.login.success'));
const { redirect, ...othersQuery } = router.currentRoute.value.query;
const redirectHasPermission =
redirect &&
![NO_RESOURCE_ROUTE_NAME, NO_PROJECT_ROUTE_NAME].includes(redirect as string) &&
routerNameHasPermission(redirect as string, router.getRoutes());
const currentRouteName = getFirstRouteNameByPermission(router.getRoutes());
const [res] = await Promise.all([getProjectInfo(appStore.currentProjectId), licenseStore.getValidateLicense()]); // license license
if (!res || res.deleted) {
router.push({
name: NO_PROJECT_ROUTE_NAME,
});
}
if (res) {
appStore.setCurrentMenuConfig(res?.moduleIds || []);
}
setLoginExpires();
router.push({
name: redirectHasPermission ? (redirect as string) : currentRouteName,
query: {
...othersQuery,
orgId: appStore.currentOrgId,
pId: appStore.currentProjectId,
},
});
}
onBeforeMount(async () => {
loginConfig();
});
</script>

View File

@ -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`;

View File

@ -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({