@liujitcn/kratos-uni-app-core 0.0.64 → 0.0.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import { computed, onMounted, ref, watch } from 'vue'
|
|
|
3
3
|
import { useUserStore } from '../stores'
|
|
4
4
|
import { navigateToLogin } from '../utils/navigation'
|
|
5
5
|
import { getLanguageOptions, useI18n, type SupportedLocale } from '../locales'
|
|
6
|
+
import { isAuthExpiredError } from '../utils/http'
|
|
6
7
|
import { defMfaService } from '../api/base/v1/mfa'
|
|
7
8
|
import MfaManageDialog from './MfaManageDialog.vue'
|
|
8
9
|
|
|
@@ -15,14 +16,6 @@ defineSlots<{
|
|
|
15
16
|
|
|
16
17
|
const userStore = useUserStore()
|
|
17
18
|
const { locale, setLocale, t } = useI18n()
|
|
18
|
-
/** 登录态失效时请求层已弹窗引导重新登录,页面侧不再叠加失败提示。 */
|
|
19
|
-
const isAuthExpiredError = (error: unknown) => {
|
|
20
|
-
if (error && typeof error === 'object') {
|
|
21
|
-
const statusCode = (error as { statusCode?: number }).statusCode
|
|
22
|
-
if (statusCode === 401 || statusCode === 403) return true
|
|
23
|
-
}
|
|
24
|
-
return error instanceof Error && /auth (required|expired)/.test(error.message)
|
|
25
|
-
}
|
|
26
19
|
|
|
27
20
|
const logoutLoading = ref(false)
|
|
28
21
|
const mfaDialogVisible = ref(false)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'vue'
|
|
2
|
+
import { computed, onMounted } from 'vue'
|
|
3
3
|
import { resolveModuleIcon, resolveStaticView } from '../module'
|
|
4
4
|
import { APP_MENU_ROOT_ID, useAppMenuBadge, useAppNavigation } from '../navigation'
|
|
5
5
|
import { resolveRootMenuId } from '../navigation-tree.mjs'
|
|
@@ -14,6 +14,12 @@ const activeMenu = computed(() => {
|
|
|
14
14
|
})
|
|
15
15
|
const visible = computed(() => Boolean(activeMenu.value && tabBar.value.length))
|
|
16
16
|
const messageBadge = useAppMenuBadge('MESSAGE_INBOX')
|
|
17
|
+
// #ifdef H5
|
|
18
|
+
// H5 端 tabBar.custom 不隐藏内置 tabbar,需手动隐藏,否则其边线从自定义栏上方露出形成双线。
|
|
19
|
+
onMounted(() => {
|
|
20
|
+
uni.hideTabBar({ fail: () => {} })
|
|
21
|
+
})
|
|
22
|
+
// #endif
|
|
17
23
|
</script>
|
|
18
24
|
|
|
19
25
|
<template>
|
package/src/utils/http.ts
CHANGED
|
@@ -74,6 +74,23 @@ type HttpRequestOptions = UniApp.RequestOptions & {
|
|
|
74
74
|
authMode?: AuthMode
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/** 认证缺失或失效错误:抛出前请求层已弹窗引导重新登录,页面侧无需重复提示。 */
|
|
78
|
+
export class AuthPromptError extends Error {
|
|
79
|
+
constructor() {
|
|
80
|
+
super(t('core.auth.session_expired'))
|
|
81
|
+
this.name = 'AuthPromptError'
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 判断错误是否为登录态失效(请求层已弹窗提示,或响应为 401/403)。 */
|
|
86
|
+
export function isAuthExpiredError(error: unknown): boolean {
|
|
87
|
+
if (error && typeof error === 'object') {
|
|
88
|
+
const statusCode = (error as { statusCode?: number }).statusCode
|
|
89
|
+
if (statusCode === 401 || statusCode === 403) return true
|
|
90
|
+
}
|
|
91
|
+
return error instanceof AuthPromptError
|
|
92
|
+
}
|
|
93
|
+
|
|
77
94
|
// 添加拦截器
|
|
78
95
|
const httpInterceptor = {
|
|
79
96
|
// 拦截前触发
|
|
@@ -296,7 +313,7 @@ async function getAccessTokenByMode(authMode: AuthMode) {
|
|
|
296
313
|
if (!getToken()) {
|
|
297
314
|
if (authMode === 'required') {
|
|
298
315
|
await promptRelogin()
|
|
299
|
-
throw new
|
|
316
|
+
throw new AuthPromptError()
|
|
300
317
|
}
|
|
301
318
|
return ''
|
|
302
319
|
}
|
|
@@ -315,7 +332,7 @@ async function getAccessTokenByMode(authMode: AuthMode) {
|
|
|
315
332
|
|
|
316
333
|
if (authMode === 'required') {
|
|
317
334
|
await promptRelogin()
|
|
318
|
-
throw new
|
|
335
|
+
throw new AuthPromptError()
|
|
319
336
|
}
|
|
320
337
|
|
|
321
338
|
silentClearAuthData()
|