@polyv/utils 2.13.0-beta.2 → 2.13.0-beta.4
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 +12 -8
- package/cjs/external-link.js +1 -1
- package/es/external-link.d.ts +12 -8
- package/es/external-link.js +1 -1
- package/package.json +1 -1
package/cjs/external-link.d.ts
CHANGED
|
@@ -17,14 +17,6 @@ export interface WebViewBridge {
|
|
|
17
17
|
export declare const isAndroid: boolean;
|
|
18
18
|
/** 是否 iOS */
|
|
19
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
20
|
type ToPointMallFunc = (params: string) => unknown;
|
|
29
21
|
declare global {
|
|
30
22
|
interface Window {
|
|
@@ -127,16 +119,26 @@ export interface LinkData {
|
|
|
127
119
|
*/
|
|
128
120
|
wxMiniprogramLink: string;
|
|
129
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* 获取链接参数
|
|
124
|
+
*/
|
|
125
|
+
export type GetLinkParams = (url: string) => Record<string, unknown>;
|
|
130
126
|
/**
|
|
131
127
|
* 跳转链接配置项
|
|
132
128
|
*/
|
|
133
129
|
export interface NavigateToLinkOptions {
|
|
134
130
|
/** 链接数据 */
|
|
135
131
|
linkData: LinkData;
|
|
132
|
+
/**
|
|
133
|
+
* 获取链接参数
|
|
134
|
+
*/
|
|
135
|
+
getLinkParams?: GetLinkParams;
|
|
136
136
|
/** 通用链接打开处理器 */
|
|
137
137
|
openLink: (url: string, jumpWay: LinkJumpWay) => void;
|
|
138
138
|
/** 是否处于保利威 webview 中 */
|
|
139
139
|
isPlvWebview?: () => boolean;
|
|
140
|
+
/** 是否移动端 */
|
|
141
|
+
isMobile?: () => boolean;
|
|
140
142
|
/** 获取保利威 webview 桥接器 */
|
|
141
143
|
getPlvWebviewBridge?: () => Promise<WebViewBridge | undefined>;
|
|
142
144
|
/** 获取保利威 webview 小窗尺寸 */
|
|
@@ -159,8 +161,10 @@ export declare function formatLink(url: string, getLinkParams?: (url: string) =>
|
|
|
159
161
|
* 根据链接类型和当前环境进行跳转处理
|
|
160
162
|
* @param options 跳转配置项
|
|
161
163
|
* @param options.linkData 链接数据,包含各种平台的链接和跳转方式
|
|
164
|
+
* @param options.getLinkParams 获取链接参数的函数
|
|
162
165
|
* @param options.openLink 通用链接打开处理器
|
|
163
166
|
* @param options.isPlvWebview 判断是否处于保利威 webview 中的函数
|
|
167
|
+
* @param options.isMobile 判断是否移动端的函数
|
|
164
168
|
* @param options.getPlvWebviewSmallWindowSize 获取保利威 webview 小窗尺寸的函数
|
|
165
169
|
* @param options.getPlvWebviewBridge 获取保利威 webview 桥接器的函数
|
|
166
170
|
* @param options.isWxMiniProgramEnv 判断是否处于微信小程序环境的函数
|
package/cjs/external-link.js
CHANGED
|
@@ -1 +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{
|
|
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{u(t.next(i))}catch(i){o(i)}}function l(i){try{u(t.throw(i))}catch(i){o(i)}}function u(i){var n;i.done?r(i.value):(n=i.value,n instanceof e?n:new e((function(i){i(n)}))).then(a,l)}u((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:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(l){return function(u){return function(l){if(e)throw new TypeError("Generator is already executing.");for(;o&&(o=0,l[0]&&(a=0)),a;)try{if(e=1,t&&(r=2&l[0]?t.return:l[0]?t.throw||((r=t.return)&&r.call(t),0):t.next)&&!(r=r.call(t,l[1])).done)return r;switch(t=0,r&&(l=[2&l[0],r.value]),l[0]){case 0:case 1:r=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,t=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!r||l[1]>r[0]&&l[1]<r[3])){a.label=l[1];break}if(6===l[0]&&a.label<r[1]){a.label=r[1],r=l;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(l);break}r[2]&&a.ops.pop(),a.trys.pop();continue}l=n.call(i,a)}catch(i){l=[6,i],t=0}finally{e=r=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,u])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LinkJumpWay=exports.LinkType=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"),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,l,u,s,k,d;return __generator(this,(function(v){switch(v.label){case 0:n=i.linkData,e=i.isWxMiniProgramEnv,t=i.toWxMiniProgram,r=i.openLink,o=i.getLinkParams,a=i.isMobile,l=n.wxMiniprogramLink,u=n.mobileLink,s=n.pcLink,k=(null==a?void 0:a())||!1,d=!1,v.label=1;case 1:return v.trys.push([1,3,,4]),[4,null==e?void 0:e()];case 2:return d=v.sent()||!1,[3,4];case 3:return v.sent(),d=!1,[3,4];case 4:return d&&l&&t?(t(formatLink(l,o)),[2]):k?(r(formatLink(u,o),LinkJumpWay.NewWindow),[2]):(k||r(formatLink(s,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,l=i.toWxMiniProgram,u=i.getLinkParams,s=i.isMobile,k=n.linkType,d=(null==t?void 0:t())||!1;if(k!==LinkType.Native){if(d){var v="",f=n.link,p=n.mobileLink,c=n.mobileAppLink,L=n.wxMiniprogramOriginalId,m=n.wxMiniprogramLink;switch(k){case LinkType.Normal:v=f;break;case LinkType.MultiPlatform:v=c||p}var g=null;return k!==LinkType.Normal&&(g={mobileLink:formatLink(p,u),wxMiniprogramOriginalId:L,wxMiniprogramLink:formatLink(m,u),mobileAppLink:formatLink(c,u)}),void toPlvWebviewBridge({link:formatLink(v,u),data:g,getPlvWebviewSmallWindowSize:r,getPlvWebviewBridge:o})}if(k!==LinkType.Normal)k===LinkType.MultiPlatform&&toMultiPlatformLink({linkData:n,getLinkParams:u,isWxMiniProgramEnv:a,toWxMiniProgram:l,openLink:e,isMobile:s});else{f=n.link;var w=n.jumpWay;e(formatLink(f,u),w)}}else toNativeLink({androidLink:formatLink(n.androidLink,u),iosLink:formatLink(n.iosLink,u),otherLink:formatLink(n.otherLink,u)})}exports.isAndroid=uaInfo.os.isAndroid,exports.isIOS=uaInfo.os.isIOS,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={}));
|
package/es/external-link.d.ts
CHANGED
|
@@ -17,14 +17,6 @@ export interface WebViewBridge {
|
|
|
17
17
|
export declare const isAndroid: boolean;
|
|
18
18
|
/** 是否 iOS */
|
|
19
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
20
|
type ToPointMallFunc = (params: string) => unknown;
|
|
29
21
|
declare global {
|
|
30
22
|
interface Window {
|
|
@@ -127,16 +119,26 @@ export interface LinkData {
|
|
|
127
119
|
*/
|
|
128
120
|
wxMiniprogramLink: string;
|
|
129
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* 获取链接参数
|
|
124
|
+
*/
|
|
125
|
+
export type GetLinkParams = (url: string) => Record<string, unknown>;
|
|
130
126
|
/**
|
|
131
127
|
* 跳转链接配置项
|
|
132
128
|
*/
|
|
133
129
|
export interface NavigateToLinkOptions {
|
|
134
130
|
/** 链接数据 */
|
|
135
131
|
linkData: LinkData;
|
|
132
|
+
/**
|
|
133
|
+
* 获取链接参数
|
|
134
|
+
*/
|
|
135
|
+
getLinkParams?: GetLinkParams;
|
|
136
136
|
/** 通用链接打开处理器 */
|
|
137
137
|
openLink: (url: string, jumpWay: LinkJumpWay) => void;
|
|
138
138
|
/** 是否处于保利威 webview 中 */
|
|
139
139
|
isPlvWebview?: () => boolean;
|
|
140
|
+
/** 是否移动端 */
|
|
141
|
+
isMobile?: () => boolean;
|
|
140
142
|
/** 获取保利威 webview 桥接器 */
|
|
141
143
|
getPlvWebviewBridge?: () => Promise<WebViewBridge | undefined>;
|
|
142
144
|
/** 获取保利威 webview 小窗尺寸 */
|
|
@@ -159,8 +161,10 @@ export declare function formatLink(url: string, getLinkParams?: (url: string) =>
|
|
|
159
161
|
* 根据链接类型和当前环境进行跳转处理
|
|
160
162
|
* @param options 跳转配置项
|
|
161
163
|
* @param options.linkData 链接数据,包含各种平台的链接和跳转方式
|
|
164
|
+
* @param options.getLinkParams 获取链接参数的函数
|
|
162
165
|
* @param options.openLink 通用链接打开处理器
|
|
163
166
|
* @param options.isPlvWebview 判断是否处于保利威 webview 中的函数
|
|
167
|
+
* @param options.isMobile 判断是否移动端的函数
|
|
164
168
|
* @param options.getPlvWebviewSmallWindowSize 获取保利威 webview 小窗尺寸的函数
|
|
165
169
|
* @param options.getPlvWebviewBridge 获取保利威 webview 桥接器的函数
|
|
166
170
|
* @param options.isWxMiniProgramEnv 判断是否处于微信小程序环境的函数
|
package/es/external-link.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(i,n,o,t){return new(o||(o=Promise))((function(e,
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(i,n,o,t){return new(o||(o=Promise))((function(e,a){function r(i){try{k(t.next(i))}catch(i){a(i)}}function l(i){try{k(t.throw(i))}catch(i){a(i)}}function k(i){var n;i.done?e(i.value):(n=i.value,n instanceof o?n:new o((function(i){i(n)}))).then(r,l)}k((t=t.apply(i,n||[])).next())}))};import{getCurrentUAInfo}from"@just4/ua-info";import{concat}from"@just4/querystring";const uaInfo=getCurrentUAInfo();export const isAndroid=uaInfo.os.isAndroid;export const isIOS=uaInfo.os.isIOS;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:a,isMobile:r}=i,{wxMiniprogramLink:l,mobileLink:k,pcLink:d}=n,s=(null==r?void 0:r())||!1;let u=!1;try{u=(yield null==o?void 0:o())||!1}catch(i){u=!1}u&&l&&t?t(formatLink(l,a)):s?e(formatLink(k,a),LinkJumpWay.NewWindow):s||e(formatLink(d,a),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:a,isWxMiniProgramEnv:r,toWxMiniProgram:l,getLinkParams:k,isMobile:d}=i,{linkType:s}=n,u=(null==t?void 0:t())||!1;if(s!==LinkType.Native){if(u){let i="";const{link:o,mobileLink:t,mobileAppLink:r,wxMiniprogramOriginalId:l,wxMiniprogramLink:d}=n;switch(s){case LinkType.Normal:i=o;break;case LinkType.MultiPlatform:i=r||t}let u=null;return s!==LinkType.Normal&&(u={mobileLink:formatLink(t,k),wxMiniprogramOriginalId:l,wxMiniprogramLink:formatLink(d,k),mobileAppLink:formatLink(r,k)}),void toPlvWebviewBridge({link:formatLink(i,k),data:u,getPlvWebviewSmallWindowSize:e,getPlvWebviewBridge:a})}if(s!==LinkType.Normal)s===LinkType.MultiPlatform&&toMultiPlatformLink({linkData:n,getLinkParams:k,isWxMiniProgramEnv:r,toWxMiniProgram:l,openLink:o,isMobile:d});else{const{link:i,jumpWay:t}=n;o(formatLink(i,k),t)}}else toNativeLink({androidLink:formatLink(n.androidLink,k),iosLink:formatLink(n.iosLink,k),otherLink:formatLink(n.otherLink,k)})}
|