diff --git a/frontend/src/components/layout/Person.vue b/frontend/src/components/layout/Person.vue index 160ffa4e..a0ada36c 100644 --- a/frontend/src/components/layout/Person.vue +++ b/frontend/src/components/layout/Person.vue @@ -18,6 +18,7 @@ import Apikey from './Apikey.vue' import { useRouter } from 'vue-router' import { useUserStore } from '@/stores/user' import { userApi } from '@/api/auth' +import { toLoginPage } from '@/utils/utils' const router = useRouter() const appearanceStore = useAppearanceStoreWithOut() @@ -37,7 +38,7 @@ const isLocalUser = computed(() => !userStore.getOrigin) const platFlag = computed(() => { const platformInfo = userStore.getPlatformInfo - return platformInfo?.flag || 0 + return platformInfo?.origin || 0 }) const dialogVisible = ref(false) const apikeyDialogVisible = ref(false) @@ -95,7 +96,8 @@ const savePwdHandler = () => { } const logout = async () => { if (!(await userStore.logout())) { - router.push('/login') + router.push(toLoginPage(router?.currentRoute?.value?.fullPath || '')) + // router.push('/login') } } diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index 7c15bae5..684b5b7c 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -667,7 +667,8 @@ "right": "Right", "welcome_description": "Welcome Description", "data_analysis_now": "I can query data, generate charts, detect data anomalies, predict data, and more! Enable Smart Data Analysis now!", - "window_entrance_icon": "Floating window entrance icon" + "window_entrance_icon": "Floating window entrance icon", + "preview_error": "The current page prohibits embedding using Iframe!" }, "chat": { "type": "Chart Type", diff --git a/frontend/src/i18n/ko-KR.json b/frontend/src/i18n/ko-KR.json index 9d389ead..a315c5f0 100644 --- a/frontend/src/i18n/ko-KR.json +++ b/frontend/src/i18n/ko-KR.json @@ -667,7 +667,8 @@ "right": "오른쪽", "welcome_description": "환영 메시지 설명", "data_analysis_now": "저는 데이터 조회, 차트 생성, 데이터 이상 감지, 데이터 예측 등을 할 수 있습니다. 빨리 스마트 데이터 조회를 시작하세요~", - "window_entrance_icon": "플로팅 윈도우 입구 아이콘" + "window_entrance_icon": "플로팅 윈도우 입구 아이콘", + "preview_error": "현재 페이지는 Iframe 임베딩을 허용하지 않습니다!" }, "chat": { "type": "차트 유형", diff --git a/frontend/src/i18n/zh-CN.json b/frontend/src/i18n/zh-CN.json index d3a9b69f..3b5763be 100644 --- a/frontend/src/i18n/zh-CN.json +++ b/frontend/src/i18n/zh-CN.json @@ -667,7 +667,8 @@ "right": "右", "welcome_description": "欢迎语描述", "data_analysis_now": "我可以查询数据、生成图表、检测数据异常、预测数据等赶快开启智能问数吧~", - "window_entrance_icon": "浮窗入口图标" + "window_entrance_icon": "浮窗入口图标", + "preview_error": "当前页面禁止使用 Iframe 嵌入!" }, "chat": { "type": "图表类型", diff --git a/frontend/src/router/watch.ts b/frontend/src/router/watch.ts index c1aaf8fe..c4a2b04f 100644 --- a/frontend/src/router/watch.ts +++ b/frontend/src/router/watch.ts @@ -5,6 +5,7 @@ import { useUserStore } from '@/stores/user' import { request } from '@/utils/request' import type { Router } from 'vue-router' import { generateDynamicRouters } from './dynamic' +import { toLoginPage } from '@/utils/utils' const appearanceStore = useAppearanceStoreWithOut() const userStore = useUserStore() @@ -17,7 +18,7 @@ export const watchRouter = (router: Router) => { await appearanceStore.setAppearance() LicenseGenerator.generateRouters(router) if (to.path.startsWith('/login') && userStore.getUid) { - next('/') + next(to?.query?.redirect || '/') return } if (assistantWhiteList.includes(to.path)) { @@ -31,7 +32,7 @@ export const watchRouter = (router: Router) => { } if (!token) { // ElMessage.error('Please login first') - next('/login') + next(toLoginPage(to.fullPath)) return } let isFirstDynamicPath = false diff --git a/frontend/src/stores/user.ts b/frontend/src/stores/user.ts index 330431af..cc8c13b5 100644 --- a/frontend/src/stores/user.ts +++ b/frontend/src/stores/user.ts @@ -4,7 +4,7 @@ import { AuthApi } from '@/api/login' import { useCache } from '@/utils/useCache' import { i18n } from '@/i18n' import { store } from './index' -import { getQueryString } from '@/utils/utils' +import { getCurrentRouter, getQueryString } from '@/utils/utils' const { wsCache } = useCache() @@ -99,7 +99,11 @@ export const UserStore = defineStore('user', { return res } if (getQueryString('code') && getQueryString('state')?.includes('oauth2_state')) { - const logout_url = location.origin + location.pathname + '#/login' + const currentPath = getCurrentRouter() + let logout_url = location.origin + location.pathname + '#/login' + if (currentPath) { + logout_url += `?redirect=${currentPath}` + } window.location.href = logout_url window.open(res, logout_url) return logout_url @@ -135,6 +139,7 @@ export const UserStore = defineStore('user', { }) this.setLanguage(this.language) + this.platformInfo = wsCache.get('user.platformInfo') }, setToken(token: string) { wsCache.set('user.token', token) diff --git a/frontend/src/utils/utils.ts b/frontend/src/utils/utils.ts index 1373ada5..267e587e 100644 --- a/frontend/src/utils/utils.ts +++ b/frontend/src/utils/utils.ts @@ -103,6 +103,29 @@ export const isBtnShow = (val: string) => { } } +export const toLoginPage = (fullPath: string) => { + if (!fullPath || fullPath === '/') { + return { + path: '/login', + } + } + return { + path: '/login', + query: { redirect: fullPath }, + } +} + +export const toLoginSuccess = (router: any) => { + const redirect = router?.currentRoute?.value?.query?.redirect + const redirectPath = Array.isArray(redirect) ? redirect[0] : redirect || '/chat' + router.push(redirectPath as string) +} +export const getCurrentRouter = () => { + const hash = location.hash + if (!hash) return null + return hash.replace('#/login?redirect=', '') +} + export const setTitle = (title?: string) => { document.title = title || 'SQLBot' } diff --git a/frontend/src/views/chat/preview.vue b/frontend/src/views/chat/preview.vue index 48235d68..e4779404 100644 --- a/frontend/src/views/chat/preview.vue +++ b/frontend/src/views/chat/preview.vue @@ -1,6 +1,8 @@