Skip to content

Commit f4b7557

Browse files
perf: Optimize the chat page entry
1 parent 34ca7a9 commit f4b7557

File tree

9 files changed

+52
-13
lines changed

9 files changed

+52
-13
lines changed

frontend/src/components/layout/Person.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Apikey from './Apikey.vue'
1818
import { useRouter } from 'vue-router'
1919
import { useUserStore } from '@/stores/user'
2020
import { userApi } from '@/api/auth'
21+
import { toLoginPage } from '@/utils/utils'
2122
2223
const router = useRouter()
2324
const appearanceStore = useAppearanceStoreWithOut()
@@ -37,7 +38,7 @@ const isLocalUser = computed(() => !userStore.getOrigin)
3738
3839
const platFlag = computed(() => {
3940
const platformInfo = userStore.getPlatformInfo
40-
return platformInfo?.flag || 0
41+
return platformInfo?.origin || 0
4142
})
4243
const dialogVisible = ref(false)
4344
const apikeyDialogVisible = ref(false)
@@ -95,7 +96,8 @@ const savePwdHandler = () => {
9596
}
9697
const logout = async () => {
9798
if (!(await userStore.logout())) {
98-
router.push('/login')
99+
router.push(toLoginPage(router?.currentRoute?.value?.fullPath || ''))
100+
// router.push('/login')
99101
}
100102
}
101103
</script>

frontend/src/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@
667667
"right": "Right",
668668
"welcome_description": "Welcome Description",
669669
"data_analysis_now": "I can query data, generate charts, detect data anomalies, predict data, and more! Enable Smart Data Analysis now!",
670-
"window_entrance_icon": "Floating window entrance icon"
670+
"window_entrance_icon": "Floating window entrance icon",
671+
"preview_error": "The current page prohibits embedding using Iframe!"
671672
},
672673
"chat": {
673674
"type": "Chart Type",

frontend/src/i18n/ko-KR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@
667667
"right": "오른쪽",
668668
"welcome_description": "환영 메시지 설명",
669669
"data_analysis_now": "저는 데이터 조회, 차트 생성, 데이터 이상 감지, 데이터 예측 등을 할 수 있습니다. 빨리 스마트 데이터 조회를 시작하세요~",
670-
"window_entrance_icon": "플로팅 윈도우 입구 아이콘"
670+
"window_entrance_icon": "플로팅 윈도우 입구 아이콘",
671+
"preview_error": "현재 페이지는 Iframe 임베딩을 허용하지 않습니다!"
671672
},
672673
"chat": {
673674
"type": "차트 유형",

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@
667667
"right": "",
668668
"welcome_description": "欢迎语描述",
669669
"data_analysis_now": "我可以查询数据、生成图表、检测数据异常、预测数据等赶快开启智能问数吧~",
670-
"window_entrance_icon": "浮窗入口图标"
670+
"window_entrance_icon": "浮窗入口图标",
671+
"preview_error": "当前页面禁止使用 Iframe 嵌入!"
671672
},
672673
"chat": {
673674
"type": "图表类型",

frontend/src/router/watch.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useUserStore } from '@/stores/user'
55
import { request } from '@/utils/request'
66
import type { Router } from 'vue-router'
77
import { generateDynamicRouters } from './dynamic'
8+
import { toLoginPage } from '@/utils/utils'
89

910
const appearanceStore = useAppearanceStoreWithOut()
1011
const userStore = useUserStore()
@@ -17,7 +18,7 @@ export const watchRouter = (router: Router) => {
1718
await appearanceStore.setAppearance()
1819
LicenseGenerator.generateRouters(router)
1920
if (to.path.startsWith('/login') && userStore.getUid) {
20-
next('/')
21+
next(to?.query?.redirect || '/')
2122
return
2223
}
2324
if (assistantWhiteList.includes(to.path)) {
@@ -31,7 +32,7 @@ export const watchRouter = (router: Router) => {
3132
}
3233
if (!token) {
3334
// ElMessage.error('Please login first')
34-
next('/login')
35+
next(toLoginPage(to.fullPath))
3536
return
3637
}
3738
let isFirstDynamicPath = false

frontend/src/stores/user.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AuthApi } from '@/api/login'
44
import { useCache } from '@/utils/useCache'
55
import { i18n } from '@/i18n'
66
import { store } from './index'
7-
import { getQueryString } from '@/utils/utils'
7+
import { getCurrentRouter, getQueryString } from '@/utils/utils'
88

99
const { wsCache } = useCache()
1010

@@ -99,7 +99,11 @@ export const UserStore = defineStore('user', {
9999
return res
100100
}
101101
if (getQueryString('code') && getQueryString('state')?.includes('oauth2_state')) {
102-
const logout_url = location.origin + location.pathname + '#/login'
102+
const currentPath = getCurrentRouter()
103+
let logout_url = location.origin + location.pathname + '#/login'
104+
if (currentPath) {
105+
logout_url += `?redirect=${currentPath}`
106+
}
103107
window.location.href = logout_url
104108
window.open(res, logout_url)
105109
return logout_url
@@ -135,6 +139,7 @@ export const UserStore = defineStore('user', {
135139
})
136140

137141
this.setLanguage(this.language)
142+
this.platformInfo = wsCache.get('user.platformInfo')
138143
},
139144
setToken(token: string) {
140145
wsCache.set('user.token', token)

frontend/src/utils/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,29 @@ export const isBtnShow = (val: string) => {
103103
}
104104
}
105105

106+
export const toLoginPage = (fullPath: string) => {
107+
if (!fullPath || fullPath === '/') {
108+
return {
109+
path: '/login',
110+
}
111+
}
112+
return {
113+
path: '/login',
114+
query: { redirect: fullPath },
115+
}
116+
}
117+
118+
export const toLoginSuccess = (router: any) => {
119+
const redirect = router?.currentRoute?.value?.query?.redirect
120+
const redirectPath = Array.isArray(redirect) ? redirect[0] : redirect || '/chat'
121+
router.push(redirectPath as string)
122+
}
123+
export const getCurrentRouter = () => {
124+
const hash = location.hash
125+
if (!hash) return null
126+
return hash.replace('#/login?redirect=', '')
127+
}
128+
106129
export const setTitle = (title?: string) => {
107130
document.title = title || 'SQLBot'
108131
}

frontend/src/views/chat/preview.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<div v-loading="divLoading" class="sqlbot-embedded-assistant-page">
3+
<error-page v-if="inIframe" :title="t('embedded.preview_error')" />
34
<chat-component
5+
v-else
46
:welcome="customSet.welcome"
57
:welcome-desc="customSet.welcome_desc"
68
:logo-assistant="logo"
@@ -11,9 +13,10 @@
1113
</template>
1214
<script setup lang="ts">
1315
import ChatComponent from '@/views/chat/index.vue'
14-
import { nextTick, onMounted, reactive, ref } from 'vue'
16+
import { computed, nextTick, onMounted, reactive, ref } from 'vue'
1517
import { useI18n } from 'vue-i18n'
16-
18+
import ErrorPage from '@/views/error/index.vue'
19+
import { isInIframe } from '@/utils/utils'
1720
const { t } = useI18n()
1821
//const chatRef = ref()
1922
@@ -25,9 +28,10 @@ const customSet = reactive({
2528
header_font_color: '#1F2329',
2629
}) as { [key: string]: any }
2730
const logo = ref()
28-
2931
const divLoading = ref(true)
3032
33+
const inIframe = computed(() => isInIframe())
34+
3135
onMounted(() => {
3236
nextTick(() => {
3337
setTimeout(() => {

frontend/src/views/login/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import login_image from '@/assets/embedded/login_image.png'
8585
import { useAppearanceStoreWithOut } from '@/stores/appearance'
8686
import loginImage from '@/assets/blue/login-image_blue.png'
8787
import Handler from './xpack/Handler.vue'
88+
import { toLoginSuccess } from '@/utils/utils'
8889
8990
const showLoading = ref(true)
9091
const router = useRouter()
@@ -118,7 +119,7 @@ const submitForm = () => {
118119
loginFormRef.value.validate((valid: boolean) => {
119120
if (valid) {
120121
userStore.login(loginForm.value).then(() => {
121-
router.push('/chat')
122+
toLoginSuccess(router)
122123
})
123124
}
124125
})

0 commit comments

Comments
 (0)