xto-fronted 0.4.106 → 0.4.107
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/dist/api/index.js +1 -1
- package/dist/{index-Nz8stCJl.js → index-BtwoRQAo.js} +1 -1
- package/dist/{index-01f4mTJg.js → index-CkKlIn7r.js} +1 -1
- package/dist/{index-BnkXUVuB.js → index-DT4MA9Sy.js} +1 -1
- package/dist/{index-BSyHGMA5.js → index-DkyZfVFt.js} +386 -385
- package/dist/{index-ddj4tPtc.js → index-rgbeABpD.js} +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +23 -22
- package/dist/stores/auth.d.ts +2 -2
- package/dist/{user-Qd_jMBaH.js → user-BMcSCtxs.js} +283 -275
- package/dist/utils/request.d.ts +5 -0
- package/package.json +1 -1
- package/src/index.ts +8 -0
- package/src/utils/request.ts +24 -3
package/dist/utils/request.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export interface PageResponse<T> {
|
|
|
17
17
|
* 用于 Nacos 动态配置场景
|
|
18
18
|
*/
|
|
19
19
|
export declare function setApiBaseUrl(url: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* 设置运行时 base 路径
|
|
22
|
+
* 用于登录过期时正确跳转到登录页
|
|
23
|
+
*/
|
|
24
|
+
export declare function setBasePath(base: string): void;
|
|
20
25
|
declare const request: AxiosInstance;
|
|
21
26
|
export declare const http: {
|
|
22
27
|
get<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import './style.scss'
|
|
|
3
3
|
|
|
4
4
|
// 配置
|
|
5
5
|
import { initAppConfig, getAppId, getClientId, getApiBaseUrl } from './utils/config'
|
|
6
|
+
import { setBasePath } from './utils/request'
|
|
6
7
|
import type { LocaleCode } from '@xto/core/locale'
|
|
7
8
|
|
|
8
9
|
// XtoConfig 类型定义
|
|
@@ -11,6 +12,7 @@ export interface XtoConfig {
|
|
|
11
12
|
appId?: string
|
|
12
13
|
clientId?: string
|
|
13
14
|
apiBaseUrl?: string
|
|
15
|
+
basePath?: string
|
|
14
16
|
indexPath?: string
|
|
15
17
|
loginPath?: string
|
|
16
18
|
locale?: LocaleCode
|
|
@@ -28,6 +30,11 @@ export function createXtoApp(config: Partial<XtoConfig>) {
|
|
|
28
30
|
apiBaseUrl: config.apiBaseUrl
|
|
29
31
|
})
|
|
30
32
|
|
|
33
|
+
// 设置 base 路径(用于登录过期时正确跳转)
|
|
34
|
+
if (config.basePath) {
|
|
35
|
+
setBasePath(config.basePath)
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
// 设置应用名称和路径到 store
|
|
32
39
|
import('./stores/app').then(({ useAppStore }) => {
|
|
33
40
|
const appStore = useAppStore()
|
|
@@ -56,6 +63,7 @@ export function createXtoApp(config: Partial<XtoConfig>) {
|
|
|
56
63
|
appId: getAppId(),
|
|
57
64
|
clientId: getClientId(),
|
|
58
65
|
apiBaseUrl: getApiBaseUrl(),
|
|
66
|
+
basePath: config.basePath || '/',
|
|
59
67
|
indexPath: config.indexPath || '/dashboard',
|
|
60
68
|
loginPath: config.loginPath || '/login',
|
|
61
69
|
locale: config.locale || 'zh-CN'
|
package/src/utils/request.ts
CHANGED
|
@@ -32,6 +32,9 @@ export interface PageResponse<T> {
|
|
|
32
32
|
// 运行时 API 基础 URL
|
|
33
33
|
let runtimeApiBaseUrl: string | undefined
|
|
34
34
|
|
|
35
|
+
// 运行时 base 路径
|
|
36
|
+
let runtimeBasePath: string | undefined
|
|
37
|
+
|
|
35
38
|
/**
|
|
36
39
|
* 设置运行时 API 基础 URL
|
|
37
40
|
* 用于 Nacos 动态配置场景
|
|
@@ -44,6 +47,24 @@ export function setApiBaseUrl(url: string) {
|
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
|
|
50
|
+
/**
|
|
51
|
+
* 设置运行时 base 路径
|
|
52
|
+
* 用于登录过期时正确跳转到登录页
|
|
53
|
+
*/
|
|
54
|
+
export function setBasePath(base: string) {
|
|
55
|
+
runtimeBasePath = base
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 获取登录页路径(考虑 base 路径)
|
|
60
|
+
*/
|
|
61
|
+
function getLoginPath(): string {
|
|
62
|
+
const base = runtimeBasePath || import.meta.env.BASE_URL || '/'
|
|
63
|
+
// 确保 base 以 / 结尾,login 不以 / 开头
|
|
64
|
+
const normalizedBase = base.endsWith('/') ? base : base + '/'
|
|
65
|
+
return normalizedBase + 'login'
|
|
66
|
+
}
|
|
67
|
+
|
|
47
68
|
// 创建 axios 实例
|
|
48
69
|
const createRequest = (): AxiosInstance => {
|
|
49
70
|
const instance = axios.create({
|
|
@@ -101,7 +122,7 @@ const createRequest = (): AxiosInstance => {
|
|
|
101
122
|
if (data.code === 9121) {
|
|
102
123
|
Message.error('登录已过期,请重新登录')
|
|
103
124
|
clearToken()
|
|
104
|
-
window.location.href =
|
|
125
|
+
window.location.href = getLoginPath()
|
|
105
126
|
return Promise.reject(new Error(data.message || 'EXPIRED OR INVALID TOKEN'))
|
|
106
127
|
}
|
|
107
128
|
|
|
@@ -118,7 +139,7 @@ const createRequest = (): AxiosInstance => {
|
|
|
118
139
|
if (data?.code === 9121) {
|
|
119
140
|
Message.error('登录已过期,请重新登录')
|
|
120
141
|
clearToken()
|
|
121
|
-
window.location.href =
|
|
142
|
+
window.location.href = getLoginPath()
|
|
122
143
|
return Promise.reject(error)
|
|
123
144
|
}
|
|
124
145
|
|
|
@@ -126,7 +147,7 @@ const createRequest = (): AxiosInstance => {
|
|
|
126
147
|
case 401:
|
|
127
148
|
Message.error('登录已过期,请重新登录')
|
|
128
149
|
clearToken()
|
|
129
|
-
window.location.href =
|
|
150
|
+
window.location.href = getLoginPath()
|
|
130
151
|
break
|
|
131
152
|
case 403:
|
|
132
153
|
Message.error('没有权限访问')
|