iframe-tab-sdk 1.0.1 → 1.0.2
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/index.js +13 -29
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -64,33 +64,25 @@ function navigateTo(urlPath, query = {}) {
|
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* 新开或跳转 tab 标签页
|
|
67
|
-
* @param {String} urlPath 页面地址
|
|
68
67
|
* @param {Object} params 相关参数
|
|
68
|
+
* @param {String} params[urlPath] 页面地址
|
|
69
69
|
* @param {String} params[name] 页面名称
|
|
70
70
|
* @param {String} params[title] 页面标题
|
|
71
71
|
* @param {Object} params[query] query 参数
|
|
72
72
|
* @param {Boolean} params[refreshClearQuery] 是否清空路由参数
|
|
73
73
|
*
|
|
74
74
|
*/
|
|
75
|
-
export function openTab(
|
|
76
|
-
const { name, title, query = {} } = params;
|
|
77
|
-
|
|
75
|
+
export function openTab(params) {
|
|
78
76
|
if (window.isIframeRun) {
|
|
79
77
|
window.parent.postMessage(
|
|
80
78
|
{
|
|
81
79
|
type: "openTab",
|
|
82
|
-
params
|
|
83
|
-
...params,
|
|
84
|
-
urlPath, // 页面地址
|
|
85
|
-
name: name ?? title, // 页面名称
|
|
86
|
-
title: title ?? name, // 页面标题
|
|
87
|
-
// 目标页面 tab 已存在时,query 参数变更会自动刷新目标页面
|
|
88
|
-
query,
|
|
89
|
-
},
|
|
80
|
+
params
|
|
90
81
|
},
|
|
91
82
|
origin
|
|
92
83
|
);
|
|
93
84
|
} else {
|
|
85
|
+
const { urlPath, query = {} } = params;
|
|
94
86
|
// 非iframe环境,执行路由跳转
|
|
95
87
|
navigateTo(urlPath, query);
|
|
96
88
|
}
|
|
@@ -98,22 +90,24 @@ export function openTab(urlPath, params) {
|
|
|
98
90
|
|
|
99
91
|
/**
|
|
100
92
|
* 刷新指定 tab 标签页
|
|
101
|
-
* @param {String} urlPath 指定 tab 标签页 URL
|
|
102
93
|
* @param {Object} params 相关参数
|
|
94
|
+
* @param {String} params[urlPath] 指定 tab 标签页 URL
|
|
103
95
|
* @param {String} params[name] 页面名称
|
|
104
96
|
* @param {String} params[title] 页面标题
|
|
105
97
|
* @param {Object} params[query] query 参数
|
|
106
98
|
*/
|
|
107
|
-
export function refreshTab(
|
|
99
|
+
export function refreshTab(params) {
|
|
100
|
+
const urlPath = params.urlPath;
|
|
108
101
|
if (window.isIframeRun) {
|
|
109
102
|
if (params) {
|
|
110
|
-
return openTab(
|
|
103
|
+
return openTab(params);
|
|
111
104
|
}
|
|
105
|
+
|
|
112
106
|
window.parent.postMessage({ type: "refreshTab", params: urlPath }, origin);
|
|
113
107
|
} else {
|
|
114
108
|
// 非iframe环境下,重新导航到指定路径
|
|
115
109
|
if (params) {
|
|
116
|
-
return openTab(
|
|
110
|
+
return openTab(params);
|
|
117
111
|
}
|
|
118
112
|
navigateTo(urlPath, {});
|
|
119
113
|
}
|
|
@@ -163,27 +157,17 @@ export function reload() {
|
|
|
163
157
|
/**
|
|
164
158
|
* 关闭某个tab打开新的tab(常用于关闭自身tab并打开新tab)
|
|
165
159
|
*/
|
|
166
|
-
export function closeAndOpenTab(
|
|
167
|
-
const { name, title, query = {}, closeTabName } = params;
|
|
168
|
-
|
|
160
|
+
export function closeAndOpenTab(params) {
|
|
169
161
|
if (window.isIframeRun) {
|
|
170
162
|
window.parent.postMessage(
|
|
171
163
|
{
|
|
172
164
|
type: "closeAndOpenTab",
|
|
173
|
-
params
|
|
174
|
-
closeTabName,
|
|
175
|
-
openRoute: {
|
|
176
|
-
urlPath, // 页面地址
|
|
177
|
-
name: name ?? title, // 页面名称
|
|
178
|
-
title: title ?? name, // 页面标题
|
|
179
|
-
// 目标页面 tab 已存在时,query 参数变更会自动刷新目标页面
|
|
180
|
-
query,
|
|
181
|
-
},
|
|
182
|
-
},
|
|
165
|
+
params
|
|
183
166
|
},
|
|
184
167
|
origin
|
|
185
168
|
);
|
|
186
169
|
} else {
|
|
170
|
+
const {urlPath,query} = params;
|
|
187
171
|
// 非iframe环境,直接跳转到新页面
|
|
188
172
|
navigateTo(urlPath, query);
|
|
189
173
|
}
|