@polyv/utils 2.13.0-beta.1 → 2.13.0-beta.3
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/cjs/external-link.d.ts +179 -0
- package/cjs/external-link.js +1 -0
- package/es/external-link.d.ts +179 -0
- package/es/external-link.js +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本模块提供链接处理相关方法。
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 保利威 WebView 桥接器接口
|
|
7
|
+
*/
|
|
8
|
+
export interface WebViewBridge {
|
|
9
|
+
/**
|
|
10
|
+
* 向 WebView 发送数据
|
|
11
|
+
* @param event 事件
|
|
12
|
+
* @param data 数据对象
|
|
13
|
+
*/
|
|
14
|
+
sendData: (event: string, data: Record<string, unknown>) => void;
|
|
15
|
+
}
|
|
16
|
+
/** 是否安卓 */
|
|
17
|
+
export declare const isAndroid: boolean;
|
|
18
|
+
/** 是否 iOS */
|
|
19
|
+
export declare const isIOS: boolean;
|
|
20
|
+
/** 是否微信(非企业微信) */
|
|
21
|
+
export declare const isWeixin: boolean;
|
|
22
|
+
/** 是否企业微信 */
|
|
23
|
+
export declare const isWorkWeixin: boolean;
|
|
24
|
+
/** 判断 PC 端微信小程序环境 */
|
|
25
|
+
export declare const isPcMiniProgram: boolean;
|
|
26
|
+
/** 是否移动端 */
|
|
27
|
+
export declare const isMobile: boolean;
|
|
28
|
+
type ToPointMallFunc = (params: string) => unknown;
|
|
29
|
+
declare global {
|
|
30
|
+
interface Window {
|
|
31
|
+
AndroidNative?: {
|
|
32
|
+
toPointMall?: ToPointMallFunc;
|
|
33
|
+
};
|
|
34
|
+
webkit?: {
|
|
35
|
+
messageHandlers?: {
|
|
36
|
+
gotoPointsMall?: {
|
|
37
|
+
postMessage?: ToPointMallFunc;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 链接类型
|
|
45
|
+
*/
|
|
46
|
+
export declare enum LinkType {
|
|
47
|
+
/**
|
|
48
|
+
* 通用链接
|
|
49
|
+
*/
|
|
50
|
+
Normal = 10,
|
|
51
|
+
/**
|
|
52
|
+
* 多平台链接
|
|
53
|
+
*/
|
|
54
|
+
MultiPlatform = 11,
|
|
55
|
+
/**
|
|
56
|
+
* 原生方法跳转
|
|
57
|
+
*/
|
|
58
|
+
Native = 12
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 外链跳转方式
|
|
62
|
+
*/
|
|
63
|
+
export declare enum LinkJumpWay {
|
|
64
|
+
/**
|
|
65
|
+
* iframe 弹框形式打开
|
|
66
|
+
*/
|
|
67
|
+
PopUp = "POP_UP",
|
|
68
|
+
/**
|
|
69
|
+
* 新窗口打开
|
|
70
|
+
*/
|
|
71
|
+
NewWindow = "NEW_WINDOW",
|
|
72
|
+
/**
|
|
73
|
+
* 当前窗口打开
|
|
74
|
+
*/
|
|
75
|
+
CurrentWindow = "CURRENT_WINDOW"
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 链接数据接口
|
|
79
|
+
*/
|
|
80
|
+
export interface LinkData {
|
|
81
|
+
/**
|
|
82
|
+
* 链接类型
|
|
83
|
+
*/
|
|
84
|
+
linkType: LinkType;
|
|
85
|
+
/**
|
|
86
|
+
* 跳转方式
|
|
87
|
+
*/
|
|
88
|
+
jumpWay: LinkJumpWay;
|
|
89
|
+
/**
|
|
90
|
+
* 通用平台跳转链接
|
|
91
|
+
*/
|
|
92
|
+
link: string;
|
|
93
|
+
/**
|
|
94
|
+
* PC 端跳转链接
|
|
95
|
+
*/
|
|
96
|
+
pcLink: string;
|
|
97
|
+
/**
|
|
98
|
+
* 移动端跳转链接
|
|
99
|
+
*/
|
|
100
|
+
mobileLink: string;
|
|
101
|
+
/**
|
|
102
|
+
* App 链接
|
|
103
|
+
*/
|
|
104
|
+
mobileAppLink: string;
|
|
105
|
+
/**
|
|
106
|
+
* 安卓端 app 跳转链接
|
|
107
|
+
*/
|
|
108
|
+
androidLink: string;
|
|
109
|
+
/**
|
|
110
|
+
* iOS app 跳转链接
|
|
111
|
+
*/
|
|
112
|
+
iosLink: string;
|
|
113
|
+
/**
|
|
114
|
+
* 其他链接
|
|
115
|
+
*/
|
|
116
|
+
otherLink: string;
|
|
117
|
+
/**
|
|
118
|
+
* 微信小程序原始 id
|
|
119
|
+
*/
|
|
120
|
+
wxMiniprogramOriginalId: string;
|
|
121
|
+
/**
|
|
122
|
+
* 微信小程序应用 id
|
|
123
|
+
*/
|
|
124
|
+
wxMiniprogramAppId: string;
|
|
125
|
+
/**
|
|
126
|
+
* 微信小程序内页面路径及参数
|
|
127
|
+
*/
|
|
128
|
+
wxMiniprogramLink: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 获取链接参数
|
|
132
|
+
*/
|
|
133
|
+
export type GetLinkParams = (url: string) => Record<string, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* 跳转链接配置项
|
|
136
|
+
*/
|
|
137
|
+
export interface NavigateToLinkOptions {
|
|
138
|
+
/** 链接数据 */
|
|
139
|
+
linkData: LinkData;
|
|
140
|
+
/**
|
|
141
|
+
* 获取链接参数
|
|
142
|
+
*/
|
|
143
|
+
getLinkParams?: GetLinkParams;
|
|
144
|
+
/** 通用链接打开处理器 */
|
|
145
|
+
openLink: (url: string, jumpWay: LinkJumpWay) => void;
|
|
146
|
+
/** 是否处于保利威 webview 中 */
|
|
147
|
+
isPlvWebview?: () => boolean;
|
|
148
|
+
/** 获取保利威 webview 桥接器 */
|
|
149
|
+
getPlvWebviewBridge?: () => Promise<WebViewBridge | undefined>;
|
|
150
|
+
/** 获取保利威 webview 小窗尺寸 */
|
|
151
|
+
getPlvWebviewSmallWindowSize?: () => {
|
|
152
|
+
width: number;
|
|
153
|
+
height: number;
|
|
154
|
+
};
|
|
155
|
+
isWxMiniProgramEnv?: () => Promise<boolean | undefined>;
|
|
156
|
+
/** 跳转微信小程序 */
|
|
157
|
+
toWxMiniProgram?: (link: string) => void;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 格式化链接地址
|
|
161
|
+
* @param url 需要格式化的链接地址
|
|
162
|
+
* @param getLinkParams 获取额外参数的函数,可选
|
|
163
|
+
* @returns 格式化后的链接地址
|
|
164
|
+
*/
|
|
165
|
+
export declare function formatLink(url: string, getLinkParams?: (url: string) => Record<string, unknown>): string;
|
|
166
|
+
/**
|
|
167
|
+
* 根据链接类型和当前环境进行跳转处理
|
|
168
|
+
* @param options 跳转配置项
|
|
169
|
+
* @param options.linkData 链接数据,包含各种平台的链接和跳转方式
|
|
170
|
+
* @param options.getLinkParams 获取链接参数的函数
|
|
171
|
+
* @param options.openLink 通用链接打开处理器
|
|
172
|
+
* @param options.isPlvWebview 判断是否处于保利威 webview 中的函数
|
|
173
|
+
* @param options.getPlvWebviewSmallWindowSize 获取保利威 webview 小窗尺寸的函数
|
|
174
|
+
* @param options.getPlvWebviewBridge 获取保利威 webview 桥接器的函数
|
|
175
|
+
* @param options.isWxMiniProgramEnv 判断是否处于微信小程序环境的函数
|
|
176
|
+
* @param options.toWxMiniProgram 跳转微信小程序的函数
|
|
177
|
+
*/
|
|
178
|
+
export declare function navigateToLink(options: NavigateToLinkOptions): void;
|
|
179
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(i,n,e,t){return new(e||(e=Promise))((function(r,o){function a(i){try{l(t.next(i))}catch(i){o(i)}}function s(i){try{l(t.throw(i))}catch(i){o(i)}}function l(i){var n;i.done?r(i.value):(n=i.value,n instanceof e?n:new e((function(i){i(n)}))).then(a,s)}l((t=t.apply(i,n||[])).next())}))},__generator=this&&this.__generator||function(i,n){var e,t,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(e)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(e=1,t&&(r=2&s[0]?t.return:s[0]?t.throw||((r=t.return)&&r.call(t),0):t.next)&&!(r=r.call(t,s[1])).done)return r;switch(t=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,t=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=n.call(i,a)}catch(i){s=[6,i],t=0}finally{e=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LinkJumpWay=exports.LinkType=exports.isMobile=exports.isPcMiniProgram=exports.isWorkWeixin=exports.isWeixin=exports.isIOS=exports.isAndroid=void 0,exports.formatLink=formatLink,exports.navigateToLink=navigateToLink;var LinkType,LinkJumpWay,ua_info_1=require("@just4/ua-info"),querystring_1=require("@just4/querystring"),ua=navigator.userAgent.toLowerCase(),uaInfo=(0,ua_info_1.getCurrentUAInfo)();function getNativeToPointMallFn(){var i,n,e,t;return exports.isAndroid?null===(i=window.AndroidNative)||void 0===i?void 0:i.toPointMall:exports.isIOS?null===(t=null===(e=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers)||void 0===e?void 0:e.gotoPointsMall)||void 0===t?void 0:t.postMessage:void 0}function toNativeLink(i){var n=i.androidLink,e=i.iosLink,t=i.otherLink,r=getNativeToPointMallFn();if(r){var o=exports.isAndroid?n:e,a=encodeURIComponent(location.href);return o=(0,querystring_1.concat)(o,{plt_back_uri:a}),void r(JSON.stringify({url:o}))}window.open(t,"_blank","noopener=yes")}function toPlvWebviewBridge(i){return __awaiter(this,void 0,void 0,(function(){var n,e,t,r;return __generator(this,(function(o){switch(o.label){case 0:return n=i.getPlvWebviewSmallWindowSize,e=i.getPlvWebviewBridge,t=(null==n?void 0:n())||{width:90,height:160},[4,null==e?void 0:e()];case 1:return(r=o.sent())?(r.sendData("clickProduct",{width:t.width,height:t.height,newPage:!0,link:i.link,data:i.data}),[2]):[2]}}))}))}function toMultiPlatformLink(i){return __awaiter(this,void 0,void 0,(function(){var n,e,t,r,o,a,s,l,u;return __generator(this,(function(p){switch(p.label){case 0:n=i.linkData,e=i.isWxMiniProgramEnv,t=i.toWxMiniProgram,r=i.openLink,o=i.getLinkParams,a=n.wxMiniprogramLink,s=n.mobileLink,l=n.pcLink,u=!1,p.label=1;case 1:return p.trys.push([1,3,,4]),[4,null==e?void 0:e()];case 2:return u=p.sent()||!1,[3,4];case 3:return p.sent(),u=!1,[3,4];case 4:return u&&a&&t?(t(formatLink(a,o)),[2]):exports.isMobile?(r(formatLink(s,o),LinkJumpWay.NewWindow),[2]):(exports.isMobile||r(formatLink(l,o),LinkJumpWay.NewWindow),[2])}}))}))}function formatLink(i,n){var e={};if(n){var t=n(i);e=Object.assign({},e,t)}return(0,querystring_1.concat)(i,e)}function navigateToLink(i){var n=i.linkData,e=i.openLink,t=i.isPlvWebview,r=i.getPlvWebviewSmallWindowSize,o=i.getPlvWebviewBridge,a=i.isWxMiniProgramEnv,s=i.toWxMiniProgram,l=i.getLinkParams,u=n.linkType,p=(null==t?void 0:t())||!1;if(u!==LinkType.Native){if(p){var k="",c=n.link,f=n.mobileLink,v=n.mobileAppLink,d=n.wxMiniprogramOriginalId,m=n.wxMiniprogramLink;switch(u){case LinkType.Normal:k=c;break;case LinkType.MultiPlatform:k=v||f}var L=null;return u!==LinkType.Normal&&(L={mobileLink:formatLink(f,l),wxMiniprogramOriginalId:d,wxMiniprogramLink:formatLink(m,l),mobileAppLink:formatLink(v,l)}),void toPlvWebviewBridge({link:formatLink(k,l),data:L,getPlvWebviewSmallWindowSize:r,getPlvWebviewBridge:o})}if(u!==LinkType.Normal)u===LinkType.MultiPlatform&&toMultiPlatformLink({linkData:n,getLinkParams:l,isWxMiniProgramEnv:a,toWxMiniProgram:s,openLink:e});else{c=n.link;var g=n.jumpWay;e(formatLink(c,l),g)}}else toNativeLink({androidLink:formatLink(n.androidLink,l),iosLink:formatLink(n.iosLink,l),otherLink:formatLink(n.otherLink,l)})}exports.isAndroid=uaInfo.os.isAndroid,exports.isIOS=uaInfo.os.isIOS,exports.isWeixin=uaInfo.client.isWx,exports.isWorkWeixin=uaInfo.client.isWxWork,exports.isPcMiniProgram=(exports.isWeixin||exports.isWorkWeixin)&&/miniprogramenv/.test(ua),exports.isMobile=uaInfo.isPortable||exports.isPcMiniProgram,function(i){i[i.Normal=10]="Normal",i[i.MultiPlatform=11]="MultiPlatform",i[i.Native=12]="Native"}(LinkType||(exports.LinkType=LinkType={})),function(i){i.PopUp="POP_UP",i.NewWindow="NEW_WINDOW",i.CurrentWindow="CURRENT_WINDOW"}(LinkJumpWay||(exports.LinkJumpWay=LinkJumpWay={}));
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本模块提供链接处理相关方法。
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 保利威 WebView 桥接器接口
|
|
7
|
+
*/
|
|
8
|
+
export interface WebViewBridge {
|
|
9
|
+
/**
|
|
10
|
+
* 向 WebView 发送数据
|
|
11
|
+
* @param event 事件
|
|
12
|
+
* @param data 数据对象
|
|
13
|
+
*/
|
|
14
|
+
sendData: (event: string, data: Record<string, unknown>) => void;
|
|
15
|
+
}
|
|
16
|
+
/** 是否安卓 */
|
|
17
|
+
export declare const isAndroid: boolean;
|
|
18
|
+
/** 是否 iOS */
|
|
19
|
+
export declare const isIOS: boolean;
|
|
20
|
+
/** 是否微信(非企业微信) */
|
|
21
|
+
export declare const isWeixin: boolean;
|
|
22
|
+
/** 是否企业微信 */
|
|
23
|
+
export declare const isWorkWeixin: boolean;
|
|
24
|
+
/** 判断 PC 端微信小程序环境 */
|
|
25
|
+
export declare const isPcMiniProgram: boolean;
|
|
26
|
+
/** 是否移动端 */
|
|
27
|
+
export declare const isMobile: boolean;
|
|
28
|
+
type ToPointMallFunc = (params: string) => unknown;
|
|
29
|
+
declare global {
|
|
30
|
+
interface Window {
|
|
31
|
+
AndroidNative?: {
|
|
32
|
+
toPointMall?: ToPointMallFunc;
|
|
33
|
+
};
|
|
34
|
+
webkit?: {
|
|
35
|
+
messageHandlers?: {
|
|
36
|
+
gotoPointsMall?: {
|
|
37
|
+
postMessage?: ToPointMallFunc;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 链接类型
|
|
45
|
+
*/
|
|
46
|
+
export declare enum LinkType {
|
|
47
|
+
/**
|
|
48
|
+
* 通用链接
|
|
49
|
+
*/
|
|
50
|
+
Normal = 10,
|
|
51
|
+
/**
|
|
52
|
+
* 多平台链接
|
|
53
|
+
*/
|
|
54
|
+
MultiPlatform = 11,
|
|
55
|
+
/**
|
|
56
|
+
* 原生方法跳转
|
|
57
|
+
*/
|
|
58
|
+
Native = 12
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 外链跳转方式
|
|
62
|
+
*/
|
|
63
|
+
export declare enum LinkJumpWay {
|
|
64
|
+
/**
|
|
65
|
+
* iframe 弹框形式打开
|
|
66
|
+
*/
|
|
67
|
+
PopUp = "POP_UP",
|
|
68
|
+
/**
|
|
69
|
+
* 新窗口打开
|
|
70
|
+
*/
|
|
71
|
+
NewWindow = "NEW_WINDOW",
|
|
72
|
+
/**
|
|
73
|
+
* 当前窗口打开
|
|
74
|
+
*/
|
|
75
|
+
CurrentWindow = "CURRENT_WINDOW"
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 链接数据接口
|
|
79
|
+
*/
|
|
80
|
+
export interface LinkData {
|
|
81
|
+
/**
|
|
82
|
+
* 链接类型
|
|
83
|
+
*/
|
|
84
|
+
linkType: LinkType;
|
|
85
|
+
/**
|
|
86
|
+
* 跳转方式
|
|
87
|
+
*/
|
|
88
|
+
jumpWay: LinkJumpWay;
|
|
89
|
+
/**
|
|
90
|
+
* 通用平台跳转链接
|
|
91
|
+
*/
|
|
92
|
+
link: string;
|
|
93
|
+
/**
|
|
94
|
+
* PC 端跳转链接
|
|
95
|
+
*/
|
|
96
|
+
pcLink: string;
|
|
97
|
+
/**
|
|
98
|
+
* 移动端跳转链接
|
|
99
|
+
*/
|
|
100
|
+
mobileLink: string;
|
|
101
|
+
/**
|
|
102
|
+
* App 链接
|
|
103
|
+
*/
|
|
104
|
+
mobileAppLink: string;
|
|
105
|
+
/**
|
|
106
|
+
* 安卓端 app 跳转链接
|
|
107
|
+
*/
|
|
108
|
+
androidLink: string;
|
|
109
|
+
/**
|
|
110
|
+
* iOS app 跳转链接
|
|
111
|
+
*/
|
|
112
|
+
iosLink: string;
|
|
113
|
+
/**
|
|
114
|
+
* 其他链接
|
|
115
|
+
*/
|
|
116
|
+
otherLink: string;
|
|
117
|
+
/**
|
|
118
|
+
* 微信小程序原始 id
|
|
119
|
+
*/
|
|
120
|
+
wxMiniprogramOriginalId: string;
|
|
121
|
+
/**
|
|
122
|
+
* 微信小程序应用 id
|
|
123
|
+
*/
|
|
124
|
+
wxMiniprogramAppId: string;
|
|
125
|
+
/**
|
|
126
|
+
* 微信小程序内页面路径及参数
|
|
127
|
+
*/
|
|
128
|
+
wxMiniprogramLink: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 获取链接参数
|
|
132
|
+
*/
|
|
133
|
+
export type GetLinkParams = (url: string) => Record<string, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* 跳转链接配置项
|
|
136
|
+
*/
|
|
137
|
+
export interface NavigateToLinkOptions {
|
|
138
|
+
/** 链接数据 */
|
|
139
|
+
linkData: LinkData;
|
|
140
|
+
/**
|
|
141
|
+
* 获取链接参数
|
|
142
|
+
*/
|
|
143
|
+
getLinkParams?: GetLinkParams;
|
|
144
|
+
/** 通用链接打开处理器 */
|
|
145
|
+
openLink: (url: string, jumpWay: LinkJumpWay) => void;
|
|
146
|
+
/** 是否处于保利威 webview 中 */
|
|
147
|
+
isPlvWebview?: () => boolean;
|
|
148
|
+
/** 获取保利威 webview 桥接器 */
|
|
149
|
+
getPlvWebviewBridge?: () => Promise<WebViewBridge | undefined>;
|
|
150
|
+
/** 获取保利威 webview 小窗尺寸 */
|
|
151
|
+
getPlvWebviewSmallWindowSize?: () => {
|
|
152
|
+
width: number;
|
|
153
|
+
height: number;
|
|
154
|
+
};
|
|
155
|
+
isWxMiniProgramEnv?: () => Promise<boolean | undefined>;
|
|
156
|
+
/** 跳转微信小程序 */
|
|
157
|
+
toWxMiniProgram?: (link: string) => void;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 格式化链接地址
|
|
161
|
+
* @param url 需要格式化的链接地址
|
|
162
|
+
* @param getLinkParams 获取额外参数的函数,可选
|
|
163
|
+
* @returns 格式化后的链接地址
|
|
164
|
+
*/
|
|
165
|
+
export declare function formatLink(url: string, getLinkParams?: (url: string) => Record<string, unknown>): string;
|
|
166
|
+
/**
|
|
167
|
+
* 根据链接类型和当前环境进行跳转处理
|
|
168
|
+
* @param options 跳转配置项
|
|
169
|
+
* @param options.linkData 链接数据,包含各种平台的链接和跳转方式
|
|
170
|
+
* @param options.getLinkParams 获取链接参数的函数
|
|
171
|
+
* @param options.openLink 通用链接打开处理器
|
|
172
|
+
* @param options.isPlvWebview 判断是否处于保利威 webview 中的函数
|
|
173
|
+
* @param options.getPlvWebviewSmallWindowSize 获取保利威 webview 小窗尺寸的函数
|
|
174
|
+
* @param options.getPlvWebviewBridge 获取保利威 webview 桥接器的函数
|
|
175
|
+
* @param options.isWxMiniProgramEnv 判断是否处于微信小程序环境的函数
|
|
176
|
+
* @param options.toWxMiniProgram 跳转微信小程序的函数
|
|
177
|
+
*/
|
|
178
|
+
export declare function navigateToLink(options: NavigateToLinkOptions): void;
|
|
179
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(i,n,o,t){return new(o||(o=Promise))((function(e,r){function a(i){try{s(t.next(i))}catch(i){r(i)}}function l(i){try{s(t.throw(i))}catch(i){r(i)}}function s(i){var n;i.done?e(i.value):(n=i.value,n instanceof o?n:new o((function(i){i(n)}))).then(a,l)}s((t=t.apply(i,n||[])).next())}))};import{getCurrentUAInfo}from"@just4/ua-info";import{concat}from"@just4/querystring";const ua=navigator.userAgent.toLowerCase(),uaInfo=getCurrentUAInfo();export const isAndroid=uaInfo.os.isAndroid;export const isIOS=uaInfo.os.isIOS;export const isWeixin=uaInfo.client.isWx;export const isWorkWeixin=uaInfo.client.isWxWork;export const isPcMiniProgram=(isWeixin||isWorkWeixin)&&/miniprogramenv/.test(ua);export const isMobile=uaInfo.isPortable||isPcMiniProgram;export var LinkType;!function(i){i[i.Normal=10]="Normal",i[i.MultiPlatform=11]="MultiPlatform",i[i.Native=12]="Native"}(LinkType||(LinkType={}));export var LinkJumpWay;function getNativeToPointMallFn(){var i,n,o,t;return isAndroid?null===(i=window.AndroidNative)||void 0===i?void 0:i.toPointMall:isIOS?null===(t=null===(o=null===(n=window.webkit)||void 0===n?void 0:n.messageHandlers)||void 0===o?void 0:o.gotoPointsMall)||void 0===t?void 0:t.postMessage:void 0}function toNativeLink(i){const{androidLink:n,iosLink:o,otherLink:t}=i,e=getNativeToPointMallFn();if(e){let i=isAndroid?n:o;const t=encodeURIComponent(location.href);i=concat(i,{plt_back_uri:t});e(JSON.stringify({url:i}))}else window.open(t,"_blank","noopener=yes")}function toPlvWebviewBridge(i){return __awaiter(this,void 0,void 0,(function*(){const{getPlvWebviewSmallWindowSize:n,getPlvWebviewBridge:o}=i,t=(null==n?void 0:n())||{width:90,height:160},e=yield null==o?void 0:o();e&&e.sendData("clickProduct",{width:t.width,height:t.height,newPage:!0,link:i.link,data:i.data})}))}function toMultiPlatformLink(i){return __awaiter(this,void 0,void 0,(function*(){const{linkData:n,isWxMiniProgramEnv:o,toWxMiniProgram:t,openLink:e,getLinkParams:r}=i,{wxMiniprogramLink:a,mobileLink:l,pcLink:s}=n;let k=!1;try{k=(yield null==o?void 0:o())||!1}catch(i){k=!1}k&&a&&t?t(formatLink(a,r)):isMobile?e(formatLink(l,r),LinkJumpWay.NewWindow):isMobile||e(formatLink(s,r),LinkJumpWay.NewWindow)}))}!function(i){i.PopUp="POP_UP",i.NewWindow="NEW_WINDOW",i.CurrentWindow="CURRENT_WINDOW"}(LinkJumpWay||(LinkJumpWay={}));export function formatLink(i,n){let o={};if(n){const t=n(i);o=Object.assign({},o,t)}return concat(i,o)}export function navigateToLink(i){const{linkData:n,openLink:o,isPlvWebview:t,getPlvWebviewSmallWindowSize:e,getPlvWebviewBridge:r,isWxMiniProgramEnv:a,toWxMiniProgram:l,getLinkParams:s}=i,{linkType:k}=n,d=(null==t?void 0:t())||!1;if(k!==LinkType.Native){if(d){let i="";const{link:o,mobileLink:t,mobileAppLink:a,wxMiniprogramOriginalId:l,wxMiniprogramLink:d}=n;switch(k){case LinkType.Normal:i=o;break;case LinkType.MultiPlatform:i=a||t}let u=null;return k!==LinkType.Normal&&(u={mobileLink:formatLink(t,s),wxMiniprogramOriginalId:l,wxMiniprogramLink:formatLink(d,s),mobileAppLink:formatLink(a,s)}),void toPlvWebviewBridge({link:formatLink(i,s),data:u,getPlvWebviewSmallWindowSize:e,getPlvWebviewBridge:r})}if(k!==LinkType.Normal)k===LinkType.MultiPlatform&&toMultiPlatformLink({linkData:n,getLinkParams:s,isWxMiniProgramEnv:a,toWxMiniProgram:l,openLink:o});else{const{link:i,jumpWay:t}=n;o(formatLink(i,s),t)}}else toNativeLink({androidLink:formatLink(n.androidLink,s),iosLink:formatLink(n.iosLink,s),otherLink:formatLink(n.otherLink,s)})}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polyv/utils",
|
|
3
|
-
"version": "2.13.0-beta.
|
|
3
|
+
"version": "2.13.0-beta.3",
|
|
4
4
|
"description": "Utility functions of Polyv frontend development.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"polyv",
|
|
@@ -20,5 +20,9 @@
|
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20.0.0"
|
|
22
22
|
},
|
|
23
|
-
"miniprogram": "./dist/es"
|
|
23
|
+
"miniprogram": "./dist/es",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@just4/querystring": "^2.0.0",
|
|
26
|
+
"@just4/ua-info": "^3.2.0"
|
|
27
|
+
}
|
|
24
28
|
}
|