@jctrans-materials/nuxt4 1.0.41-beta.10

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.
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ const kit = require('nuxt/kit');
4
+ const defu = require('defu');
5
+
6
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
+ const module$1 = kit.defineNuxtModule({
8
+ meta: {
9
+ name: "@jctrans-materials/nuxt4",
10
+ configKey: "jctrans",
11
+ compatibility: {
12
+ nuxt: ">=3.0.0"
13
+ }
14
+ },
15
+ defaults: {
16
+ addStyle: true,
17
+ sharedConfig: {},
18
+ tracking: {
19
+ enabled: true,
20
+ autoInit: true,
21
+ directiveName: "gio-track",
22
+ globalVarName: "__JCTRANS_GIO_CONFIG__",
23
+ initOptions: {
24
+ debug: false,
25
+ trackPage: false,
26
+ autoTrackPage: false,
27
+ performance: {
28
+ monitor: true,
29
+ exception: true
30
+ }
31
+ }
32
+ }
33
+ },
34
+ async setup(options, nuxt) {
35
+ const { resolve } = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
36
+ nuxt.options.runtimeConfig.public ||= {};
37
+ nuxt.options.runtimeConfig.public.jctrans = defu.defu(
38
+ nuxt.options.runtimeConfig.public.jctrans,
39
+ {
40
+ sharedConfig: options.sharedConfig,
41
+ tracking: options.tracking
42
+ }
43
+ );
44
+ if (options.addStyle) {
45
+ nuxt.options.css.push("@jctrans-materials/comps-vue3/index.css");
46
+ }
47
+ [
48
+ "JcSearch",
49
+ "JcLoginDialog",
50
+ "ApplyDataDialog",
51
+ "JcMSearch",
52
+ "GlobalModal",
53
+ "JcVerifySlide",
54
+ "JcCarrierSearch",
55
+ "AirCarrierSearch",
56
+ "SeaCarrierSearch",
57
+ "AirLineSearch",
58
+ "SeaLineSearch",
59
+ "LineCascader"
60
+ ].forEach((name) => {
61
+ kit.addComponent({
62
+ name,
63
+ export: name,
64
+ filePath: "@jctrans-materials/comps-vue3"
65
+ });
66
+ });
67
+ nuxt.options.build.transpile.push(
68
+ "@jctrans-materials/comps-vue3",
69
+ "element-plus"
70
+ );
71
+ kit.addPlugin({
72
+ src: resolve("./runtime/plugin"),
73
+ mode: "all"
74
+ });
75
+ kit.addPlugin({
76
+ src: resolve("./runtime/gio.client"),
77
+ mode: "client"
78
+ });
79
+ kit.addPlugin({
80
+ src: resolve("./runtime/gio.server"),
81
+ mode: "server"
82
+ });
83
+ kit.addPlugin({
84
+ src: resolve("./runtime/plugin.client"),
85
+ mode: "client"
86
+ });
87
+ kit.addTypeTemplate({
88
+ filename: "types/jctrans-materials-nuxt4.d.ts",
89
+ src: resolve("./runtime/types.d.ts")
90
+ });
91
+ kit.addRouteMiddleware({
92
+ name: "jctrans-global-auth",
93
+ path: resolve("./runtime/middleware/auth"),
94
+ global: true
95
+ });
96
+ }
97
+ });
98
+
99
+ module.exports = module$1;
@@ -0,0 +1,51 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { SharedConfig } from '@jctrans-materials/comps-vue3';
3
+
4
+ interface TrackingPerformanceNetwork {
5
+ exclude?: string | RegExp | Array<string | RegExp>;
6
+ }
7
+ interface TrackingPerformanceOptions {
8
+ monitor?: boolean;
9
+ exception?: boolean;
10
+ network?: TrackingPerformanceNetwork | boolean;
11
+ }
12
+ interface TrackingInitOptions {
13
+ debug?: boolean;
14
+ serverUrl?: string;
15
+ trackPage?: boolean;
16
+ forceLogin?: boolean;
17
+ idMapping?: boolean;
18
+ hashtag?: boolean;
19
+ autoTrackPage?: boolean;
20
+ performance?: TrackingPerformanceOptions;
21
+ [key: string]: any;
22
+ }
23
+ interface TrackingOptions {
24
+ enabled?: boolean;
25
+ autoInit?: boolean;
26
+ directiveName?: string;
27
+ globalVarName?: string;
28
+ accountId?: string;
29
+ dataSourceId?: string;
30
+ appId?: string;
31
+ initOptions?: TrackingInitOptions;
32
+ }
33
+ interface ModuleOptions {
34
+ addStyle?: boolean;
35
+ sharedConfig?: Partial<SharedConfig>;
36
+ tracking?: TrackingOptions;
37
+ }
38
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
39
+
40
+ declare module "@nuxt/schema" {
41
+ interface PublicRuntimeConfig {
42
+ jctrans?: {
43
+ sharedConfig?: Partial<SharedConfig>;
44
+ appId?: string;
45
+ tracking?: TrackingOptions;
46
+ };
47
+ }
48
+ }
49
+
50
+ export = _default;
51
+ export type { ModuleOptions, TrackingInitOptions, TrackingOptions, TrackingPerformanceNetwork, TrackingPerformanceOptions };
@@ -0,0 +1,51 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { SharedConfig } from '@jctrans-materials/comps-vue3';
3
+
4
+ interface TrackingPerformanceNetwork {
5
+ exclude?: string | RegExp | Array<string | RegExp>;
6
+ }
7
+ interface TrackingPerformanceOptions {
8
+ monitor?: boolean;
9
+ exception?: boolean;
10
+ network?: TrackingPerformanceNetwork | boolean;
11
+ }
12
+ interface TrackingInitOptions {
13
+ debug?: boolean;
14
+ serverUrl?: string;
15
+ trackPage?: boolean;
16
+ forceLogin?: boolean;
17
+ idMapping?: boolean;
18
+ hashtag?: boolean;
19
+ autoTrackPage?: boolean;
20
+ performance?: TrackingPerformanceOptions;
21
+ [key: string]: any;
22
+ }
23
+ interface TrackingOptions {
24
+ enabled?: boolean;
25
+ autoInit?: boolean;
26
+ directiveName?: string;
27
+ globalVarName?: string;
28
+ accountId?: string;
29
+ dataSourceId?: string;
30
+ appId?: string;
31
+ initOptions?: TrackingInitOptions;
32
+ }
33
+ interface ModuleOptions {
34
+ addStyle?: boolean;
35
+ sharedConfig?: Partial<SharedConfig>;
36
+ tracking?: TrackingOptions;
37
+ }
38
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
39
+
40
+ declare module "@nuxt/schema" {
41
+ interface PublicRuntimeConfig {
42
+ jctrans?: {
43
+ sharedConfig?: Partial<SharedConfig>;
44
+ appId?: string;
45
+ tracking?: TrackingOptions;
46
+ };
47
+ }
48
+ }
49
+
50
+ export { _default as default };
51
+ export type { ModuleOptions, TrackingInitOptions, TrackingOptions, TrackingPerformanceNetwork, TrackingPerformanceOptions };
@@ -0,0 +1,51 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { SharedConfig } from '@jctrans-materials/comps-vue3';
3
+
4
+ interface TrackingPerformanceNetwork {
5
+ exclude?: string | RegExp | Array<string | RegExp>;
6
+ }
7
+ interface TrackingPerformanceOptions {
8
+ monitor?: boolean;
9
+ exception?: boolean;
10
+ network?: TrackingPerformanceNetwork | boolean;
11
+ }
12
+ interface TrackingInitOptions {
13
+ debug?: boolean;
14
+ serverUrl?: string;
15
+ trackPage?: boolean;
16
+ forceLogin?: boolean;
17
+ idMapping?: boolean;
18
+ hashtag?: boolean;
19
+ autoTrackPage?: boolean;
20
+ performance?: TrackingPerformanceOptions;
21
+ [key: string]: any;
22
+ }
23
+ interface TrackingOptions {
24
+ enabled?: boolean;
25
+ autoInit?: boolean;
26
+ directiveName?: string;
27
+ globalVarName?: string;
28
+ accountId?: string;
29
+ dataSourceId?: string;
30
+ appId?: string;
31
+ initOptions?: TrackingInitOptions;
32
+ }
33
+ interface ModuleOptions {
34
+ addStyle?: boolean;
35
+ sharedConfig?: Partial<SharedConfig>;
36
+ tracking?: TrackingOptions;
37
+ }
38
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
39
+
40
+ declare module "@nuxt/schema" {
41
+ interface PublicRuntimeConfig {
42
+ jctrans?: {
43
+ sharedConfig?: Partial<SharedConfig>;
44
+ appId?: string;
45
+ tracking?: TrackingOptions;
46
+ };
47
+ }
48
+ }
49
+
50
+ export = _default;
51
+ export type { ModuleOptions, TrackingInitOptions, TrackingOptions, TrackingPerformanceNetwork, TrackingPerformanceOptions };
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@jctrans-materials/nuxt4",
3
+ "configKey": "jctrans",
4
+ "compatibility": {
5
+ "nuxt": ">=3.0.0"
6
+ },
7
+ "version": "1.0.41-beta.3",
8
+ "builder": {
9
+ "@nuxt/module-builder": "1.0.2",
10
+ "unbuild": "3.6.1"
11
+ }
12
+ }
@@ -0,0 +1,96 @@
1
+ import { defineNuxtModule, createResolver, addComponent, addPlugin, addTypeTemplate, addRouteMiddleware } from 'nuxt/kit';
2
+ import { defu } from 'defu';
3
+
4
+ const module$1 = defineNuxtModule({
5
+ meta: {
6
+ name: "@jctrans-materials/nuxt4",
7
+ configKey: "jctrans",
8
+ compatibility: {
9
+ nuxt: ">=3.0.0"
10
+ }
11
+ },
12
+ defaults: {
13
+ addStyle: true,
14
+ sharedConfig: {},
15
+ tracking: {
16
+ enabled: true,
17
+ autoInit: true,
18
+ directiveName: "gio-track",
19
+ globalVarName: "__JCTRANS_GIO_CONFIG__",
20
+ initOptions: {
21
+ debug: false,
22
+ trackPage: false,
23
+ autoTrackPage: false,
24
+ performance: {
25
+ monitor: true,
26
+ exception: true
27
+ }
28
+ }
29
+ }
30
+ },
31
+ async setup(options, nuxt) {
32
+ const { resolve } = createResolver(import.meta.url);
33
+ nuxt.options.runtimeConfig.public ||= {};
34
+ nuxt.options.runtimeConfig.public.jctrans = defu(
35
+ nuxt.options.runtimeConfig.public.jctrans,
36
+ {
37
+ sharedConfig: options.sharedConfig,
38
+ tracking: options.tracking
39
+ }
40
+ );
41
+ if (options.addStyle) {
42
+ nuxt.options.css.push("@jctrans-materials/comps-vue3/index.css");
43
+ }
44
+ [
45
+ "JcSearch",
46
+ "JcLoginDialog",
47
+ "ApplyDataDialog",
48
+ "JcMSearch",
49
+ "GlobalModal",
50
+ "JcVerifySlide",
51
+ "JcCarrierSearch",
52
+ "AirCarrierSearch",
53
+ "SeaCarrierSearch",
54
+ "AirLineSearch",
55
+ "SeaLineSearch",
56
+ "LineCascader"
57
+ ].forEach((name) => {
58
+ addComponent({
59
+ name,
60
+ export: name,
61
+ filePath: "@jctrans-materials/comps-vue3"
62
+ });
63
+ });
64
+ nuxt.options.build.transpile.push(
65
+ "@jctrans-materials/comps-vue3",
66
+ "element-plus"
67
+ );
68
+ addPlugin({
69
+ src: resolve("./runtime/plugin"),
70
+ mode: "all"
71
+ });
72
+ addPlugin({
73
+ src: resolve("./runtime/gio.client"),
74
+ mode: "client"
75
+ });
76
+ addPlugin({
77
+ src: resolve("./runtime/gio.server"),
78
+ mode: "server"
79
+ });
80
+ addPlugin({
81
+ src: resolve("./runtime/plugin.client"),
82
+ mode: "client"
83
+ });
84
+ addTypeTemplate({
85
+ filename: "types/jctrans-materials-nuxt4.d.ts",
86
+ src: resolve("./runtime/types.d.ts")
87
+ });
88
+ addRouteMiddleware({
89
+ name: "jctrans-global-auth",
90
+ path: resolve("./runtime/middleware/auth"),
91
+ global: true
92
+ });
93
+ }
94
+ });
95
+
96
+ export { module$1 as default };
@@ -0,0 +1,3 @@
1
+ import "gio-webjs-sdk";
2
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
3
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import { defineNuxtPlugin } from "#app";
2
+ import "gio-webjs-sdk";
3
+ export default defineNuxtPlugin({
4
+ name: "jctrans-gio-sdk-loader",
5
+ enforce: "pre",
6
+ setup() {
7
+ if (process.dev && typeof window !== "undefined") {
8
+ if (typeof window.gdp !== "function") {
9
+ console.warn(
10
+ "[GIO] SDK \u5DF2\u5F15\u5165\uFF0C\u4F46 window.gdp \u4ECD\u4E0D\u53EF\u7528\uFF0C\u8BF7\u68C0\u67E5\u6253\u5305/\u8FD0\u884C\u73AF\u5883"
11
+ );
12
+ }
13
+ }
14
+ }
15
+ });
@@ -0,0 +1,28 @@
1
+ declare const _default: import("#app").Plugin<{
2
+ gio: {
3
+ init: () => void;
4
+ track: () => void;
5
+ isInitialized: () => boolean;
6
+ isBrowser: () => boolean;
7
+ setUserId: () => void;
8
+ clearUserId: () => void;
9
+ setGeneralProps: () => void;
10
+ setPageAttributes: () => void;
11
+ sendPage: () => void;
12
+ };
13
+ trackEvent: () => void;
14
+ }> & import("#app").ObjectPlugin<{
15
+ gio: {
16
+ init: () => void;
17
+ track: () => void;
18
+ isInitialized: () => boolean;
19
+ isBrowser: () => boolean;
20
+ setUserId: () => void;
21
+ clearUserId: () => void;
22
+ setGeneralProps: () => void;
23
+ setPageAttributes: () => void;
24
+ sendPage: () => void;
25
+ };
26
+ trackEvent: () => void;
27
+ }>;
28
+ export default _default;
@@ -0,0 +1,42 @@
1
+ import { defineNuxtPlugin, useRuntimeConfig } from "#app";
2
+ const normalizeDirectiveName = (value) => {
3
+ if (typeof value !== "string") return "gio-track";
4
+ const trimmed = value.trim();
5
+ if (!trimmed) return "gio-track";
6
+ return trimmed.replace(/^v-/, "");
7
+ };
8
+ export default defineNuxtPlugin((nuxtApp) => {
9
+ const runtimeConfig = useRuntimeConfig();
10
+ const directiveName = normalizeDirectiveName(
11
+ runtimeConfig.public?.jctrans?.tracking?.directiveName
12
+ );
13
+ nuxtApp.vueApp.directive("gio-track", {});
14
+ if (directiveName !== "gio-track") {
15
+ nuxtApp.vueApp.directive(directiveName, {});
16
+ }
17
+ const mockGio = {
18
+ init: () => {
19
+ },
20
+ track: () => {
21
+ },
22
+ isInitialized: () => false,
23
+ isBrowser: () => false,
24
+ setUserId: () => {
25
+ },
26
+ clearUserId: () => {
27
+ },
28
+ setGeneralProps: () => {
29
+ },
30
+ setPageAttributes: () => {
31
+ },
32
+ sendPage: () => {
33
+ }
34
+ };
35
+ return {
36
+ provide: {
37
+ gio: mockGio,
38
+ trackEvent: () => {
39
+ }
40
+ }
41
+ };
42
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("#app").RouteMiddleware;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { defineNuxtRouteMiddleware } from "#app";
2
+ export default defineNuxtRouteMiddleware((to, from) => {
3
+ });
@@ -0,0 +1,18 @@
1
+ type TrackAttrs = Record<string, string | number | Array<string | number>>;
2
+ type GioPublicApi = {
3
+ isInitialized: () => boolean;
4
+ isBrowser: () => boolean;
5
+ init: (...args: any[]) => void;
6
+ track: (eventName: string, attrs?: TrackAttrs, callback?: () => void) => void;
7
+ setGeneralProps: (props: Record<string, any>) => void;
8
+ setPageAttributes: (props: Record<string, any>) => void;
9
+ sendPage: () => void;
10
+ };
11
+ declare const _default: import("#app").Plugin<{
12
+ gio: GioPublicApi;
13
+ trackEvent: (eventName: string, attrs?: TrackAttrs) => void;
14
+ }> & import("#app").ObjectPlugin<{
15
+ gio: GioPublicApi;
16
+ trackEvent: (eventName: string, attrs?: TrackAttrs) => void;
17
+ }>;
18
+ export default _default;
@@ -0,0 +1,251 @@
1
+ import { callOnce, defineNuxtPlugin, useRuntimeConfig, useRouter } from "#app";
2
+ import {
3
+ getOrCreateClientId,
4
+ normalizeClickPageAttrs,
5
+ tracker
6
+ } from "@jctrans-materials/shared";
7
+ import { nextTick } from "vue";
8
+ const pickString = (...values) => {
9
+ for (const value of values) {
10
+ if (typeof value === "string") {
11
+ const trimmed = value.trim();
12
+ if (trimmed) return trimmed;
13
+ }
14
+ }
15
+ return "";
16
+ };
17
+ const pickBoolean = (...values) => {
18
+ for (const value of values) {
19
+ if (typeof value === "boolean") return value;
20
+ if (typeof value === "string") {
21
+ const normalized = value.trim().toLowerCase();
22
+ if (normalized === "true") return true;
23
+ if (normalized === "false") return false;
24
+ }
25
+ }
26
+ return void 0;
27
+ };
28
+ const getGlobalTrackingConfig = (globalVarName) => {
29
+ if (typeof window === "undefined") return {};
30
+ const currentWindow = window;
31
+ const fromCustom = currentWindow?.[globalVarName];
32
+ const fromJctrans = currentWindow?.__JCTRANS_GIO_CONFIG__;
33
+ const fromDefault = currentWindow?.__GIO_CONFIG__;
34
+ const finalConfig = fromCustom || fromJctrans || fromDefault;
35
+ if (finalConfig && typeof finalConfig === "object") {
36
+ return finalConfig;
37
+ }
38
+ return {};
39
+ };
40
+ const normalizeDirectiveName = (value) => {
41
+ const raw = pickString(value);
42
+ const name = raw || "gio-track";
43
+ return name.replace(/^v-/, "");
44
+ };
45
+ const normalizeBinding = (binding) => {
46
+ const value = binding.value;
47
+ if (typeof value === "string") {
48
+ const eventName2 = value.trim();
49
+ return {
50
+ eventName: eventName2,
51
+ trigger: "click",
52
+ attrs: {},
53
+ once: false,
54
+ stop: false,
55
+ prevent: false
56
+ };
57
+ }
58
+ if (!value || typeof value !== "object") {
59
+ return {
60
+ eventName: "",
61
+ trigger: "click",
62
+ attrs: {},
63
+ once: false,
64
+ stop: false,
65
+ prevent: false
66
+ };
67
+ }
68
+ const eventName = pickString(value.event, value.name, binding.arg);
69
+ const trigger = pickString(value.trigger) || "click";
70
+ const attrs = value.attributes || value.attrs || {};
71
+ return {
72
+ eventName,
73
+ trigger,
74
+ attrs,
75
+ once: Boolean(value.once),
76
+ stop: Boolean(value.stop),
77
+ prevent: Boolean(value.prevent),
78
+ callback: typeof value.onTracked === "function" ? value.onTracked : typeof value.callback === "function" ? value.callback : void 0
79
+ };
80
+ };
81
+ const removeElementHandler = (element) => {
82
+ const bound = element.__jctransTrackHandler__;
83
+ if (!bound) return;
84
+ element.removeEventListener(bound.trigger, bound.handler);
85
+ delete element.__jctransTrackHandler__;
86
+ };
87
+ const bindTrackHandler = (element, binding, gio) => {
88
+ removeElementHandler(element);
89
+ const normalized = normalizeBinding(binding);
90
+ if (!normalized.eventName) return;
91
+ const handler = (event) => {
92
+ if (normalized.prevent && "preventDefault" in event) {
93
+ event.preventDefault();
94
+ }
95
+ if (normalized.stop && "stopPropagation" in event) {
96
+ event.stopPropagation();
97
+ }
98
+ const normalizedAttrs = normalizeClickPageAttrs(
99
+ normalized.eventName,
100
+ normalized.attrs
101
+ );
102
+ gio.track(normalized.eventName, normalizedAttrs, () => {
103
+ normalized.callback?.({
104
+ event,
105
+ eventName: normalized.eventName,
106
+ attrs: normalizedAttrs,
107
+ trigger: normalized.trigger
108
+ });
109
+ });
110
+ if (normalized.once) {
111
+ removeElementHandler(element);
112
+ }
113
+ };
114
+ element.addEventListener(normalized.trigger, handler);
115
+ element.__jctransTrackHandler__ = {
116
+ eventName: normalized.eventName,
117
+ trigger: normalized.trigger,
118
+ handler
119
+ };
120
+ };
121
+ const identifyDeviceIfNeeded = async (forceLogin, key = "jctrans-gio-identify-device") => {
122
+ if (!import.meta.client || !forceLogin) return;
123
+ await callOnce(key, () => {
124
+ const deviceId = getOrCreateClientId();
125
+ if (!deviceId) return;
126
+ const gdp = window.gdp;
127
+ if (typeof gdp === "function") {
128
+ gdp("identify", deviceId);
129
+ }
130
+ });
131
+ };
132
+ export default defineNuxtPlugin((nuxtApp) => {
133
+ const runtimeConfig = useRuntimeConfig();
134
+ const router = useRouter();
135
+ const gio = tracker;
136
+ const runtimeTracking = runtimeConfig.public?.jctrans?.tracking || {};
137
+ const globalVarName = pickString(
138
+ runtimeTracking.globalVarName,
139
+ "__JCTRANS_GIO_CONFIG__"
140
+ );
141
+ const globalTracking = getGlobalTrackingConfig(globalVarName);
142
+ const metaEnv = import.meta.env || {};
143
+ const enabled = pickBoolean(runtimeTracking.enabled, globalTracking.enabled);
144
+ if (enabled === false) {
145
+ return {
146
+ provide: {
147
+ gio,
148
+ trackEvent: () => {
149
+ }
150
+ }
151
+ };
152
+ }
153
+ const initOptions = {
154
+ ...runtimeTracking.initOptions || {},
155
+ ...globalTracking.initOptions || {}
156
+ };
157
+ if (!initOptions.serverUrl) {
158
+ const serverUrl = pickString(
159
+ runtimeConfig.public?.GIO_SERVER_URL,
160
+ runtimeConfig.public?.gioServerUrl,
161
+ globalTracking?.serverUrl,
162
+ runtimeTracking?.serverUrl
163
+ );
164
+ if (serverUrl) {
165
+ initOptions.serverUrl = serverUrl;
166
+ }
167
+ }
168
+ const accountId = pickString(
169
+ globalTracking.accountId,
170
+ runtimeTracking.accountId,
171
+ runtimeConfig.public?.gioAccountId,
172
+ runtimeConfig.public?.GIO_ACCOUNT_ID,
173
+ metaEnv.VITE_GIO_ACCOUNT_ID
174
+ );
175
+ const dataSourceId = pickString(
176
+ globalTracking.dataSourceId,
177
+ runtimeTracking.dataSourceId,
178
+ runtimeConfig.public?.gioDataSourceId,
179
+ runtimeConfig.public?.GIO_DATA_SOURCE_ID,
180
+ metaEnv.VITE_GIO_DATA_SOURCE_ID
181
+ );
182
+ const appId = pickString(
183
+ globalTracking.appId,
184
+ runtimeTracking.appId,
185
+ runtimeConfig.public?.gioAppId,
186
+ runtimeConfig.public?.GIO_APP_ID,
187
+ metaEnv.VITE_GIO_APP_ID
188
+ );
189
+ const autoInit = pickBoolean(
190
+ runtimeTracking.autoInit,
191
+ globalTracking.autoInit
192
+ );
193
+ const forceLogin = pickBoolean(
194
+ globalTracking.initOptions?.forceLogin,
195
+ runtimeTracking.initOptions?.forceLogin,
196
+ initOptions.forceLogin
197
+ ) ?? false;
198
+ if ((autoInit ?? true) && accountId && dataSourceId && !gio.isInitialized()) {
199
+ if (appId) {
200
+ gio.init(accountId, dataSourceId, appId, initOptions);
201
+ } else {
202
+ gio.init(accountId, dataSourceId, initOptions);
203
+ }
204
+ void identifyDeviceIfNeeded(
205
+ forceLogin,
206
+ `jctrans-gio-identify-device:${accountId}:${dataSourceId}`
207
+ );
208
+ }
209
+ const trackEvent = (eventName, attrs) => {
210
+ const normalizedEvent = pickString(eventName);
211
+ if (!normalizedEvent) return;
212
+ gio.track(normalizedEvent, normalizeClickPageAttrs(normalizedEvent, attrs));
213
+ };
214
+ const directiveName = normalizeDirectiveName(
215
+ globalTracking.directiveName || runtimeTracking.directiveName
216
+ );
217
+ const trackDirective = {
218
+ mounted(element, binding) {
219
+ bindTrackHandler(element, binding, gio);
220
+ },
221
+ updated(element, binding) {
222
+ if (JSON.stringify(binding.value) !== JSON.stringify(binding.oldValue)) {
223
+ bindTrackHandler(element, binding, gio);
224
+ }
225
+ },
226
+ beforeUnmount(element) {
227
+ removeElementHandler(element);
228
+ }
229
+ };
230
+ nuxtApp.vueApp.directive(directiveName, trackDirective);
231
+ if (initOptions.trackPage === false && initOptions.autoTrackPage) {
232
+ if (import.meta.client) {
233
+ router.afterEach((to) => {
234
+ setTimeout(async () => {
235
+ await nextTick();
236
+ gio.setPageAttributes({
237
+ route_name: String(to.name || ""),
238
+ route_path: to.path
239
+ });
240
+ gio.sendPage();
241
+ }, 50);
242
+ });
243
+ }
244
+ }
245
+ return {
246
+ provide: {
247
+ gio,
248
+ trackEvent
249
+ }
250
+ };
251
+ });
@@ -0,0 +1,6 @@
1
+ declare const _default: import("#app").Plugin<{
2
+ initAuthSharedConfig: (newConfig: Partial<import("@jctrans-materials/shared").SharedConfig>) => void;
3
+ }> & import("#app").ObjectPlugin<{
4
+ initAuthSharedConfig: (newConfig: Partial<import("@jctrans-materials/shared").SharedConfig>) => void;
5
+ }>;
6
+ export default _default;
@@ -0,0 +1,37 @@
1
+ import { defineNuxtPlugin, useRuntimeConfig } from "#app";
2
+ import {
3
+ initSharedConfig,
4
+ createRequest,
5
+ getAppId
6
+ } from "@jctrans-materials/comps-vue3";
7
+ import { ZINDEX_INJECTION_KEY } from "element-plus";
8
+ import { ref } from "vue";
9
+ export default defineNuxtPlugin((nuxtApp) => {
10
+ nuxtApp.vueApp.provide(ZINDEX_INJECTION_KEY, { zIndex: ref(0) });
11
+ const runtimeConfig = useRuntimeConfig();
12
+ const sharedConfig = runtimeConfig.public?.jctrans?.sharedConfig;
13
+ if (sharedConfig) {
14
+ const finalBaseURL = runtimeConfig.public.PROD_CLIENT_PROXY_API || sharedConfig.prefixPath || "";
15
+ const LOGIN_PAGE = runtimeConfig.public.APP_LOGIN_PAGE;
16
+ initSharedConfig({
17
+ ...sharedConfig,
18
+ prefixPath: finalBaseURL
19
+ });
20
+ createRequest("fetch", {
21
+ fetch: $fetch,
22
+ baseURL: finalBaseURL,
23
+ onUnauthorized: () => {
24
+ if (import.meta.client) {
25
+ const appId = sharedConfig.appId || getAppId();
26
+ const currentPath = encodeURIComponent(window.location.pathname);
27
+ window.location.href = `${LOGIN_PAGE || `https://passport.jctrans.com`}/login?appId=${appId}&path=${currentPath}`;
28
+ }
29
+ }
30
+ });
31
+ }
32
+ return {
33
+ provide: {
34
+ initAuthSharedConfig: initSharedConfig
35
+ }
36
+ };
37
+ });
@@ -0,0 +1,39 @@
1
+ // src/runtime/types.d.ts — Nuxt 4 适配版
2
+ import { initSharedConfig } from "@jctrans-materials/comps-vue3";
3
+
4
+ type TrackAttrs = Record<string, string | number | Array<string | number>>;
5
+
6
+ type GioPublicApi = {
7
+ isInitialized: () => boolean;
8
+ isBrowser: () => boolean;
9
+ init: (...args: any[]) => void;
10
+ track: (eventName: string, attrs?: TrackAttrs, callback?: () => void) => void;
11
+ setGeneralProps: (props: Record<string, any>) => void;
12
+ setPageAttributes: (props: Record<string, any>) => void;
13
+ sendPage: () => void;
14
+ };
15
+
16
+ declare module "#app" {
17
+ interface NuxtApp {
18
+ $initAuthSharedConfig: typeof initSharedConfig;
19
+ $gio: GioPublicApi;
20
+ $trackEvent: (eventName: string, attrs?: TrackAttrs) => void;
21
+ }
22
+ }
23
+
24
+ declare module "vue" {
25
+ interface ComponentCustomProperties {
26
+ $initAuthSharedConfig: typeof initSharedConfig;
27
+ $gio: GioPublicApi;
28
+ $trackEvent: (eventName: string, attrs?: TrackAttrs) => void;
29
+ }
30
+ }
31
+
32
+ declare global {
33
+ interface Window {
34
+ __JCTRANS_GIO_CONFIG__?: Record<string, unknown>;
35
+ __GIO_CONFIG__?: Record<string, unknown>;
36
+ }
37
+ }
38
+
39
+ export {};
@@ -0,0 +1,3 @@
1
+ export { default } from './module.mjs'
2
+
3
+ export { type ModuleOptions, type TrackingInitOptions, type TrackingOptions, type TrackingPerformanceNetwork, type TrackingPerformanceOptions } from './module.mjs'
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@jctrans-materials/nuxt4",
3
+ "type": "module",
4
+ "version": "1.0.41-beta.10",
5
+ "description": "Nuxt 4 module for JCtrans UI components",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/module.d.mts",
9
+ "import": "./dist/module.mjs",
10
+ "require": "./dist/module.cjs"
11
+ }
12
+ },
13
+ "main": "./dist/module.cjs",
14
+ "module": "./dist/module.mjs",
15
+ "types": "./dist/module.d.mts",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "dependencies": {
20
+ "@nuxt/kit": "^3.0.0",
21
+ "defu": "6.1.2",
22
+ "vue": "^3.5.26",
23
+ "vue-router": "^4.6.4",
24
+ "@jctrans-materials/comps-vue3": "1.0.41-beta.10",
25
+ "@jctrans-materials/shared": "1.0.41-beta.10"
26
+ },
27
+ "peerDependencies": {
28
+ "gio-webjs-sdk": "^4.0.0",
29
+ "nuxt": ">=3.0.0",
30
+ "@jctrans-materials/comps-vue3": "1.0.41-beta.10",
31
+ "@jctrans-materials/shared": "1.0.41-beta.10"
32
+ },
33
+ "devDependencies": {
34
+ "@nuxt/module-builder": "latest",
35
+ "nuxt": "^3.12.1",
36
+ "unbuild": "^3.6.1"
37
+ },
38
+ "scripts": {
39
+ "build": "nuxt-module-build",
40
+ "dev": "nuxt dev",
41
+ "generate": "nuxt generate",
42
+ "preview": "nuxt preview"
43
+ }
44
+ }