Skip to content

Commit 6cca485

Browse files
authored
fix: The x-lowcode-org request header is deleted from the me interface (#1739)
1 parent 97a5bfd commit 6cca485

5 files changed

Lines changed: 32 additions & 25 deletions

File tree

packages/common/composable/defaultGlobalService.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,30 @@ const userState = reactive({
4949
username: '',
5050
token: null,
5151
expireTime: null,
52-
tenantId: ''
52+
tenantId: '',
53+
tenant: []
5354
},
5455
needToLogin: false
5556
})
5657

5758
const getLoginStatus = () => userState.needToLogin
5859

59-
const setNeedToLogin = (value: boolean, tenantId: any) => {
60+
const setNeedToLogin = (value: boolean) => {
6061
userState.needToLogin = value
6162
if (!value) {
62-
const baseUrl = `${window.location.origin}${window.location.pathname}?type=app&`
63-
const id = getBaseInfo().id
64-
const baseTenantId = getBaseInfo().tenantId
65-
66-
// 浏览器Url没有组织id,都默认公共组织,应用id默认为公共组织的应用1
67-
if (!baseTenantId) {
68-
window.location.href = `${baseUrl}id=1&tenant=${tenantId}`
69-
}
70-
71-
if (baseTenantId && !id) {
72-
window.location.href = `${baseUrl}tenant=${baseTenantId}`
73-
}
74-
75-
if (baseTenantId && id) {
76-
window.location = window.location
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+
}
7774
}
75+
window.location.reload()
7876
}
7977
}
8078

@@ -86,7 +84,12 @@ const setUserInfo = (data: any) => {
8684

8785
const fetchUserInfo = () => {
8886
// 获取登录用户信息
89-
return getMetaApi(META_SERVICE.Http).get('/platform-center/api/user/me')
87+
return getMetaApi(META_SERVICE.Http).get('/platform-center/api/user/me', {
88+
transformRequest: (data: any, headers: any) => {
89+
delete headers['x-lowcode-org']
90+
return data
91+
}
92+
})
9093
}
9194

9295
const setTenantInfo = (id: any) => {

packages/common/composable/http/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const createAbortController = (config) => {
117117

118118
// 取消所有进行中的请求
119119
const abortAllRequests = (message = '用户未登录,请求已取消') => {
120-
abortControllers.forEach((controller, key) => {
120+
abortControllers.forEach((controller) => {
121121
controller.abort(message)
122122
})
123123
abortControllers.clear()

packages/design-core/src/login/Login.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default {
4343
},
4444
emits: ['changeStatus'],
4545
setup(props, { emit }) {
46-
const { fetchUserInfo, setUserInfo, setNeedToLogin, getBaseInfo } = getMetaApi(META_SERVICE.GlobalService)
46+
const { fetchUserInfo, setUserInfo, setNeedToLogin } = getMetaApi(META_SERVICE.GlobalService)
4747
const state = reactive({
4848
loginData: {
4949
username: '',
@@ -61,12 +61,14 @@ export default {
6161
localStorage.setItem('engineToken', data.token)
6262
fetchUserInfo().then((infoData: any) => {
6363
if (infoData) {
64-
const tenantId = getBaseInfo().tenantId ? getBaseInfo().tenantId : infoData.tenant[0]?.id
6564
setUserInfo({ ...data, ...infoData })
66-
setNeedToLogin(false, tenantId)
65+
setNeedToLogin(false)
6766
}
6867
})
6968
})
69+
.catch(() => {
70+
setNeedToLogin(true)
71+
})
7072
}
7173
7274
const toRegister = () => {

packages/design-core/src/login/js/useLogin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { reactive } from 'vue'
22

3-
const characters = `!@#$%^&*()_+-=[};":\|,'<>?。`
3+
const characters = `!@#$%^&*()_+-=[};":|,'<>?。`
44
const passwordRules = [
55
{
66
content: ['密码长度8-20个字符。', '密码必须包含:大写字母、小写字母、数字。'],
@@ -9,7 +9,7 @@ const passwordRules = [
99
},
1010
{
1111
content: [`密码必须包含特殊字符:${characters}`],
12-
rule: /^(?=.*[!@#$%^&*()_+\-=[\}\]{;":|,.'<>?]).+$/,
12+
rule: /^(?=.*[!@#$%^&*()_+\-=[}\]{;":|,.'<>?]).+$/,
1313
pass: false
1414
},
1515
{

packages/layout/src/DesignWorkspace.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ export default {
113113
})
114114
const tenantValue = computed(() =>
115115
enableLogin
116-
? tenantList.value.find((item) => item.id === getBaseInfo().tenantId) || tenantList.value[0]
116+
? getBaseInfo().tenantId
117+
? tenantList.value.find((item) => item.id === getBaseInfo().tenantId) || { id: '', label: '请选择组织' }
118+
: tenantList.value[0]
117119
: { ...getBaseInfo(), label: 'Public' }
118120
)
119121

0 commit comments

Comments
 (0)