@jctrans-materials/nuxt 1.0.10 → 1.0.12
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 +3 -3
- package/src/module.ts +1 -0
- package/src/runtime/plugin.ts +37 -9
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jctrans-materials/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.12",
|
|
5
5
|
"description": "Nuxt module for JCtrans UI components",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./src/module.ts"
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
"nuxt": "^3.0.0",
|
|
13
13
|
"vue": "^3.5.26",
|
|
14
14
|
"vue-router": "^4.6.4",
|
|
15
|
-
"@jctrans-materials/comps-vue3": "1.0.
|
|
15
|
+
"@jctrans-materials/comps-vue3": "1.0.12"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"nuxt": "^3.0.0",
|
|
19
|
-
"@jctrans-materials/comps-vue3": "1.0.
|
|
19
|
+
"@jctrans-materials/comps-vue3": "1.0.12"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@nuxt/module-builder": "latest"
|
package/src/module.ts
CHANGED
package/src/runtime/plugin.ts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
// @jctrans-materials/nuxt/runtime/plugin.ts
|
|
2
|
+
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
3
|
+
import {
|
|
4
|
+
initSharedConfig,
|
|
5
|
+
createRequest,
|
|
6
|
+
getAppId,
|
|
7
|
+
} from "@jctrans-materials/comps-vue3";
|
|
3
8
|
|
|
4
|
-
export default defineNuxtPlugin(() => {
|
|
5
|
-
const runtimeConfig = useRuntimeConfig()
|
|
6
|
-
|
|
7
|
-
const sharedConfig =
|
|
8
|
-
runtimeConfig.public?.jctrans?.sharedConfig
|
|
9
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
10
|
+
const runtimeConfig = useRuntimeConfig();
|
|
11
|
+
const sharedConfig = runtimeConfig.public?.jctrans?.sharedConfig;
|
|
9
12
|
|
|
10
13
|
if (sharedConfig) {
|
|
11
|
-
|
|
14
|
+
// 1. 初始化静态配置
|
|
15
|
+
const finalBaseURL: string =
|
|
16
|
+
(runtimeConfig.public.PROD_CLIENT_PROXY_API as string) ||
|
|
17
|
+
sharedConfig.prefixPath;
|
|
18
|
+
|
|
19
|
+
// 1. 初始化静态配置(建议把最新的 URL 也更新进去)
|
|
20
|
+
initSharedConfig({
|
|
21
|
+
...sharedConfig,
|
|
22
|
+
prefixPath: finalBaseURL,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// 2. 🚀 使用 fetch 驱动,并注入 Nuxt 内置的 $fetch
|
|
26
|
+
createRequest("fetch", {
|
|
27
|
+
// 这里将 Nuxt 的 $fetch 注入到适配器中,
|
|
28
|
+
// 它可以享受 Nuxt 所有的 SSR 优化(如在服务器端免请求、自动带上服务器端上下文等)
|
|
29
|
+
fetch: $fetch as any,
|
|
30
|
+
baseURL: finalBaseURL,
|
|
31
|
+
onUnauthorized: () => {
|
|
32
|
+
if (import.meta.client) {
|
|
33
|
+
const appId = sharedConfig.appId || getAppId();
|
|
34
|
+
const currentPath = encodeURIComponent(window.location.pathname);
|
|
35
|
+
// 跳转至登录
|
|
36
|
+
window.location.href = `https://passport.jctrans.com/login?appId=${appId}&path=${currentPath}`;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
});
|
|
12
40
|
}
|
|
13
|
-
})
|
|
41
|
+
});
|