xto-fronted 0.4.109 → 0.4.110
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-CXDHEqS7.js → index-BMIR-PSJ.js} +1 -1
- package/dist/{index-CzwIDcOh.js → index-C3r5dnEs.js} +1 -1
- package/dist/{index-BRc3QTzT.js → index-CLcJb_H7.js} +1 -1
- package/dist/{index-DpuXxSLr.js → index-Ch8vmOiD.js} +1 -1
- package/dist/{index-Cqe1Z1sC.js → index-DTWHgS2f.js} +361 -359
- package/dist/index.js +47 -46
- package/dist/{user-CnAtwLXY.js → user-CHxvQHYq.js} +380 -375
- package/dist/utils/config.d.ts +6 -0
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/router/layoutRoute.ts +4 -1
- package/src/utils/config.ts +14 -1
package/dist/utils/config.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare function initAppConfig(config: {
|
|
|
19
19
|
appId?: string;
|
|
20
20
|
clientId?: string;
|
|
21
21
|
apiBaseUrl?: string;
|
|
22
|
+
basePath?: string;
|
|
22
23
|
}): void;
|
|
23
24
|
/**
|
|
24
25
|
* 获取 AppId
|
|
@@ -33,8 +34,13 @@ export declare function getClientId(): string;
|
|
|
33
34
|
* 获取 API 基础路径
|
|
34
35
|
*/
|
|
35
36
|
export declare function getApiBaseUrl(): string;
|
|
37
|
+
/**
|
|
38
|
+
* 获取应用基础路径(用于路由 base)
|
|
39
|
+
*/
|
|
40
|
+
export declare function getBasePath(): string;
|
|
36
41
|
export declare const appConfig: {
|
|
37
42
|
appId: import('vue').Ref<string, string>;
|
|
38
43
|
clientId: import('vue').Ref<string, string>;
|
|
39
44
|
apiBaseUrl: import('vue').Ref<string, string>;
|
|
45
|
+
basePath: import('vue').Ref<string, string>;
|
|
40
46
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -39,7 +39,8 @@ export async function createXtoApp(config: Partial<XtoConfig>) {
|
|
|
39
39
|
initAppConfig({
|
|
40
40
|
appId: config.appId,
|
|
41
41
|
clientId: config.clientId,
|
|
42
|
-
apiBaseUrl: baseUrl || config.apiBaseUrl
|
|
42
|
+
apiBaseUrl: baseUrl || config.apiBaseUrl,
|
|
43
|
+
basePath: config.basePath
|
|
43
44
|
})
|
|
44
45
|
|
|
45
46
|
// 设置 base 路径(用于登录过期时正确跳转)
|
|
@@ -6,6 +6,7 @@ import { createRouter as vueCreateRouter, createWebHistory } from 'vue-router'
|
|
|
6
6
|
import type { RouteRecordRaw, Router } from 'vue-router'
|
|
7
7
|
import { h, defineComponent } from 'vue'
|
|
8
8
|
import Layout from '@/components/Layout/index.vue'
|
|
9
|
+
import { getBasePath } from '@/utils/config'
|
|
9
10
|
|
|
10
11
|
interface LayoutRouteOptions {
|
|
11
12
|
indexPath?: string
|
|
@@ -63,8 +64,10 @@ export function createLayoutRoute(
|
|
|
63
64
|
* @returns 路由实例
|
|
64
65
|
*/
|
|
65
66
|
export function createRouter(routes: RouteRecordRaw[], options: CreateRouterOptions = {}): Router {
|
|
67
|
+
// 优先使用传入的 base,否则使用全局配置的 basePath
|
|
68
|
+
const base = options.base || getBasePath()
|
|
66
69
|
return vueCreateRouter({
|
|
67
|
-
history: createWebHistory(
|
|
70
|
+
history: createWebHistory(base),
|
|
68
71
|
routes,
|
|
69
72
|
scrollBehavior: () => ({ left: 0, top: 0 })
|
|
70
73
|
})
|
package/src/utils/config.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { ref } from 'vue'
|
|
|
12
12
|
const appId = ref<string>('')
|
|
13
13
|
const clientId = ref<string>('')
|
|
14
14
|
const apiBaseUrl = ref<string>('')
|
|
15
|
+
const basePath = ref<string>('')
|
|
15
16
|
|
|
16
17
|
// 运行时配置是否已加载
|
|
17
18
|
let runtimeConfigLoaded = false
|
|
@@ -61,6 +62,7 @@ export function initAppConfig(config: {
|
|
|
61
62
|
appId?: string
|
|
62
63
|
clientId?: string
|
|
63
64
|
apiBaseUrl?: string
|
|
65
|
+
basePath?: string
|
|
64
66
|
}) {
|
|
65
67
|
if (config.appId) {
|
|
66
68
|
appId.value = config.appId
|
|
@@ -71,6 +73,9 @@ export function initAppConfig(config: {
|
|
|
71
73
|
if (config.apiBaseUrl) {
|
|
72
74
|
apiBaseUrl.value = config.apiBaseUrl
|
|
73
75
|
}
|
|
76
|
+
if (config.basePath) {
|
|
77
|
+
basePath.value = config.basePath
|
|
78
|
+
}
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
/**
|
|
@@ -127,9 +132,17 @@ export function getApiBaseUrl(): string {
|
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
134
|
|
|
135
|
+
/**
|
|
136
|
+
* 获取应用基础路径(用于路由 base)
|
|
137
|
+
*/
|
|
138
|
+
export function getBasePath(): string {
|
|
139
|
+
return basePath.value
|
|
140
|
+
}
|
|
141
|
+
|
|
130
142
|
// 导出响应式引用(供特殊场景直接使用)
|
|
131
143
|
export const appConfig = {
|
|
132
144
|
appId,
|
|
133
145
|
clientId,
|
|
134
|
-
apiBaseUrl
|
|
146
|
+
apiBaseUrl,
|
|
147
|
+
basePath
|
|
135
148
|
}
|