mazey-wechat-launch-app 2.4.4 → 2.6.0
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/LICENSE +1 -1
- package/README.md +33 -7
- package/lib/index.cjs.js +2 -2
- package/lib/index.d.ts +30 -11
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +2 -2
- package/lib/launch-app.min.js +2 -2
- package/package.json +2 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
<!-- omit from toc -->
|
|
2
|
-
|
|
3
1
|
# mazey-wechat-launch-app
|
|
4
2
|
|
|
5
3
|
[![NPM version][npm-image]][npm-url]
|
|
@@ -31,10 +29,8 @@
|
|
|
31
29
|
|
|
32
30
|
## Install
|
|
33
31
|
|
|
34
|
-
使用 [npm](https://www.npmjs.com/package/mazey-wechat-launch-app) 安装 mazey-wechat-launch-app:
|
|
35
|
-
|
|
36
32
|
```bash
|
|
37
|
-
npm install mazey-wechat-launch-app
|
|
33
|
+
npm install mazey-wechat-launch-app
|
|
38
34
|
```
|
|
39
35
|
|
|
40
36
|
## Usage
|
|
@@ -100,8 +96,6 @@ app.start({});
|
|
|
100
96
|
</script>
|
|
101
97
|
```
|
|
102
98
|
|
|
103
|
-
提示:如果项目里面已经使用了 jQuery、js-sha1、mazey 依赖库,可以使用体积更小的版本 [`v2.1.4`](https://cdn.jsdelivr.net/npm/mazey-wechat-launch-app@2.1.4/lib/launch-app.min.js)。
|
|
104
|
-
|
|
105
99
|
## API
|
|
106
100
|
|
|
107
101
|
### 参数
|
|
@@ -124,6 +118,38 @@ app.start({});
|
|
|
124
118
|
| `update` | 更新 | function |
|
|
125
119
|
| `destroy` | 销毁 | function |
|
|
126
120
|
|
|
121
|
+
### 分享配置与更新
|
|
122
|
+
|
|
123
|
+
好友分享使用 `updateAppMessageShareDataOptions`,类型为 `UpdateAppMessageShareDataOptions`,包含 `title`、`desc`、`link` 和 `imgUrl`。朋友圈分享使用 `updateTimelineShareDataOptions`,类型为 `UpdateTimelineShareDataOptions`,包含 `title`、`link` 和 `imgUrl`。两种配置都支持可选的 `success` 回调。
|
|
124
|
+
|
|
125
|
+
`success` 表示分享数据设置成功,不表示用户已完成分享。分享链接需符合微信 JS 安全域名要求。
|
|
126
|
+
|
|
127
|
+
`onMenuShareAppMessageOptions`、`onMenuShareTimelineOptions` 和对应旧类型继续兼容,但已标记为 deprecated。每个渠道的新配置不为 `undefined` 时,采用完整的新配置,不合并旧配置字段。旧参数中的 `type`、`dataUrl` 和 `cancel` 不会传给新接口。
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const app = LAUNCH_APP({
|
|
131
|
+
weixinJsSdkTicket: 'valid-ticket',
|
|
132
|
+
serviceAccountAppId: 'wx-service',
|
|
133
|
+
updateAppMessageShareDataOptions: {
|
|
134
|
+
title: '分享标题',
|
|
135
|
+
desc: '分享描述',
|
|
136
|
+
link: 'https://example.com/',
|
|
137
|
+
imgUrl: 'https://example.com/icon.png',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
app.LAUNCH_APP_SHARE_TIMELINE({
|
|
142
|
+
title: '朋友圈标题',
|
|
143
|
+
link: 'https://example.com/',
|
|
144
|
+
imgUrl: 'https://example.com/icon.png',
|
|
145
|
+
});
|
|
146
|
+
app.start({});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
返回值中的 `LAUNCH_APP_SHARE_APP_MESSAGE` 和 `LAUNCH_APP_SHARE_TIMELINE`,与对应的 `window.LAUNCH_APP_*` 属性引用相同函数。工厂创建后即可调用;仍需调用 `start()` 初始化 SDK。ready 前每个渠道只保留最新配置,方法调用优先于工厂初始配置。ready 后调用方法会立即更新分享数据,无需提供 `openPlatformMobileAppId`。未配置的渠道不主动调用 SDK。
|
|
150
|
+
|
|
151
|
+
参考:[微信 JS-SDK 文档](https://developers.weixin.qq.com/doc/service/guide/h5/jssdk.html)。
|
|
152
|
+
|
|
127
153
|
## FAQ
|
|
128
154
|
|
|
129
155
|
**1\. 为什么微信里面通过分享卡片能唤起,直接打开链接却无法唤起的?**
|
package/lib/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* mazey-wechat-launch-app v2.
|
|
2
|
+
* mazey-wechat-launch-app v2.6.0 https://www.npmjs.com/package/mazey-wechat-launch-app
|
|
3
3
|
* (c) 2018-2026 Cheng
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
"use strict";require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.object.assign.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js");var e=require("mazey"),n=require("jquery"),
|
|
6
|
+
"use strict";require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.object.assign.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/es.string.link.js"),require("core-js/modules/web.dom-collections.iterator.js");var e=require("mazey"),n=require("jquery"),t=require("js-sha1");function a(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var a=t.call(e,n);if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:n+""}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function r(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,a)}return t}function i(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?r(Object(t),!0).forEach(function(n){a(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):r(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}return e}var o={weixinJsSdkTicket:"",launchContainerQuery:".mazey-launch-app-selector",launchShowWeixinToBrowserImgUrl:"",canShowWeixinToBrowser:!1,extInfo:"",serviceAccountAppId:"",wexinServiceAccountAppId:"",openPlatformMobileAppId:"",genTagPrefixStr:"mazey-launch-app-btn-prefix-",launchShowWeixinToBrowserClassName:"mazey-launch-app-wx-to-browser",launchBtnClassName:"mazey-launch-app-inner-btn",launchBtnStyle:"",launchBtnText:"Launch App <br /><br /><br />",launchErrorLink:"",canContinuousUpdating:!1,onMenuShareTimelineOptions:void 0,onMenuShareAppMessageOptions:void 0,updateTimelineShareDataOptions:void 0,updateAppMessageShareDataOptions:void 0,isConClosed:!0,isWxDebug:!1,openTagList:["wx-open-launch-app"],canLaunchApp:function(){return!0},canFireErrorLinkDirectly:function(){return!1},launchBtnClick:function(){},launchReady:function(){}};module.exports=function(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o,r=Object.assign(o,a),c=r.weixinJsSdkTicket,l=r.launchContainerQuery,s=r.genTagPrefixStr,p=r.launchShowWeixinToBrowserImgUrl,u=r.canShowWeixinToBrowser,d=r.launchShowWeixinToBrowserClassName,h=r.launchBtnClassName,g=r.launchBtnStyle,f=r.launchBtnText,m=r.launchErrorLink,w=r.wexinServiceAccountAppId,A=r.openPlatformMobileAppId,v=r.canContinuousUpdating,_=r.onMenuShareTimelineOptions,y=r.onMenuShareAppMessageOptions,P=r.updateTimelineShareDataOptions,E=r.updateAppMessageShareDataOptions,b=r.isConClosed,S=r.isWxDebug,x=r.openTagList,k=r.canLaunchApp,L=r.canFireErrorLinkDirectly,O=r.launchBtnClick,I=r.launchReady,C=r.serviceAccountAppId,j=r.extInfo,T=e.genCustomConsole("LaunchCon:",{isClosed:b}),N=window.wx;N||console.error("Launch App: wx is not found");var D=function(){};T.log("Launch App");var U={title:document.title,link:location.href,imgUrl:""},H=i(i({},U),{},{desc:""}),R=!1,W=void 0!==P?P:_,B=void 0!==E?E:y,z=function(e){var n=e.title,t=e.link,a=e.imgUrl,r=e.success;N.updateTimelineShareData(i({title:n,link:t,imgUrl:a},void 0===r?{}:{success:r}))},q=function(e){var n=e.title,t=e.desc,a=e.link,r=e.imgUrl,o=e.success;N.updateAppMessageShareData(i({title:n,desc:t,link:a,imgUrl:r},void 0===o?{}:{success:o}))},M=function(e){W=i(i({},U),e),R&&z(W)},X=function(e){B=i(i({},H),e),R&&q(B)};window.LAUNCH_APP_SHARE_TIMELINE=M,window.LAUNCH_APP_SHARE_APP_MESSAGE=X;var J=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"button";return"<style>.".concat(h,"{")+"opacity: 0;width: 100%;height: 100%;backgroud: transparent;color: #300f54;border: none;box-sizing: border-box;text-align: center;vertical-align: middle;"+g+n+"}</style>"+"<".concat(t,' class="').concat(h,'"')+(e&&"button"===t?' onclick="'.concat(e,'"'):"")+(e&&"a"===t?' target="_self" href="'.concat(e,'"'):"")+">"+f+"</".concat(t,">")},F=J();function Q(){e.addStyle('.mazey-launch-app-mask{position:fixed;top:0;right:0;bottom:0;left:0;background-color:rgba(0, 0, 0, .5);text-align:right;font-size:0;white-space:nowrap;overflow:auto;z-index:999;}.mazey-launch-app-img{display:inline-block;vertical-align:middle;text-align:left;font-size:14px;white-space:normal;width:50vw;margin:0.5rem 0.5rem 0 0;}.mazey-launch-app-img:after{content:"";display:inline-block;height:100%;vertical-align:middle;}',{id:"mazey-launch-app-mask-style"}),window.LAUNCH_APP_HIDE_WEIXIN_BROWSER||(window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=function(){n(".mazey-launch-app-mask").hide()}),0===n(".mazey-launch-app-mask").length?n("body").append("<div class='mazey-launch-app-mask' onclick='window.LAUNCH_APP_HIDE_WEIXIN_BROWSER()'><img "+"class='mazey-launch-app-img ".concat(d,"' ")+"src='".concat(p,"' ")+"alt='Launch App' /></div>"):n(".mazey-launch-app-mask").show()}function Y(){T.log("renderWeixinLaunchTemplate"),!C&&w&&(console.warn("wexinServiceAccountAppId will be deprecated, use serviceAccountAppId instead."),C=w),function(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";T.log("renderWXOpenLaunchApp"),R=!1,Promise.all([Promise.resolve(c||window.LAUNCH_APP_WEIXIN_JS_SDK_TICKET||e.getQueryParam("weixinJsSdkTicket")||""),Promise.resolve(t)]).then(function(t){T.log("allRes",t);var i=t[0];if(i){var o=t[1];if(o){var c=e.generateRndNum(7),p=i,d=(new Date).getTime(),h=o("jsapi_ticket="+p+"&noncestr="+c+"×tamp="+d+"&url="+location.href);return N.config({debug:S,appId:a,timestamp:d,nonceStr:c,signature:h,jsApiList:["showOptionMenu","updateTimelineShareData","updateAppMessageShareData"],openTagList:x}),N.ready(function(){if(R=!0,void 0!==B&&q(B),void 0!==W&&z(W),r){window.LAUNCH_APP_READY=!0,I&&I();var e=function(){var e=n(l);T.log("containers",l,e,e.length),e.length>0&&e.each(function(e,t){var a=n(t).attr("data-launch-app-key");if(!a){var i=n(t).parents("[data-launch-app-key]:eq(0)");i.length>0&&(a=i.attr("data-launch-app-key"),T.log("keyEle",i,a))}a||(a=String(e));var o="mazey-launch-app-tag-".concat(a),c=n(".".concat(o," wx-open-launch-app")),l=n(t).attr("data-launch-app-ext-info");if(!l){var p=n(t).parents("[data-launch-app-ext-info]:eq(0)");p.length>0&&(l=p.attr("data-launch-app-ext-info"),T.log("eleExtInfoEle parents",p,l))}l&&(j=l);var d=n(t).attr("data-launch-app-error-link");if(!d){var h=n(t).parents("[data-launch-app-error-link]:eq(0)");h.length>0&&(d=h.attr("data-launch-app-error-link"),T.log("eleErrorLinkEle parents",h,d))}var g=m;d&&(g=d),0===c.length&&(n(t).addClass(o),T.log("success:",o),function(e){var t=s,a=t+e,i="<wx-open-launch-app id='"+a+"' appid='"+r+"' extinfo='".concat(j)+"' style='z-index:99;position:absolute;width:100%;height:100%;opacity:1;background:transparent;overflow:hidden;left:0;'><script type='text/wxtag-template'>"+F+"<\/script></wx-open-launch-app>";n("."+e+":eq(0)").append(i);var o=document.getElementById(a);o&&(o.addEventListener("ready",function(e){T.log("ready event",e)}),o.addEventListener("launch",function(e){T.log("launch event",e),e.detail&&e.detail.extInfo&&T.log("launch extInfo",e.detail.extInfo)}),o.addEventListener("error",function(e){T.error(e.detail),n("[id^='"+t+"']").hide(),u&&Q(),g&&(T.log("realErrorLink",g),location.href=g)}),o.addEventListener("click",function(e){T.log("click event",e),O&&O()}))}(o))})};e(),D=e}else T.log("openPlatformMobileAppId is required for weixin launch app")}),N.error(function(e){T.error(e)}),"success:launch_app"}T.error("sha1 is required")}else T.error("weixinJsSdkTicket is required")}).catch(function(e){T.error(e)})}(C,A)}function G(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(T.log("appUpdated",e),!window.LAUNCH_APP_LOAD&&k(e)&&(Y(),window.LAUNCH_APP_LOAD=!0),v&&window.LAUNCH_APP_LOAD&&k(e)&&D(),L()){var t=n(l);t.length>0&&t.each(function(e,t){var a=n(t).children("."+h);if(!a||!a.length){var r=n(t).attr("data-launch-app-error-link");if(!r){var i=n(t).parents("[data-launch-app-error-link]:eq(0)");i.length>0&&(r=i.attr("data-launch-app-error-link"))}if(r&&"string"==typeof r&&r.length){var o=J(r,"position:absolute;left:0;z-index:999;","a");n(t).append(o)}}})}}function K(){T.log("appBeforeDestroy",K),window.LAUNCH_APP_LOAD=null,window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=null}return window.LAUNCH_APP_UPDATE=G,window.LAUNCH_APP_BEFORE_DESTROY=K,window.LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER=Q,{LAUNCH_APP_UPDATE:G,LAUNCH_APP_BEFORE_DESTROY:K,LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER:Q,LAUNCH_APP_SHARE_TIMELINE:M,LAUNCH_APP_SHARE_APP_MESSAGE:X,start:G,update:G,destroy:K}};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
export interface UpdateTimelineShareDataOptions {
|
|
2
|
+
title: string;
|
|
3
|
+
link: string;
|
|
4
|
+
imgUrl: string;
|
|
5
|
+
/** Called when share data is configured, not when the user shares. */
|
|
6
|
+
success?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface UpdateAppMessageShareDataOptions extends UpdateTimelineShareDataOptions {
|
|
9
|
+
desc: string;
|
|
10
|
+
}
|
|
11
|
+
/** @deprecated Use UpdateTimelineShareDataOptions. */
|
|
1
12
|
export interface MenuShareTimelineOptions {
|
|
2
13
|
title: string;
|
|
3
14
|
link: string;
|
|
4
15
|
imgUrl: string;
|
|
16
|
+
/** Called when share data is configured, not when the user shares. */
|
|
5
17
|
success: () => void;
|
|
6
18
|
cancel: () => void;
|
|
7
19
|
}
|
|
20
|
+
/** @deprecated Use UpdateAppMessageShareDataOptions. */
|
|
8
21
|
export interface MenuShareAppMessageOptions {
|
|
9
22
|
title: string;
|
|
10
23
|
desc: string;
|
|
@@ -12,11 +25,12 @@ export interface MenuShareAppMessageOptions {
|
|
|
12
25
|
imgUrl: string;
|
|
13
26
|
type: string;
|
|
14
27
|
dataUrl: string;
|
|
28
|
+
/** Called when share data is configured, not when the user shares. */
|
|
15
29
|
success: () => void;
|
|
16
30
|
cancel: () => void;
|
|
17
31
|
}
|
|
18
|
-
export type LAUNCH_APP_SHARE_TIMELINE = (options: MenuShareTimelineOptions) => void;
|
|
19
|
-
export type LAUNCH_APP_SHARE_APP_MESSAGE = (options: MenuShareAppMessageOptions) => void;
|
|
32
|
+
export type LAUNCH_APP_SHARE_TIMELINE = (options: UpdateTimelineShareDataOptions | MenuShareTimelineOptions) => void;
|
|
33
|
+
export type LAUNCH_APP_SHARE_APP_MESSAGE = (options: UpdateAppMessageShareDataOptions | MenuShareAppMessageOptions) => void;
|
|
20
34
|
export interface retVal {
|
|
21
35
|
LAUNCH_APP_UPDATE(data: any): void;
|
|
22
36
|
LAUNCH_APP_BEFORE_DESTROY(): void;
|
|
@@ -27,12 +41,7 @@ export interface retVal {
|
|
|
27
41
|
update(data: any): void;
|
|
28
42
|
destroy(): void;
|
|
29
43
|
}
|
|
30
|
-
|
|
31
|
-
* Launch App
|
|
32
|
-
*
|
|
33
|
-
* @returns {void}
|
|
34
|
-
*/
|
|
35
|
-
declare const _default: (options?: {
|
|
44
|
+
export interface LaunchAppOptions {
|
|
36
45
|
weixinJsSdkTicket?: string;
|
|
37
46
|
launchContainerQuery?: string;
|
|
38
47
|
genTagPrefixStr?: string;
|
|
@@ -48,8 +57,12 @@ declare const _default: (options?: {
|
|
|
48
57
|
wexinServiceAccountAppId?: string;
|
|
49
58
|
openPlatformMobileAppId?: string;
|
|
50
59
|
canContinuousUpdating?: boolean;
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
updateTimelineShareDataOptions?: UpdateTimelineShareDataOptions | undefined;
|
|
61
|
+
updateAppMessageShareDataOptions?: UpdateAppMessageShareDataOptions | undefined;
|
|
62
|
+
/** @deprecated Use updateTimelineShareDataOptions. */
|
|
63
|
+
onMenuShareTimelineOptions?: MenuShareTimelineOptions | undefined;
|
|
64
|
+
/** @deprecated Use updateAppMessageShareDataOptions. */
|
|
65
|
+
onMenuShareAppMessageOptions?: MenuShareAppMessageOptions | undefined;
|
|
53
66
|
isConClosed?: boolean;
|
|
54
67
|
isWxDebug?: boolean;
|
|
55
68
|
openTagList?: string[];
|
|
@@ -57,6 +70,12 @@ declare const _default: (options?: {
|
|
|
57
70
|
canFireErrorLinkDirectly?: () => boolean;
|
|
58
71
|
launchBtnClick?: () => void;
|
|
59
72
|
launchReady?: () => void;
|
|
60
|
-
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Launch App
|
|
76
|
+
*
|
|
77
|
+
* @returns Lifecycle and share-data methods.
|
|
78
|
+
*/
|
|
79
|
+
declare const _default: (options?: LaunchAppOptions) => retVal;
|
|
61
80
|
export default _default;
|
|
62
81
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,MAAM,yBAAyB,GAAG,CACtC,OAAO,EAAE,wBAAwB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,8BAA8B;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,gCAAiC,SAAQ,8BAA8B;IACtF,IAAI,EAAE,MAAM,CAAC;CACd;AAED,sDAAsD;AACtD,MAAM,WAAW,w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|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
import"core-js/modules/es.array.concat.js";import"core-js/modules/es.array.iterator.js";import"core-js/modules/es.object.assign.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.promise.js";import"core-js/modules/es.string.iterator.js";import"core-js/modules/web.dom-collections.iterator.js";import{genCustomConsole as e,addStyle as n,generateRndNum as
|
|
6
|
+
import"core-js/modules/es.array.concat.js";import"core-js/modules/es.array.iterator.js";import"core-js/modules/es.object.assign.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.promise.js";import"core-js/modules/es.string.iterator.js";import"core-js/modules/es.string.link.js";import"core-js/modules/web.dom-collections.iterator.js";import{genCustomConsole as e,addStyle as n,generateRndNum as t,getQueryParam as a}from"mazey";import r from"jquery";import i from"js-sha1";function o(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var a=t.call(e,n);if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:n+""}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function c(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,a)}return t}function l(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?c(Object(t),!0).forEach(function(n){o(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):c(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}return e}var p={weixinJsSdkTicket:"",launchContainerQuery:".mazey-launch-app-selector",launchShowWeixinToBrowserImgUrl:"",canShowWeixinToBrowser:!1,extInfo:"",serviceAccountAppId:"",wexinServiceAccountAppId:"",openPlatformMobileAppId:"",genTagPrefixStr:"mazey-launch-app-btn-prefix-",launchShowWeixinToBrowserClassName:"mazey-launch-app-wx-to-browser",launchBtnClassName:"mazey-launch-app-inner-btn",launchBtnStyle:"",launchBtnText:"Launch App <br /><br /><br />",launchErrorLink:"",canContinuousUpdating:!1,onMenuShareTimelineOptions:void 0,onMenuShareAppMessageOptions:void 0,updateTimelineShareDataOptions:void 0,updateAppMessageShareDataOptions:void 0,isConClosed:!0,isWxDebug:!1,openTagList:["wx-open-launch-app"],canLaunchApp:function(){return!0},canFireErrorLinkDirectly:function(){return!1},launchBtnClick:function(){},launchReady:function(){}},s=function(){var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:p,c=Object.assign(p,o),s=c.weixinJsSdkTicket,u=c.launchContainerQuery,d=c.genTagPrefixStr,h=c.launchShowWeixinToBrowserImgUrl,g=c.canShowWeixinToBrowser,f=c.launchShowWeixinToBrowserClassName,m=c.launchBtnClassName,w=c.launchBtnStyle,A=c.launchBtnText,v=c.launchErrorLink,_=c.wexinServiceAccountAppId,y=c.openPlatformMobileAppId,P=c.canContinuousUpdating,E=c.onMenuShareTimelineOptions,b=c.onMenuShareAppMessageOptions,S=c.updateTimelineShareDataOptions,x=c.updateAppMessageShareDataOptions,k=c.isConClosed,L=c.isWxDebug,O=c.openTagList,I=c.canLaunchApp,C=c.canFireErrorLinkDirectly,j=c.launchBtnClick,T=c.launchReady,N=c.serviceAccountAppId,D=c.extInfo,U=e("LaunchCon:",{isClosed:k}),H=window.wx;H||console.error("Launch App: wx is not found");var W=function(){};U.log("Launch App");var B={title:document.title,link:location.href,imgUrl:""},R=l(l({},B),{},{desc:""}),z=!1,M=void 0!==S?S:E,q=void 0!==x?x:b,X=function(e){var n=e.title,t=e.link,a=e.imgUrl,r=e.success;H.updateTimelineShareData(l({title:n,link:t,imgUrl:a},void 0===r?{}:{success:r}))},J=function(e){var n=e.title,t=e.desc,a=e.link,r=e.imgUrl,i=e.success;H.updateAppMessageShareData(l({title:n,desc:t,link:a,imgUrl:r},void 0===i?{}:{success:i}))},F=function(e){M=l(l({},B),e),z&&X(M)},Y=function(e){q=l(l({},R),e),z&&J(q)};window.LAUNCH_APP_SHARE_TIMELINE=F,window.LAUNCH_APP_SHARE_APP_MESSAGE=Y;var G=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"button";return"<style>.".concat(m,"{")+"opacity: 0;width: 100%;height: 100%;backgroud: transparent;color: #300f54;border: none;box-sizing: border-box;text-align: center;vertical-align: middle;"+w+n+"}</style>"+"<".concat(t,' class="').concat(m,'"')+(e&&"button"===t?' onclick="'.concat(e,'"'):"")+(e&&"a"===t?' target="_self" href="'.concat(e,'"'):"")+">"+A+"</".concat(t,">")},K=G();function Q(){n('.mazey-launch-app-mask{position:fixed;top:0;right:0;bottom:0;left:0;background-color:rgba(0, 0, 0, .5);text-align:right;font-size:0;white-space:nowrap;overflow:auto;z-index:999;}.mazey-launch-app-img{display:inline-block;vertical-align:middle;text-align:left;font-size:14px;white-space:normal;width:50vw;margin:0.5rem 0.5rem 0 0;}.mazey-launch-app-img:after{content:"";display:inline-block;height:100%;vertical-align:middle;}',{id:"mazey-launch-app-mask-style"}),window.LAUNCH_APP_HIDE_WEIXIN_BROWSER||(window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=function(){r(".mazey-launch-app-mask").hide()}),0===r(".mazey-launch-app-mask").length?r("body").append("<div class='mazey-launch-app-mask' onclick='window.LAUNCH_APP_HIDE_WEIXIN_BROWSER()'><img "+"class='mazey-launch-app-img ".concat(f,"' ")+"src='".concat(h,"' ")+"alt='Launch App' /></div>"):r(".mazey-launch-app-mask").show()}function V(){U.log("renderWeixinLaunchTemplate"),!N&&_&&(console.warn("wexinServiceAccountAppId will be deprecated, use serviceAccountAppId instead."),N=_),function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";U.log("renderWXOpenLaunchApp"),z=!1,Promise.all([Promise.resolve(s||window.LAUNCH_APP_WEIXIN_JS_SDK_TICKET||a("weixinJsSdkTicket")||""),Promise.resolve(i)]).then(function(a){U.log("allRes",a);var i=a[0];if(i){var o=a[1];if(o){var c=t(7),l=i,p=(new Date).getTime(),s=o("jsapi_ticket="+l+"&noncestr="+c+"×tamp="+p+"&url="+location.href);return H.config({debug:L,appId:e,timestamp:p,nonceStr:c,signature:s,jsApiList:["showOptionMenu","updateTimelineShareData","updateAppMessageShareData"],openTagList:O}),H.ready(function(){if(z=!0,void 0!==q&&J(q),void 0!==M&&X(M),n){window.LAUNCH_APP_READY=!0,T&&T();var e=function(){var e=r(u);U.log("containers",u,e,e.length),e.length>0&&e.each(function(e,t){var a=r(t).attr("data-launch-app-key");if(!a){var i=r(t).parents("[data-launch-app-key]:eq(0)");i.length>0&&(a=i.attr("data-launch-app-key"),U.log("keyEle",i,a))}a||(a=String(e));var o="mazey-launch-app-tag-".concat(a),c=r(".".concat(o," wx-open-launch-app")),l=r(t).attr("data-launch-app-ext-info");if(!l){var p=r(t).parents("[data-launch-app-ext-info]:eq(0)");p.length>0&&(l=p.attr("data-launch-app-ext-info"),U.log("eleExtInfoEle parents",p,l))}l&&(D=l);var s=r(t).attr("data-launch-app-error-link");if(!s){var u=r(t).parents("[data-launch-app-error-link]:eq(0)");u.length>0&&(s=u.attr("data-launch-app-error-link"),U.log("eleErrorLinkEle parents",u,s))}var h=v;s&&(h=s),0===c.length&&(r(t).addClass(o),U.log("success:",o),function(e){var t=d,a=t+e,i="<wx-open-launch-app id='"+a+"' appid='"+n+"' extinfo='".concat(D)+"' style='z-index:99;position:absolute;width:100%;height:100%;opacity:1;background:transparent;overflow:hidden;left:0;'><script type='text/wxtag-template'>"+K+"<\/script></wx-open-launch-app>";r("."+e+":eq(0)").append(i);var o=document.getElementById(a);o&&(o.addEventListener("ready",function(e){U.log("ready event",e)}),o.addEventListener("launch",function(e){U.log("launch event",e),e.detail&&e.detail.extInfo&&U.log("launch extInfo",e.detail.extInfo)}),o.addEventListener("error",function(e){U.error(e.detail),r("[id^='"+t+"']").hide(),g&&Q(),h&&(U.log("realErrorLink",h),location.href=h)}),o.addEventListener("click",function(e){U.log("click event",e),j&&j()}))}(o))})};e(),W=e}else U.log("openPlatformMobileAppId is required for weixin launch app")}),H.error(function(e){U.error(e)}),"success:launch_app"}U.error("sha1 is required")}else U.error("weixinJsSdkTicket is required")}).catch(function(e){U.error(e)})}(N,y)}function Z(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(U.log("appUpdated",e),!window.LAUNCH_APP_LOAD&&I(e)&&(V(),window.LAUNCH_APP_LOAD=!0),P&&window.LAUNCH_APP_LOAD&&I(e)&&W(),C()){var n=r(u);n.length>0&&n.each(function(e,n){var t=r(n).children("."+m);if(!t||!t.length){var a=r(n).attr("data-launch-app-error-link");if(!a){var i=r(n).parents("[data-launch-app-error-link]:eq(0)");i.length>0&&(a=i.attr("data-launch-app-error-link"))}if(a&&"string"==typeof a&&a.length){var o=G(a,"position:absolute;left:0;z-index:999;","a");r(n).append(o)}}})}}function $(){U.log("appBeforeDestroy",$),window.LAUNCH_APP_LOAD=null,window.LAUNCH_APP_HIDE_WEIXIN_BROWSER=null}return window.LAUNCH_APP_UPDATE=Z,window.LAUNCH_APP_BEFORE_DESTROY=$,window.LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER=Q,{LAUNCH_APP_UPDATE:Z,LAUNCH_APP_BEFORE_DESTROY:$,LAUNCH_APP_SHOW_WEIXIN_TO_BROWSER:Q,LAUNCH_APP_SHARE_TIMELINE:F,LAUNCH_APP_SHARE_APP_MESSAGE:Y,start:Z,update:Z,destroy:$}};export{s as default};
|