@hairy/wechat-jssdk 1.2.4 → 1.2.6
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/package.json +1 -1
- package/dist/index.cjs.js +0 -282
- package/dist/index.d.ts +0 -114
- package/dist/index.esm.js +0 -245
package/package.json
CHANGED
package/dist/index.cjs.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
WechatJssdk: () => WechatJssdk
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
|
|
37
|
-
// src/internal/load_script.ts
|
|
38
|
-
var import_noop = __toESM(require("lodash/noop"));
|
|
39
|
-
function loadScript(source, onLoaded = import_noop.default, options = {}) {
|
|
40
|
-
const {
|
|
41
|
-
type = "text/javascript",
|
|
42
|
-
async = true,
|
|
43
|
-
crossOrigin,
|
|
44
|
-
referrerPolicy,
|
|
45
|
-
noModule,
|
|
46
|
-
defer,
|
|
47
|
-
waitForScriptLoad = true
|
|
48
|
-
} = options;
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
let shouldAppend = false;
|
|
51
|
-
let element = document.querySelector(`script[src="${source}"]`);
|
|
52
|
-
if (!element) {
|
|
53
|
-
element = document.createElement("script");
|
|
54
|
-
element.type = type;
|
|
55
|
-
element.async = async;
|
|
56
|
-
element.src = source;
|
|
57
|
-
if (defer)
|
|
58
|
-
element.defer = defer;
|
|
59
|
-
if (crossOrigin)
|
|
60
|
-
element.crossOrigin = crossOrigin;
|
|
61
|
-
if (noModule)
|
|
62
|
-
element.noModule = noModule;
|
|
63
|
-
if (referrerPolicy)
|
|
64
|
-
element.referrerPolicy = referrerPolicy;
|
|
65
|
-
shouldAppend = true;
|
|
66
|
-
} else if (Object.hasOwn(element.dataset, "loaded")) {
|
|
67
|
-
resolve(element);
|
|
68
|
-
}
|
|
69
|
-
element.addEventListener("error", (event) => reject(event));
|
|
70
|
-
element.addEventListener("abort", (event) => reject(event));
|
|
71
|
-
element.addEventListener("load", () => {
|
|
72
|
-
element.dataset.loaded = "true";
|
|
73
|
-
onLoaded(element);
|
|
74
|
-
resolve(element);
|
|
75
|
-
});
|
|
76
|
-
if (shouldAppend)
|
|
77
|
-
element = document.head.appendChild(element);
|
|
78
|
-
if (!waitForScriptLoad)
|
|
79
|
-
resolve(element);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/helper.ts
|
|
84
|
-
var WechatJssdkHelper = class {
|
|
85
|
-
constructor(options) {
|
|
86
|
-
this.isReady = false;
|
|
87
|
-
const { immediate = true, version, requestConfig } = options;
|
|
88
|
-
this.version = version || "1.3.0";
|
|
89
|
-
this.requestConfig = requestConfig;
|
|
90
|
-
this.loadJssdk();
|
|
91
|
-
if (immediate)
|
|
92
|
-
this.config();
|
|
93
|
-
}
|
|
94
|
-
loadJssdk() {
|
|
95
|
-
const scriptUrl = `https://res.wx.qq.com/open/js/jweixin-${this.version}.js`;
|
|
96
|
-
this.loadPromise = loadScript(scriptUrl).then(() => {
|
|
97
|
-
this.loadPromise = void 0;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
async config() {
|
|
101
|
-
if (this.configPromise)
|
|
102
|
-
return this.configPromise;
|
|
103
|
-
if (this.loadPromise)
|
|
104
|
-
await this.loadPromise;
|
|
105
|
-
this.configPromise = (async () => {
|
|
106
|
-
wx.config(await this.requestConfig());
|
|
107
|
-
})();
|
|
108
|
-
return this.configPromise;
|
|
109
|
-
}
|
|
110
|
-
async ready() {
|
|
111
|
-
if (this.readyPromise)
|
|
112
|
-
return this.readyPromise;
|
|
113
|
-
if (this.loadPromise)
|
|
114
|
-
await this.loadPromise;
|
|
115
|
-
if (this.isReady)
|
|
116
|
-
return;
|
|
117
|
-
this.readyPromise = new Promise((resolve, reject) => {
|
|
118
|
-
wx.ready(() => {
|
|
119
|
-
this.isReady = true;
|
|
120
|
-
this.readyPromise = void 0;
|
|
121
|
-
resolve();
|
|
122
|
-
});
|
|
123
|
-
wx.error((error) => {
|
|
124
|
-
this.isReady = false;
|
|
125
|
-
this.readyPromise = void 0;
|
|
126
|
-
reject(error);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
return this.readyPromise;
|
|
130
|
-
}
|
|
131
|
-
async error() {
|
|
132
|
-
return this.ready().catch((error) => error);
|
|
133
|
-
}
|
|
134
|
-
async implement(key, options) {
|
|
135
|
-
if (this.configPromise)
|
|
136
|
-
await this.configPromise;
|
|
137
|
-
await this.ready();
|
|
138
|
-
wx[key](options);
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// src/index.ts
|
|
143
|
-
var WechatJssdk = class extends WechatJssdkHelper {
|
|
144
|
-
constructor(options) {
|
|
145
|
-
super(options);
|
|
146
|
-
}
|
|
147
|
-
// --- 1.4.0 API start ---
|
|
148
|
-
updateAppMessageShareData(options) {
|
|
149
|
-
return this.implement("updateAppMessageShareData", options);
|
|
150
|
-
}
|
|
151
|
-
updateTimelineShareData(options) {
|
|
152
|
-
return this.implement("updateTimelineShareData", options);
|
|
153
|
-
}
|
|
154
|
-
// --- 1.4.0 API end ---
|
|
155
|
-
addCard() {
|
|
156
|
-
return this.implement("addCard");
|
|
157
|
-
}
|
|
158
|
-
checkJsApi(options) {
|
|
159
|
-
return this.implement("checkJsApi", options);
|
|
160
|
-
}
|
|
161
|
-
chooseCard(options) {
|
|
162
|
-
return this.implement("chooseCard", options);
|
|
163
|
-
}
|
|
164
|
-
chooseImage(options) {
|
|
165
|
-
return this.implement("chooseImage", options);
|
|
166
|
-
}
|
|
167
|
-
chooseWXPay(options) {
|
|
168
|
-
return this.implement("chooseWXPay", options);
|
|
169
|
-
}
|
|
170
|
-
closeWindow() {
|
|
171
|
-
return this.implement("closeWindow");
|
|
172
|
-
}
|
|
173
|
-
consumeAndShareCard(options) {
|
|
174
|
-
return this.implement("consumeAndShareCard", options);
|
|
175
|
-
}
|
|
176
|
-
downloadImage(options) {
|
|
177
|
-
return this.implement("downloadImage", options);
|
|
178
|
-
}
|
|
179
|
-
downloadVoice(options) {
|
|
180
|
-
return this.implement("downloadVoice", options);
|
|
181
|
-
}
|
|
182
|
-
getLocalImgData(options) {
|
|
183
|
-
return this.implement("getLocalImgData", options);
|
|
184
|
-
}
|
|
185
|
-
getLocation(options) {
|
|
186
|
-
return this.implement("getLocation", options);
|
|
187
|
-
}
|
|
188
|
-
getNetworkType(options) {
|
|
189
|
-
return this.implement("getNetworkType", options);
|
|
190
|
-
}
|
|
191
|
-
hideAllNonBaseMenuItem() {
|
|
192
|
-
return this.implement("hideAllNonBaseMenuItem");
|
|
193
|
-
}
|
|
194
|
-
hideMenuItems(options) {
|
|
195
|
-
return this.implement("hideMenuItems", options);
|
|
196
|
-
}
|
|
197
|
-
hideOptionMenu() {
|
|
198
|
-
return this.implement("hideOptionMenu");
|
|
199
|
-
}
|
|
200
|
-
onMenuShareAppMessage(options) {
|
|
201
|
-
return this.implement("onMenuShareAppMessage", options);
|
|
202
|
-
}
|
|
203
|
-
onMenuShareQQ(options) {
|
|
204
|
-
return this.implement("onMenuShareQQ", options);
|
|
205
|
-
}
|
|
206
|
-
onMenuShareQZone(options) {
|
|
207
|
-
return this.implement("onMenuShareQZone", options);
|
|
208
|
-
}
|
|
209
|
-
onMenuShareTimeline(options) {
|
|
210
|
-
return this.implement("onMenuShareTimeline", options);
|
|
211
|
-
}
|
|
212
|
-
onMenuShareWeibo(options) {
|
|
213
|
-
return this.implement("onMenuShareWeibo", options);
|
|
214
|
-
}
|
|
215
|
-
onSearchBeacons(options) {
|
|
216
|
-
return this.implement("onSearchBeacons", options);
|
|
217
|
-
}
|
|
218
|
-
onVoicePlayEnd(options) {
|
|
219
|
-
return this.implement("onVoicePlayEnd", options);
|
|
220
|
-
}
|
|
221
|
-
onVoiceRecordEnd(options) {
|
|
222
|
-
return this.implement("onVoiceRecordEnd", options);
|
|
223
|
-
}
|
|
224
|
-
openCard(options) {
|
|
225
|
-
return this.implement("openCard", options);
|
|
226
|
-
}
|
|
227
|
-
openLocation(options) {
|
|
228
|
-
return this.implement("openLocation", options);
|
|
229
|
-
}
|
|
230
|
-
openProductSpecificView(options) {
|
|
231
|
-
return this.implement("openProductSpecificView", options);
|
|
232
|
-
}
|
|
233
|
-
pauseVoice(options) {
|
|
234
|
-
return this.implement("pauseVoice", options);
|
|
235
|
-
}
|
|
236
|
-
playVoice(options) {
|
|
237
|
-
return this.implement("playVoice", options);
|
|
238
|
-
}
|
|
239
|
-
previewImage(options) {
|
|
240
|
-
return this.implement("previewImage", options);
|
|
241
|
-
}
|
|
242
|
-
scanQRCode(options) {
|
|
243
|
-
return this.implement("scanQRCode", options);
|
|
244
|
-
}
|
|
245
|
-
showAllNonBaseMenuItem() {
|
|
246
|
-
return this.implement("showAllNonBaseMenuItem");
|
|
247
|
-
}
|
|
248
|
-
showMenuItems(options) {
|
|
249
|
-
return this.implement("showMenuItems", options);
|
|
250
|
-
}
|
|
251
|
-
showOptionMenu() {
|
|
252
|
-
return this.implement("showOptionMenu");
|
|
253
|
-
}
|
|
254
|
-
startRecord() {
|
|
255
|
-
return this.implement("startRecord");
|
|
256
|
-
}
|
|
257
|
-
startSearchBeacons(options) {
|
|
258
|
-
return this.implement("startSearchBeacons", options);
|
|
259
|
-
}
|
|
260
|
-
stopRecord(options) {
|
|
261
|
-
return this.implement("stopRecord", options);
|
|
262
|
-
}
|
|
263
|
-
stopSearchBeacons(options) {
|
|
264
|
-
return this.implement("stopSearchBeacons", options);
|
|
265
|
-
}
|
|
266
|
-
stopVoice(options) {
|
|
267
|
-
return this.implement("stopVoice", options);
|
|
268
|
-
}
|
|
269
|
-
translateVoice(options) {
|
|
270
|
-
return this.implement("translateVoice", options);
|
|
271
|
-
}
|
|
272
|
-
uploadImage(options) {
|
|
273
|
-
return this.implement("uploadImage", options);
|
|
274
|
-
}
|
|
275
|
-
uploadVoice(options) {
|
|
276
|
-
return this.implement("uploadVoice", options);
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
280
|
-
0 && (module.exports = {
|
|
281
|
-
WechatJssdk
|
|
282
|
-
});
|
package/dist/index.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import * as WxType from 'jweixin';
|
|
2
|
-
|
|
3
|
-
declare module 'jweixin' {
|
|
4
|
-
type v4ApiMethod = 'updateTimelineShareData' | 'updateAppMessageShareData';
|
|
5
|
-
function config(config_: {
|
|
6
|
-
debug?: boolean | undefined;
|
|
7
|
-
appId: string;
|
|
8
|
-
timestamp: number;
|
|
9
|
-
nonceStr: string;
|
|
10
|
-
signature: string;
|
|
11
|
-
jsApiList: (WxType.ApiMethod | v4ApiMethod)[];
|
|
12
|
-
}): void;
|
|
13
|
-
}
|
|
14
|
-
declare global {
|
|
15
|
-
const wx: typeof WxType;
|
|
16
|
-
}
|
|
17
|
-
type WechatJssdkConfig = Omit<Parameters<typeof wx.config>[0], 'catch' | 'finally' | 'then'>;
|
|
18
|
-
interface WechatJssdkOptions {
|
|
19
|
-
/**
|
|
20
|
-
* 初始化请求配置
|
|
21
|
-
*/
|
|
22
|
-
requestConfig: () => Promise<WechatJssdkConfig> | WechatJssdkConfig;
|
|
23
|
-
/**
|
|
24
|
-
* 是否立即加载 config
|
|
25
|
-
*
|
|
26
|
-
* @default true
|
|
27
|
-
*/
|
|
28
|
-
immediate?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* wechat-jssdk 版本
|
|
31
|
-
*
|
|
32
|
-
* @default 1.3.0
|
|
33
|
-
*/
|
|
34
|
-
version?: '1.2.0' | '1.3.0' | '1.4.0' | '1.5.0' | '1.6.0';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* jssdk 的前置处理类
|
|
39
|
-
* @constructor 加载配置(apiHost,appId,config,version,jssdk)
|
|
40
|
-
* @function implement 提供 wxApi 执行器(等待 config 与 ready 结束,在调用 api)
|
|
41
|
-
* @function config 加载配置,提供 promise 式返回
|
|
42
|
-
* @function ready wx.rady,提供 promise 式返回
|
|
43
|
-
*/
|
|
44
|
-
declare class WechatJssdkHelper {
|
|
45
|
-
private version;
|
|
46
|
-
private isReady;
|
|
47
|
-
private requestConfig;
|
|
48
|
-
private loadPromise?;
|
|
49
|
-
private configPromise?;
|
|
50
|
-
private readyPromise?;
|
|
51
|
-
private loadJssdk;
|
|
52
|
-
constructor(options: WechatJssdkOptions);
|
|
53
|
-
config(): Promise<void>;
|
|
54
|
-
ready(): Promise<void>;
|
|
55
|
-
error(): Promise<any>;
|
|
56
|
-
protected implement<Key extends keyof typeof wx | string>(key: Key, options?: any): Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @description WechatJssdk Api 封装,与 [jssdk 文档](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html) 保持一致,主要以下改动
|
|
61
|
-
* @description 内置请求,读取 config 配置,初始化自动调用 wx.config
|
|
62
|
-
* @description 所有 api 的 promise 化处理(仅等待 wx.ready)
|
|
63
|
-
* @description 简易化初始化构建,config 处理
|
|
64
|
-
* @description 可指定加载 jssdk 版本(默认 1.3.0)
|
|
65
|
-
* @template `const wxJssdk = new WechatJssdk({env, config})`
|
|
66
|
-
*/
|
|
67
|
-
declare class WechatJssdk extends WechatJssdkHelper {
|
|
68
|
-
constructor(options: WechatJssdkOptions);
|
|
69
|
-
updateAppMessageShareData(options: WxType.IonMenuShareAppMessage): Promise<void>;
|
|
70
|
-
updateTimelineShareData(options: WxType.IonMenuShareAppMessage): Promise<void>;
|
|
71
|
-
addCard(): Promise<void>;
|
|
72
|
-
checkJsApi(options: WxType.IcheckJsApi): Promise<void>;
|
|
73
|
-
chooseCard(options: WxType.IchooseCard): Promise<void>;
|
|
74
|
-
chooseImage(options: WxType.IchooseImage): Promise<void>;
|
|
75
|
-
chooseWXPay(options: WxType.IchooseWXPay): Promise<void>;
|
|
76
|
-
closeWindow(): Promise<void>;
|
|
77
|
-
consumeAndShareCard(options: WxType.IconsumeAndShareCard): Promise<void>;
|
|
78
|
-
downloadImage(options: WxType.IdownloadImage): Promise<void>;
|
|
79
|
-
downloadVoice(options: WxType.IupdownloadVoice): Promise<void>;
|
|
80
|
-
getLocalImgData(options: WxType.IgetLocalImgData): Promise<void>;
|
|
81
|
-
getLocation(options: WxType.IgetLocation): Promise<void>;
|
|
82
|
-
getNetworkType(options: WxType.IgetNetworkType): Promise<void>;
|
|
83
|
-
hideAllNonBaseMenuItem(): Promise<void>;
|
|
84
|
-
hideMenuItems(options: WxType.IhideMenuItems): Promise<void>;
|
|
85
|
-
hideOptionMenu(): Promise<void>;
|
|
86
|
-
onMenuShareAppMessage(options: WxType.IonMenuShareAppMessage): Promise<void>;
|
|
87
|
-
onMenuShareQQ(options: WxType.IonMenuShareQQ): Promise<void>;
|
|
88
|
-
onMenuShareQZone(options: WxType.IonMenuShareQZone): Promise<void>;
|
|
89
|
-
onMenuShareTimeline(options: WxType.IonMenuShareTimeline): Promise<void>;
|
|
90
|
-
onMenuShareWeibo(options: WxType.IonMenuShareWeibo): Promise<void>;
|
|
91
|
-
onSearchBeacons(options: WxType.IonSearchBeacons): Promise<void>;
|
|
92
|
-
onVoicePlayEnd(options: WxType.IonVoicePlayEnd): Promise<void>;
|
|
93
|
-
onVoiceRecordEnd(options: WxType.IonVoiceRecordEnd): Promise<void>;
|
|
94
|
-
openCard(options: WxType.IopenCard): Promise<void>;
|
|
95
|
-
openLocation(options: WxType.IopenLocation): Promise<void>;
|
|
96
|
-
openProductSpecificView(options: WxType.IopenProductSpecificView): Promise<void>;
|
|
97
|
-
pauseVoice(options: WxType.IplaypausestopVoice): Promise<void>;
|
|
98
|
-
playVoice(options: WxType.IplaypausestopVoice): Promise<void>;
|
|
99
|
-
previewImage(options: WxType.IpreviewImage): Promise<void>;
|
|
100
|
-
scanQRCode(options: WxType.IscanQRCode): Promise<void>;
|
|
101
|
-
showAllNonBaseMenuItem(): Promise<void>;
|
|
102
|
-
showMenuItems(options: WxType.IshowMenuItems): Promise<void>;
|
|
103
|
-
showOptionMenu(): Promise<void>;
|
|
104
|
-
startRecord(): Promise<void>;
|
|
105
|
-
startSearchBeacons(options: WxType.IstartSearchBeacons): Promise<void>;
|
|
106
|
-
stopRecord(options: WxType.IstopRecord): Promise<void>;
|
|
107
|
-
stopSearchBeacons(options: WxType.IstopSearchBeacons): Promise<void>;
|
|
108
|
-
stopVoice(options: WxType.IplaypausestopVoice): Promise<void>;
|
|
109
|
-
translateVoice(options: WxType.ItranslateVoice): Promise<void>;
|
|
110
|
-
uploadImage(options: WxType.IuploadImage): Promise<void>;
|
|
111
|
-
uploadVoice(options: WxType.IupdownloadVoice): Promise<void>;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export { WechatJssdk };
|
package/dist/index.esm.js
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
// src/internal/load_script.ts
|
|
2
|
-
import noop from "lodash/noop";
|
|
3
|
-
function loadScript(source, onLoaded = noop, options = {}) {
|
|
4
|
-
const {
|
|
5
|
-
type = "text/javascript",
|
|
6
|
-
async = true,
|
|
7
|
-
crossOrigin,
|
|
8
|
-
referrerPolicy,
|
|
9
|
-
noModule,
|
|
10
|
-
defer,
|
|
11
|
-
waitForScriptLoad = true
|
|
12
|
-
} = options;
|
|
13
|
-
return new Promise((resolve, reject) => {
|
|
14
|
-
let shouldAppend = false;
|
|
15
|
-
let element = document.querySelector(`script[src="${source}"]`);
|
|
16
|
-
if (!element) {
|
|
17
|
-
element = document.createElement("script");
|
|
18
|
-
element.type = type;
|
|
19
|
-
element.async = async;
|
|
20
|
-
element.src = source;
|
|
21
|
-
if (defer)
|
|
22
|
-
element.defer = defer;
|
|
23
|
-
if (crossOrigin)
|
|
24
|
-
element.crossOrigin = crossOrigin;
|
|
25
|
-
if (noModule)
|
|
26
|
-
element.noModule = noModule;
|
|
27
|
-
if (referrerPolicy)
|
|
28
|
-
element.referrerPolicy = referrerPolicy;
|
|
29
|
-
shouldAppend = true;
|
|
30
|
-
} else if (Object.hasOwn(element.dataset, "loaded")) {
|
|
31
|
-
resolve(element);
|
|
32
|
-
}
|
|
33
|
-
element.addEventListener("error", (event) => reject(event));
|
|
34
|
-
element.addEventListener("abort", (event) => reject(event));
|
|
35
|
-
element.addEventListener("load", () => {
|
|
36
|
-
element.dataset.loaded = "true";
|
|
37
|
-
onLoaded(element);
|
|
38
|
-
resolve(element);
|
|
39
|
-
});
|
|
40
|
-
if (shouldAppend)
|
|
41
|
-
element = document.head.appendChild(element);
|
|
42
|
-
if (!waitForScriptLoad)
|
|
43
|
-
resolve(element);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// src/helper.ts
|
|
48
|
-
var WechatJssdkHelper = class {
|
|
49
|
-
constructor(options) {
|
|
50
|
-
this.isReady = false;
|
|
51
|
-
const { immediate = true, version, requestConfig } = options;
|
|
52
|
-
this.version = version || "1.3.0";
|
|
53
|
-
this.requestConfig = requestConfig;
|
|
54
|
-
this.loadJssdk();
|
|
55
|
-
if (immediate)
|
|
56
|
-
this.config();
|
|
57
|
-
}
|
|
58
|
-
loadJssdk() {
|
|
59
|
-
const scriptUrl = `https://res.wx.qq.com/open/js/jweixin-${this.version}.js`;
|
|
60
|
-
this.loadPromise = loadScript(scriptUrl).then(() => {
|
|
61
|
-
this.loadPromise = void 0;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
async config() {
|
|
65
|
-
if (this.configPromise)
|
|
66
|
-
return this.configPromise;
|
|
67
|
-
if (this.loadPromise)
|
|
68
|
-
await this.loadPromise;
|
|
69
|
-
this.configPromise = (async () => {
|
|
70
|
-
wx.config(await this.requestConfig());
|
|
71
|
-
})();
|
|
72
|
-
return this.configPromise;
|
|
73
|
-
}
|
|
74
|
-
async ready() {
|
|
75
|
-
if (this.readyPromise)
|
|
76
|
-
return this.readyPromise;
|
|
77
|
-
if (this.loadPromise)
|
|
78
|
-
await this.loadPromise;
|
|
79
|
-
if (this.isReady)
|
|
80
|
-
return;
|
|
81
|
-
this.readyPromise = new Promise((resolve, reject) => {
|
|
82
|
-
wx.ready(() => {
|
|
83
|
-
this.isReady = true;
|
|
84
|
-
this.readyPromise = void 0;
|
|
85
|
-
resolve();
|
|
86
|
-
});
|
|
87
|
-
wx.error((error) => {
|
|
88
|
-
this.isReady = false;
|
|
89
|
-
this.readyPromise = void 0;
|
|
90
|
-
reject(error);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
return this.readyPromise;
|
|
94
|
-
}
|
|
95
|
-
async error() {
|
|
96
|
-
return this.ready().catch((error) => error);
|
|
97
|
-
}
|
|
98
|
-
async implement(key, options) {
|
|
99
|
-
if (this.configPromise)
|
|
100
|
-
await this.configPromise;
|
|
101
|
-
await this.ready();
|
|
102
|
-
wx[key](options);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// src/index.ts
|
|
107
|
-
var WechatJssdk = class extends WechatJssdkHelper {
|
|
108
|
-
constructor(options) {
|
|
109
|
-
super(options);
|
|
110
|
-
}
|
|
111
|
-
// --- 1.4.0 API start ---
|
|
112
|
-
updateAppMessageShareData(options) {
|
|
113
|
-
return this.implement("updateAppMessageShareData", options);
|
|
114
|
-
}
|
|
115
|
-
updateTimelineShareData(options) {
|
|
116
|
-
return this.implement("updateTimelineShareData", options);
|
|
117
|
-
}
|
|
118
|
-
// --- 1.4.0 API end ---
|
|
119
|
-
addCard() {
|
|
120
|
-
return this.implement("addCard");
|
|
121
|
-
}
|
|
122
|
-
checkJsApi(options) {
|
|
123
|
-
return this.implement("checkJsApi", options);
|
|
124
|
-
}
|
|
125
|
-
chooseCard(options) {
|
|
126
|
-
return this.implement("chooseCard", options);
|
|
127
|
-
}
|
|
128
|
-
chooseImage(options) {
|
|
129
|
-
return this.implement("chooseImage", options);
|
|
130
|
-
}
|
|
131
|
-
chooseWXPay(options) {
|
|
132
|
-
return this.implement("chooseWXPay", options);
|
|
133
|
-
}
|
|
134
|
-
closeWindow() {
|
|
135
|
-
return this.implement("closeWindow");
|
|
136
|
-
}
|
|
137
|
-
consumeAndShareCard(options) {
|
|
138
|
-
return this.implement("consumeAndShareCard", options);
|
|
139
|
-
}
|
|
140
|
-
downloadImage(options) {
|
|
141
|
-
return this.implement("downloadImage", options);
|
|
142
|
-
}
|
|
143
|
-
downloadVoice(options) {
|
|
144
|
-
return this.implement("downloadVoice", options);
|
|
145
|
-
}
|
|
146
|
-
getLocalImgData(options) {
|
|
147
|
-
return this.implement("getLocalImgData", options);
|
|
148
|
-
}
|
|
149
|
-
getLocation(options) {
|
|
150
|
-
return this.implement("getLocation", options);
|
|
151
|
-
}
|
|
152
|
-
getNetworkType(options) {
|
|
153
|
-
return this.implement("getNetworkType", options);
|
|
154
|
-
}
|
|
155
|
-
hideAllNonBaseMenuItem() {
|
|
156
|
-
return this.implement("hideAllNonBaseMenuItem");
|
|
157
|
-
}
|
|
158
|
-
hideMenuItems(options) {
|
|
159
|
-
return this.implement("hideMenuItems", options);
|
|
160
|
-
}
|
|
161
|
-
hideOptionMenu() {
|
|
162
|
-
return this.implement("hideOptionMenu");
|
|
163
|
-
}
|
|
164
|
-
onMenuShareAppMessage(options) {
|
|
165
|
-
return this.implement("onMenuShareAppMessage", options);
|
|
166
|
-
}
|
|
167
|
-
onMenuShareQQ(options) {
|
|
168
|
-
return this.implement("onMenuShareQQ", options);
|
|
169
|
-
}
|
|
170
|
-
onMenuShareQZone(options) {
|
|
171
|
-
return this.implement("onMenuShareQZone", options);
|
|
172
|
-
}
|
|
173
|
-
onMenuShareTimeline(options) {
|
|
174
|
-
return this.implement("onMenuShareTimeline", options);
|
|
175
|
-
}
|
|
176
|
-
onMenuShareWeibo(options) {
|
|
177
|
-
return this.implement("onMenuShareWeibo", options);
|
|
178
|
-
}
|
|
179
|
-
onSearchBeacons(options) {
|
|
180
|
-
return this.implement("onSearchBeacons", options);
|
|
181
|
-
}
|
|
182
|
-
onVoicePlayEnd(options) {
|
|
183
|
-
return this.implement("onVoicePlayEnd", options);
|
|
184
|
-
}
|
|
185
|
-
onVoiceRecordEnd(options) {
|
|
186
|
-
return this.implement("onVoiceRecordEnd", options);
|
|
187
|
-
}
|
|
188
|
-
openCard(options) {
|
|
189
|
-
return this.implement("openCard", options);
|
|
190
|
-
}
|
|
191
|
-
openLocation(options) {
|
|
192
|
-
return this.implement("openLocation", options);
|
|
193
|
-
}
|
|
194
|
-
openProductSpecificView(options) {
|
|
195
|
-
return this.implement("openProductSpecificView", options);
|
|
196
|
-
}
|
|
197
|
-
pauseVoice(options) {
|
|
198
|
-
return this.implement("pauseVoice", options);
|
|
199
|
-
}
|
|
200
|
-
playVoice(options) {
|
|
201
|
-
return this.implement("playVoice", options);
|
|
202
|
-
}
|
|
203
|
-
previewImage(options) {
|
|
204
|
-
return this.implement("previewImage", options);
|
|
205
|
-
}
|
|
206
|
-
scanQRCode(options) {
|
|
207
|
-
return this.implement("scanQRCode", options);
|
|
208
|
-
}
|
|
209
|
-
showAllNonBaseMenuItem() {
|
|
210
|
-
return this.implement("showAllNonBaseMenuItem");
|
|
211
|
-
}
|
|
212
|
-
showMenuItems(options) {
|
|
213
|
-
return this.implement("showMenuItems", options);
|
|
214
|
-
}
|
|
215
|
-
showOptionMenu() {
|
|
216
|
-
return this.implement("showOptionMenu");
|
|
217
|
-
}
|
|
218
|
-
startRecord() {
|
|
219
|
-
return this.implement("startRecord");
|
|
220
|
-
}
|
|
221
|
-
startSearchBeacons(options) {
|
|
222
|
-
return this.implement("startSearchBeacons", options);
|
|
223
|
-
}
|
|
224
|
-
stopRecord(options) {
|
|
225
|
-
return this.implement("stopRecord", options);
|
|
226
|
-
}
|
|
227
|
-
stopSearchBeacons(options) {
|
|
228
|
-
return this.implement("stopSearchBeacons", options);
|
|
229
|
-
}
|
|
230
|
-
stopVoice(options) {
|
|
231
|
-
return this.implement("stopVoice", options);
|
|
232
|
-
}
|
|
233
|
-
translateVoice(options) {
|
|
234
|
-
return this.implement("translateVoice", options);
|
|
235
|
-
}
|
|
236
|
-
uploadImage(options) {
|
|
237
|
-
return this.implement("uploadImage", options);
|
|
238
|
-
}
|
|
239
|
-
uploadVoice(options) {
|
|
240
|
-
return this.implement("uploadVoice", options);
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
export {
|
|
244
|
-
WechatJssdk
|
|
245
|
-
};
|