@deppon/deppon-router 2.1.1

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/es/utils.js ADDED
@@ -0,0 +1,558 @@
1
+ import './_virtual/_rollup-plugin-inject-process-env.js';
2
+ import _typeof from '@babel/runtime/helpers/typeof';
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
+
7
+ var _excluded = ["appendIsUap"],
8
+ _excluded2 = ["uumsFunction", "closeCurrentTab"];
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ /**
12
+ * 创建路由工具函数
13
+ * @param {Object} router - Vue Router 实例
14
+ * @param {Object} [defaultViewTab] - 默认的 viewTab 配置(可选)
15
+ * @returns {Object} 工具函数对象,包含以下方法:
16
+ * - safePush: 安全的路由跳转(带错误处理)
17
+ * - safeReplace: 安全的路由替换(带错误处理)
18
+ * - pushByName: 根据路由名称跳转
19
+ * - pushByPath: 根据路由路径跳转
20
+ * - goBack: 返回上一页
21
+ * - hasRoute: 检查路由是否存在
22
+ * - getRouteConfig: 获取路由配置
23
+ * - depponPush: 智能路由跳转(在 iframe 环境中自动使用 viewTab,否则使用 router.push)
24
+ * - getQueryByRoute: 智能获取路由参数(在 iframe 环境中从父级获取,否则从当前路由 query 获取)
25
+ */
26
+ /**
27
+ * iframe 环境中的路由跳转工具函数(已迁移自 @deppon/deppon-utils)
28
+ */
29
+
30
+ /**
31
+ * 检查是否在 iframe 环境中且父级支持 viewTab
32
+ * @returns {boolean} 是否支持 viewTab
33
+ */
34
+ function isViewTabSupported() {
35
+ return typeof window !== 'undefined' && window.top && window.top !== window.self && typeof window.top.viewTab === 'function';
36
+ }
37
+
38
+ /**
39
+ * 从父级 iframe 获取参数
40
+ * @returns {Record<string, any>} 参数对象
41
+ */
42
+ function getParentParams() {
43
+ if (typeof window === 'undefined' || !window.top || window.top === window.self) {
44
+ return {};
45
+ }
46
+ try {
47
+ var top = window.top;
48
+ if (top.Ext && top.Ext.getCmp && typeof top.Ext.getCmp === 'function') {
49
+ var mainAreaPanel = top.Ext.getCmp('mainAreaPanel');
50
+ if (mainAreaPanel && mainAreaPanel.params) {
51
+ return mainAreaPanel.params || {};
52
+ }
53
+ }
54
+ } catch (error) {
55
+ // 跨域或其他错误,返回空对象
56
+ }
57
+ return {};
58
+ }
59
+
60
+ /**
61
+ * 在 URL 后追加参数
62
+ * @param {string} url - 原始 URL
63
+ * @param {string} param - 要追加的参数(格式:key=value)
64
+ * @returns {string} 追加参数后的 URL
65
+ */
66
+ function appendUrlParam(url, param) {
67
+ // 解析参数名
68
+ var _param$split = param.split('='),
69
+ _param$split2 = _slicedToArray(_param$split, 1),
70
+ key = _param$split2[0];
71
+
72
+ // 检查 URL 中是否已经存在该参数
73
+ // 使用正则表达式检查 query string 中是否已经包含该参数名
74
+ var paramPattern = new RegExp("[?&]".concat(key, "(=|&|$)"));
75
+ if (paramPattern.test(url)) {
76
+ // 如果参数已存在,直接返回原 URL
77
+ return url;
78
+ }
79
+ if (typeof window === 'undefined' || !window.top || window.top === window.self) {
80
+ // 降级处理:手动追加参数
81
+ var _separator = url.includes('?') ? '&' : '?';
82
+ return "".concat(url).concat(_separator).concat(param);
83
+ }
84
+ try {
85
+ var top = window.top;
86
+ if (top.Ext && top.Ext.urlAppend && typeof top.Ext.urlAppend === 'function') {
87
+ return top.Ext.urlAppend(url, param);
88
+ }
89
+ } catch (error) {
90
+ }
91
+
92
+ // 降级处理:手动追加参数
93
+ var separator = url.includes('?') ? '&' : '?';
94
+ return "".concat(url).concat(separator).concat(param);
95
+ }
96
+
97
+ /**
98
+ * 关闭当前标签页(内部函数)
99
+ * @param {string} url - 标签页 URL
100
+ * @param {string} type - 标签页类型(默认:'IFRAME')
101
+ */
102
+ function closeCurrentTabInternal(url) {
103
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'IFRAME';
104
+ if (typeof window === 'undefined' || !window.top || window.top === window.self) {
105
+ return;
106
+ }
107
+ try {
108
+ var top = window.top;
109
+ if (top.closeTab && typeof top.closeTab === 'function') {
110
+ top.closeTab(url, type);
111
+ }
112
+ } catch (error) {
113
+ }
114
+ }
115
+
116
+ /**
117
+ * 在 iframe 环境中打开新标签页(通过父级的 viewTab 方法)
118
+ * @param {string} title - 标签页标题
119
+ * @param {string} url - 要打开的 URL
120
+ * @param {string} [viewType='iframe'] - 视图类型,默认为 'iframe'
121
+ * @param {Record<string, any> | null} [params=null] - 参数对象
122
+ * @param {Object} [options={}] - 配置选项
123
+ * @param {boolean} [options.appendIsUap=false] - 是否在 URL 后追加 isUap=true 参数(默认 false,不再自动追加)
124
+ * @returns {boolean} 是否成功调用 viewTab,如果不在 iframe 环境中返回 false
125
+ */
126
+ function viewTab(title, url) {
127
+ var viewType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'iframe';
128
+ var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
129
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
130
+ if (!isViewTabSupported()) {
131
+ return false;
132
+ }
133
+ try {
134
+ var top = window.top;
135
+ var _options$appendIsUap = options.appendIsUap,
136
+ appendIsUap = _options$appendIsUap === void 0 ? false : _options$appendIsUap,
137
+ restOptions = _objectWithoutProperties(options, _excluded);
138
+
139
+ // 如果需要追加 isUap 参数(默认不再追加)
140
+ var finalUrl = url;
141
+ if (appendIsUap) {
142
+ finalUrl = appendUrlParam(url, 'isUap=true');
143
+ }
144
+
145
+ // 调用父级的 viewTab 方法
146
+ top.viewTab(title, finalUrl, viewType, params, restOptions);
147
+ return true;
148
+ } catch (error) {
149
+ return false;
150
+ }
151
+ }
152
+
153
+ /**
154
+ * 获取 viewTab 工具函数对象
155
+ * @returns {Object|null} viewTab 工具函数对象,如果不在 iframe 环境中返回 null
156
+ */
157
+ function getViewTabUtils() {
158
+ // 直接返回本地函数,不再依赖 @deppon/deppon-utils
159
+ return {
160
+ isViewTabSupported: isViewTabSupported,
161
+ getParentParams: getParentParams,
162
+ appendUrlParam: appendUrlParam,
163
+ closeCurrentTab: closeCurrentTabInternal,
164
+ viewTab: viewTab
165
+ };
166
+ }
167
+
168
+ /**
169
+ * 合并 viewTab 配置(默认配置 + 传入配置,传入配置优先)
170
+ * @param {Object} defaultConfig - 默认配置
171
+ * @param {Object} userConfig - 用户传入的配置
172
+ * @returns {Object} 合并后的配置
173
+ */
174
+ function mergeViewTabConfig(defaultConfig, userConfig) {
175
+ if (!defaultConfig) {
176
+ return userConfig || null;
177
+ }
178
+ if (!userConfig) {
179
+ return defaultConfig;
180
+ }
181
+ // 深度合并,userConfig 优先
182
+ return _objectSpread(_objectSpread(_objectSpread({}, defaultConfig), userConfig), {}, {
183
+ // uumsFunction 需要特殊处理(如果用户提供了,完全覆盖默认的)
184
+ uumsFunction: userConfig.uumsFunction || defaultConfig.uumsFunction
185
+ });
186
+ }
187
+ function createRouterUtils(router) {
188
+ var defaultViewTab = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
189
+ // 保存原始的 push 方法
190
+ var originalPush = router.push.bind(router);
191
+
192
+ /**
193
+ * 将路由位置转换为完整 URL
194
+ * @param {Object|String} location - 路由位置
195
+ * @returns {string} 完整 URL
196
+ */
197
+ function locationToUrl(location) {
198
+ if (typeof location === 'string') {
199
+ var _router$options$histo;
200
+ // 字符串路径
201
+ if (location.startsWith('http')) {
202
+ return location;
203
+ }
204
+ // 处理 hash 模式
205
+ var base = ((_router$options$histo = router.options.history) === null || _router$options$histo === void 0 ? void 0 : _router$options$histo.base) || '';
206
+ var isHash = base.includes('#') || typeof window !== 'undefined' && window.location.hash;
207
+ if (isHash && !location.startsWith('#')) {
208
+ return "".concat(window.location.origin, "/#").concat(location.startsWith('/') ? location : "/".concat(location));
209
+ }
210
+ return "".concat(window.location.origin).concat(location.startsWith('/') ? location : "/".concat(location));
211
+ }
212
+
213
+ // 使用 router.resolve 来正确解析路由(包括 params 和 query)
214
+ var resolved = router.resolve(location);
215
+ var url = resolved.href;
216
+
217
+ // 如果 href 是相对路径,添加 origin
218
+ if (!url.startsWith('http')) {
219
+ url = "".concat(window.location.origin).concat(url.startsWith('/') ? '' : '/').concat(url);
220
+ }
221
+ return url;
222
+ }
223
+ return {
224
+ /**
225
+ * 包装后的 push 方法,自动应用默认的 _viewTab 配置
226
+ * @param {Object|String} location - 路由位置
227
+ * @param {Function} onComplete - 成功回调
228
+ * @param {Function} onAbort - 失败回调
229
+ */
230
+ push: function push(location, onComplete, onAbort) {
231
+ // 直接调用 depponPush,它会自动处理默认配置
232
+ return this.depponPush(location, onComplete, onAbort);
233
+ },
234
+ /**
235
+ * 安全的路由跳转(带错误处理)
236
+ * @param {Object|String} location - 路由位置
237
+ * @param {Function} onComplete - 成功回调
238
+ * @param {Function} onAbort - 失败回调
239
+ */
240
+ safePush: function safePush(location, onComplete, onAbort) {
241
+ return originalPush(location)["catch"](function (err) {
242
+ // 忽略导航重复的错误
243
+ if (err.name !== 'NavigationDuplicated') {
244
+ if (onAbort) {
245
+ onAbort(err);
246
+ }
247
+ }
248
+ }).then(function () {
249
+ if (onComplete) {
250
+ onComplete();
251
+ }
252
+ });
253
+ },
254
+ /**
255
+ * 安全的路由替换(带错误处理)
256
+ * @param {Object|String} location - 路由位置
257
+ * @param {Function} onComplete - 成功回调
258
+ * @param {Function} onAbort - 失败回调
259
+ */
260
+ safeReplace: function safeReplace(location, onComplete, onAbort) {
261
+ return router.replace(location)["catch"](function (err) {
262
+ if (err.name !== 'NavigationDuplicated') {
263
+ if (onAbort) {
264
+ onAbort(err);
265
+ }
266
+ }
267
+ }).then(function () {
268
+ if (onComplete) {
269
+ onComplete();
270
+ }
271
+ });
272
+ },
273
+ /**
274
+ * 根据路由名称跳转
275
+ * @param {String} name - 路由名称
276
+ * @param {Object} params - 路由参数
277
+ * @param {Object} query - 查询参数
278
+ */
279
+ pushByName: function pushByName(name) {
280
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
281
+ var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
282
+ return this.safePush({
283
+ name: name,
284
+ params: params,
285
+ query: query
286
+ });
287
+ },
288
+ /**
289
+ * 根据路由路径跳转
290
+ * @param {String} path - 路由路径
291
+ * @param {Object} query - 查询参数
292
+ */
293
+ pushByPath: function pushByPath(path) {
294
+ var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
295
+ return this.safePush({
296
+ path: path,
297
+ query: query
298
+ });
299
+ },
300
+ /**
301
+ * 返回上一页
302
+ * @param {Number} delta - 返回的步数,默认为 1
303
+ */
304
+ goBack: function goBack() {
305
+ var delta = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
306
+ router.go(-delta);
307
+ },
308
+ /**
309
+ * 关闭当前标签页
310
+ * @param {string} [url] - 标签页 URL(默认使用当前页面的 location.href)
311
+ * @param {string} [type='IFRAME'] - 标签页类型(默认:'IFRAME')
312
+ */
313
+ closeCurrentTab: function closeCurrentTab(url) {
314
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'IFRAME';
315
+ var utils = getViewTabUtils();
316
+
317
+ // 判断是否应该使用 viewTab(与 depponPush 逻辑一致)
318
+ var shouldUseViewTab = utils && utils.isViewTabSupported && utils.isViewTabSupported();
319
+ if (shouldUseViewTab && utils) {
320
+ // 在 iframe 环境中使用 viewTab 关闭标签页
321
+ var tabUrl = url || (typeof window !== 'undefined' ? window.location.href : '');
322
+ return closeCurrentTabInternal(tabUrl, type);
323
+ } else {
324
+ // 降级处理:使用 router 常规的返回
325
+ router.go(-1);
326
+ }
327
+ },
328
+ /**
329
+ * 检查路由是否存在(包括动态添加的路由)
330
+ * @param {String} name - 路由名称
331
+ * @returns {Boolean}
332
+ */
333
+ hasRoute: function hasRoute(name) {
334
+ // 使用 getRoutes() 获取所有路由(包括动态添加的),而不仅仅是初始路由
335
+ return router.getRoutes().some(function (route) {
336
+ return route.name === name;
337
+ });
338
+ },
339
+ /**
340
+ * 获取路由配置(包括动态添加的路由)
341
+ * @param {String} name - 路由名称
342
+ * @returns {Object|null}
343
+ */
344
+ getRouteConfig: function getRouteConfig(name) {
345
+ // 使用 getRoutes() 获取所有路由(包括动态添加的),而不仅仅是初始路由
346
+ return router.getRoutes().find(function (route) {
347
+ return route.name === name;
348
+ }) || null;
349
+ },
350
+ /**
351
+ * 智能获取路由参数:在 iframe 环境中优先从父级获取,否则从当前路由 query 获取
352
+ * 与 depponPush 的参数获取逻辑保持一致
353
+ * @param {String} [key] - 参数键名,如果不提供则返回所有参数对象
354
+ * @returns {any} 参数值(如果提供了 key)或参数对象(如果未提供 key)
355
+ *
356
+ * @example
357
+ * // 获取所有参数
358
+ * const params = router.getQueryByRoute();
359
+ *
360
+ * // 获取指定参数
361
+ * const sourceType = router.getQueryByRoute('sourceType');
362
+ */
363
+ getQueryByRoute: function getQueryByRoute(key) {
364
+ var utils = getViewTabUtils();
365
+ var params = {};
366
+
367
+ // 如果在 iframe 环境中且支持 viewTab,优先从父级获取参数
368
+ if (utils && utils.isViewTabSupported && utils.isViewTabSupported()) {
369
+ // 优先从父级获取 params(与 depponPush 逻辑一致)
370
+ var parentParams = utils.getParentParams && utils.getParentParams() || {};
371
+ // 同时从当前路由 query 获取参数(合并两者,query 优先级更高)
372
+ var queryParams = router.currentRoute.value.query || {};
373
+ // 合并参数:父级 params 作为基础,query 参数覆盖同名参数
374
+ params = _objectSpread(_objectSpread({}, parentParams), queryParams);
375
+ } else {
376
+ // 否则从当前路由 query 获取
377
+ params = router.currentRoute.value.query || {};
378
+ }
379
+
380
+ // 如果提供了 key,返回对应的值;否则返回所有参数
381
+ return key ? params[key] || null : params;
382
+ },
383
+ /**
384
+ * 智能路由跳转:在 iframe 环境中自动使用 viewTab,否则使用 router.push
385
+ * 参数传递方式与 router.push 完全一致,在 iframe 环境中会自动适配 viewTab
386
+ * @param {Object|String} location - 路由位置(与 router.push 一致)
387
+ * - 如果是字符串:路径字符串,如 '/home' 或 '/home?id=1'
388
+ * - 如果是对象,可以包含以下属性:
389
+ * - path: 路径
390
+ * - name: 路由名称
391
+ * - params: 路由参数(在 iframe 环境中会传递给 viewTab 的 params)
392
+ * - query: 查询参数(会转换为 URL 的 query string)
393
+ * - _viewTab: viewTab 选项对象(可选,仅在 iframe 环境中生效)
394
+ * - title: 标签页标题(默认使用路由 meta.title 或 '新页面')
395
+ * - uumsFunction: UUMS 功能配置
396
+ * - functionCode: 功能代码
397
+ * - sourceSystem: 来源系统
398
+ * - closeCurrentTab: 是否关闭当前标签页(默认 false)
399
+ * @param {Function} [onComplete] - 成功回调(与 router.push 一致)
400
+ * @param {Function} [onAbort] - 失败回调(与 router.push 一致)
401
+ * @returns {Promise} 跳转 Promise
402
+ *
403
+ * @example
404
+ * // 基本用法(与 router.push 完全一致,在 iframe 环境中自动使用 viewTab)
405
+ * router.depponPush('/home');
406
+ * router.depponPush({ path: '/home', query: { id: 1 } });
407
+ * router.depponPush({ name: 'Home', params: { id: 1 } });
408
+ *
409
+ * // 在 iframe 环境中自定义 viewTab 选项
410
+ * router.depponPush({
411
+ * path: '/preferInfo',
412
+ * query: { sourceType: 'insert' },
413
+ * params: { custNumber: '701265308', preferId: '1312' },
414
+ * _viewTab: {
415
+ * title: 'CMC-产品折扣新增',
416
+ * uumsFunction: {
417
+ * functionCode: 'CMC_FUNCTION_00002',
418
+ * sourceSystem: 'CMC',
419
+ * },
420
+ * closeCurrentTab: true,
421
+ * },
422
+ * });
423
+ *
424
+ * // 替换原有代码示例:
425
+ * // 原代码:
426
+ * // if (top.viewTab) {
427
+ * // let params = { sourceType: 'insert' };
428
+ * // let url = location.origin + '/#/preferInfo?sourceType=insert';
429
+ * // let tabUrl = top.Ext.urlAppend(url, 'isUap=true');
430
+ * // top.closeTab(tabUrl, 'IFRAME');
431
+ * // top.viewTab('CMC-产品折扣新增', url, 'iframe', params, { ... });
432
+ * // } else {
433
+ * // this.$router.push({ path: '/preferInfo', query: { sourceType: 'insert' } });
434
+ * // }
435
+ * //
436
+ * // 新代码(自动适配):
437
+ * router.depponPush({
438
+ * path: '/preferInfo',
439
+ * query: { sourceType: 'insert' },
440
+ * params: { sourceType: 'insert' },
441
+ * _viewTab: {
442
+ * title: 'CMC-产品折扣新增',
443
+ * uumsFunction: {
444
+ * functionCode: 'CMC_FUNCTION_00002',
445
+ * sourceSystem: 'CMC',
446
+ * },
447
+ * closeCurrentTab: true,
448
+ * },
449
+ * });
450
+ */
451
+ depponPush: function depponPush(location, onComplete, onAbort) {
452
+ var utils = getViewTabUtils();
453
+
454
+ // 提取 viewTab 选项(如果存在),并合并默认配置
455
+ var viewTabOptions = null;
456
+ var cleanLocation = location;
457
+ // 记录用户是否明确提供了 title(在 _viewTab 中)
458
+ var userProvidedTitle = null;
459
+ if (location && _typeof(location) === 'object' && location._viewTab) {
460
+ // 检查用户是否明确提供了 title
461
+ userProvidedTitle = location._viewTab.title;
462
+ // 合并默认配置和用户配置(用户配置优先)
463
+ viewTabOptions = mergeViewTabConfig(defaultViewTab, location._viewTab);
464
+ // 创建清理后的 location 对象(移除 _viewTab)
465
+ cleanLocation = _objectSpread({}, location);
466
+ delete cleanLocation._viewTab;
467
+ } else if (defaultViewTab) {
468
+ // 如果用户没有提供 _viewTab,但有默认配置,使用默认配置
469
+ viewTabOptions = defaultViewTab;
470
+ }
471
+
472
+ // 如果支持 viewTab 且在 iframe 环境中,或者明确提供了 viewTabOptions(强制使用 viewTab)
473
+ var shouldUseViewTab = utils && utils.isViewTabSupported && utils.isViewTabSupported() || viewTabOptions !== null;
474
+ if (shouldUseViewTab && utils) {
475
+ try {
476
+ // 如果没有提供 viewTabOptions,使用默认值
477
+ var defaultOptions = viewTabOptions || {};
478
+ var uumsFunction = defaultOptions.uumsFunction,
479
+ _defaultOptions$close = defaultOptions.closeCurrentTab,
480
+ closeCurrentTab = _defaultOptions$close === void 0 ? false : _defaultOptions$close,
481
+ restOptions = _objectWithoutProperties(defaultOptions, _excluded2);
482
+
483
+ // 构建完整 URL(使用清理后的 location)
484
+ var url = locationToUrl(cleanLocation);
485
+
486
+ // 获取标题的优先级:用户明确提供的 title > 目标路由的 meta.title > defaultViewTab.title > '新页面'
487
+ var finalTitle = null;
488
+
489
+ // 1. 如果用户明确提供了 title,使用用户的 title
490
+ if (userProvidedTitle !== null && userProvidedTitle !== undefined) {
491
+ finalTitle = userProvidedTitle;
492
+ } else {
493
+ // 2. 尝试从目标路由的 meta.title 中获取
494
+ try {
495
+ // 解析目标路由,获取其 meta.title
496
+ var resolved = router.resolve(cleanLocation);
497
+ if (resolved.matched && resolved.matched.length > 0) {
498
+ var _targetRoute$meta;
499
+ // 获取最后一个匹配的路由(最具体的路由)
500
+ var targetRoute = resolved.matched[resolved.matched.length - 1];
501
+ finalTitle = (_targetRoute$meta = targetRoute.meta) === null || _targetRoute$meta === void 0 ? void 0 : _targetRoute$meta.title;
502
+ }
503
+ } catch (error) {
504
+ }
505
+
506
+ // 3. 如果目标路由没有 title,使用默认配置的 title
507
+ if (!finalTitle && defaultViewTab && defaultViewTab.title) {
508
+ finalTitle = defaultViewTab.title;
509
+ }
510
+
511
+ // 4. 最后使用默认值
512
+ if (!finalTitle) {
513
+ finalTitle = '新页面';
514
+ }
515
+ }
516
+
517
+ // 获取参数(优先使用 location.params,其次从父级获取)
518
+ var params = null;
519
+ if (cleanLocation && _typeof(cleanLocation) === 'object' && cleanLocation.params) {
520
+ params = cleanLocation.params;
521
+ } else if (utils.getParentParams) {
522
+ params = utils.getParentParams();
523
+ }
524
+
525
+ // 使用 viewTab 跳转(即使 isViewTabSupported 返回 false,如果提供了 viewTabOptions 也尝试调用)
526
+ if (utils.viewTab) {
527
+ // 如果需要关闭当前标签页,在调用 viewTab 之前先关闭
528
+ // 使用当前页面的实际 URL(location.href),这样可以正确匹配包含动态参数的 URL
529
+ if (closeCurrentTab) {
530
+ var currentUrl = typeof window !== 'undefined' ? window.location.href : '';
531
+ if (currentUrl && utils.closeCurrentTab) {
532
+ utils.closeCurrentTab(currentUrl, 'IFRAME');
533
+ }
534
+ }
535
+
536
+ // 不再自动追加 isUap 参数,默认 appendIsUap 为 false
537
+ var success = utils.viewTab(finalTitle, url, 'iframe', params, _objectSpread({
538
+ uumsFunction: uumsFunction,
539
+ appendIsUap: false
540
+ }, restOptions));
541
+ if (success) {
542
+ if (onComplete) {
543
+ onComplete();
544
+ }
545
+ return Promise.resolve();
546
+ }
547
+ }
548
+ } catch (error) {
549
+ }
550
+ }
551
+
552
+ // 降级处理:使用普通 push(使用清理后的 location)
553
+ return this.safePush(cleanLocation, onComplete, onAbort);
554
+ }
555
+ };
556
+ }
557
+
558
+ export { createRouterUtils };
package/es/vue.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ declare namespace _default {
2
+ export { install };
3
+ }
4
+ export default _default;
5
+ /**
6
+ * Vue 插件安装函数
7
+ * @param {Object} app - Vue 应用实例
8
+ * @param {Object|Array} options - 配置选项或路由配置数组
9
+ * @param {Object} options.router - 已创建的 router 实例(如果提供,将直接使用)
10
+ * @param {Array} options.routes - 路由配置数组
11
+ * @param {Object} options.routerOptions - Vue Router 原始配置选项
12
+ * @param {Object} options.guards - 路由守卫配置
13
+ * @param {Object} options.log - 日志实例(可选,用于路由追踪)
14
+ * @param {Function} options.onRouteChange - 路由变化回调(可选)
15
+ */
16
+ declare function install(app: Object, options?: Object | any[]): void;
package/es/vue.js ADDED
@@ -0,0 +1,42 @@
1
+ import './_virtual/_rollup-plugin-inject-process-env.js';
2
+ import { createDepponRouter } from './index.js';
3
+
4
+ /**
5
+ * Vue 插件安装函数
6
+ * @param {Object} app - Vue 应用实例
7
+ * @param {Object|Array} options - 配置选项或路由配置数组
8
+ * @param {Object} options.router - 已创建的 router 实例(如果提供,将直接使用)
9
+ * @param {Array} options.routes - 路由配置数组
10
+ * @param {Object} options.routerOptions - Vue Router 原始配置选项
11
+ * @param {Object} options.guards - 路由守卫配置
12
+ * @param {Object} options.log - 日志实例(可选,用于路由追踪)
13
+ * @param {Function} options.onRouteChange - 路由变化回调(可选)
14
+ */
15
+ function install(app) {
16
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
+ var router;
18
+
19
+ // 如果传入的是 router 实例,直接使用
20
+ if (options && options.router) {
21
+ router = options.router;
22
+ } else {
23
+ // 否则创建新的路由实例
24
+ router = createDepponRouter(options);
25
+ }
26
+
27
+ // 安装 Vue Router
28
+ app.use(router);
29
+
30
+ // 注册全局属性(可选,用于 Options API)
31
+ app.config.globalProperties.$router = router;
32
+ // 注意:Vue Router 4 已在全局原型上定义只读的 $route,勿手动覆盖
33
+ // app.config.globalProperties.$route = router.currentRoute;
34
+
35
+ // 提供实例,供 Composition API 使用
36
+ app.provide('depponRouter', router);
37
+ }
38
+ var vue = {
39
+ install: install
40
+ };
41
+
42
+ export { vue as default };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@deppon/deppon-router",
3
+ "version": "2.1.1",
4
+ "description": "德邦前端 Vue Router 4 封装包",
5
+ "license": "MIT",
6
+ "homepage": "",
7
+ "keywords": [
8
+ "router",
9
+ "vue-router",
10
+ "vue-router4",
11
+ "vue",
12
+ "vue3",
13
+ "vue-plugin"
14
+ ],
15
+ "author": {
16
+ "name": "",
17
+ "email": ""
18
+ },
19
+ "main": "es/index.js",
20
+ "module": "es/index.js",
21
+ "typings": "es/index.d.ts",
22
+ "sideEffects": false,
23
+ "scripts": {
24
+ "build": "ts-node build.ts",
25
+ "publish:auto": "npm publish"
26
+ },
27
+ "publishConfig": {
28
+ "registry": "https://devrepo.devcloud.cn-east-3.huaweicloud.com/artgalaxy/api/npm/cn-east-3_8a2e1f0ee52d4adb9a0a6998d78d0dda_npm_1/"
29
+ },
30
+ "files": [
31
+ "es"
32
+ ],
33
+ "repository": {
34
+ "type": "git",
35
+ "url": ""
36
+ },
37
+ "dependencies": {
38
+ "@babel/runtime": "^7.17.7",
39
+ "vue-router": "^4.0.0"
40
+ },
41
+ "peerDependencies": {
42
+ "vue": "^3.0.0",
43
+ "vue-router": "^4.0.0"
44
+ },
45
+ "gitHead": "1f329a64567c2e22df7860b0918ebe3427718945"
46
+ }