Skip to content

Commit 2599cb8

Browse files
committed
fix:Refresh the page after logging in
1 parent e731e10 commit 2599cb8

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

packages/common/composable/defaultGlobalService.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { useMessage, defineService, getMetaApi, META_SERVICE } from '@opentiny/tiny-engine-meta-register'
1+
import {
2+
useCanvas,
3+
useResource,
4+
useMessage,
5+
defineService,
6+
getMetaApi,
7+
META_SERVICE
8+
} from '@opentiny/tiny-engine-meta-register'
29
import { reactive, watch } from 'vue'
310

411
const getBaseInfo = () => {
@@ -55,24 +62,25 @@ const userState = reactive({
5562
needToLogin: false
5663
})
5764

65+
const { subscribe, publish } = useMessage()
66+
5867
const getLoginStatus = () => userState.needToLogin
5968

6069
const setNeedToLogin = (value: boolean) => {
6170
userState.needToLogin = value
71+
6272
if (!value) {
63-
const defaultTenantId = userState.userInfo.tenant?.[0]?.id
64-
if (defaultTenantId) {
65-
const currentUrl = new URL(window.location.href)
66-
const currentTenant = getBaseInfo().tenantId
67-
68-
const filterList = userState.userInfo.tenant.filter((item) => item.id === currentTenant) || []
69-
// 只有当tenant值不存在时才更新
70-
if (!filterList?.length) {
71-
currentUrl.searchParams.set('tenant', String(defaultTenantId))
72-
window.history.replaceState(window.history.state, '', currentUrl.href)
73+
watch(
74+
useCanvas().isCanvasApiReady,
75+
(ready) => {
76+
if (ready) {
77+
useResource().fetchResource()
78+
}
79+
},
80+
{
81+
immediate: true
7382
}
74-
}
75-
window.location.reload()
83+
)
7684
}
7785
}
7886

@@ -104,8 +112,6 @@ const fetchAppInfo = (appId: string) => getMetaApi(META_SERVICE.Http).get(`/app-
104112
const fetchAppList = (platformId: string) =>
105113
getMetaApi(META_SERVICE.Http).get(`/app-center/api/apps/list/${platformId}`)
106114

107-
const { subscribe, publish } = useMessage()
108-
109115
const postLocationHistoryChanged = (data: any) => publish({ topic: 'locationHistoryChanged', data })
110116

111117
/**

packages/common/composable/http/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ const whiteList = [
108108
const notAuthList = ['app-center/api/chat/completions', 'app-center/api/ai/chat', 'app-center/api/ai/search']
109109
const LoginErrorCode = ['CM004', 'CM005', 'CM006', 'CM007', 'CM336', 'CM339']
110110

111+
// 新增:重置认证状态的函数
112+
const resetAuthState = () => {
113+
isUnauthorized = false
114+
abortControllers.clear()
115+
}
116+
111117
// 创建 AbortController 并关联到请求
112118
const createAbortController = (config) => {
113119
const controller = new AbortController()
@@ -191,6 +197,10 @@ const requestHandler = (config) => {
191197
return new Promise(() => {})
192198
}
193199
} else {
200+
// 有 token 时重置认证状态
201+
if (isUnauthorized) {
202+
resetAuthState()
203+
}
194204
if (!notAuthList.some((url) => config.url.includes(url))) {
195205
config.headers.Authorization = `Bearer ${token}`
196206
}

packages/common/js/canvas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface CanvasStatus {
2626
}
2727

2828
export const getCanvasStatus = (data: Occupier | undefined): CanvasStatus => {
29-
const globalState = getMetaApi(META_SERVICE.GlobalService).getState()
29+
const userInfo = getMetaApi(META_SERVICE.GlobalService).getUserInfo()
3030
const isDemo = useResource().appSchemaState.isDemo
3131
let state = ''
3232

@@ -35,7 +35,7 @@ export const getCanvasStatus = (data: Occupier | undefined): CanvasStatus => {
3535
} else if (!data) {
3636
state = PAGE_STATUS.Release
3737
} else {
38-
state = globalState.userInfo.id === data.id ? PAGE_STATUS.Occupy : PAGE_STATUS.Lock
38+
state = userInfo.id === data.id ? PAGE_STATUS.Occupy : PAGE_STATUS.Lock
3939
}
4040

4141
return {

0 commit comments

Comments
 (0)