@dcloudio/uni-mp-xhs 2.0.1-34620220419001

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/dist/index.js ADDED
@@ -0,0 +1,2179 @@
1
+ import Vue from 'vue';
2
+ import { initVueI18n } from '@dcloudio/uni-i18n';
3
+
4
+ let realAtob;
5
+
6
+ const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
7
+ const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;
8
+
9
+ if (typeof atob !== 'function') {
10
+ realAtob = function (str) {
11
+ str = String(str).replace(/[\t\n\f\r ]+/g, '');
12
+ if (!b64re.test(str)) { throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.") }
13
+
14
+ // Adding the padding if missing, for semplicity
15
+ str += '=='.slice(2 - (str.length & 3));
16
+ var bitmap; var result = ''; var r1; var r2; var i = 0;
17
+ for (; i < str.length;) {
18
+ bitmap = b64.indexOf(str.charAt(i++)) << 18 | b64.indexOf(str.charAt(i++)) << 12 |
19
+ (r1 = b64.indexOf(str.charAt(i++))) << 6 | (r2 = b64.indexOf(str.charAt(i++)));
20
+
21
+ result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255)
22
+ : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255)
23
+ : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255);
24
+ }
25
+ return result
26
+ };
27
+ } else {
28
+ // 注意atob只能在全局对象上调用,例如:`const Base64 = {atob};Base64.atob('xxxx')`是错误的用法
29
+ realAtob = atob;
30
+ }
31
+
32
+ function b64DecodeUnicode (str) {
33
+ return decodeURIComponent(realAtob(str).split('').map(function (c) {
34
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
35
+ }).join(''))
36
+ }
37
+
38
+ function getCurrentUserInfo () {
39
+ const token = ( xhs).getStorageSync('uni_id_token') || '';
40
+ const tokenArr = token.split('.');
41
+ if (!token || tokenArr.length !== 3) {
42
+ return {
43
+ uid: null,
44
+ role: [],
45
+ permission: [],
46
+ tokenExpired: 0
47
+ }
48
+ }
49
+ let userInfo;
50
+ try {
51
+ userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1]));
52
+ } catch (error) {
53
+ throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message)
54
+ }
55
+ userInfo.tokenExpired = userInfo.exp * 1000;
56
+ delete userInfo.exp;
57
+ delete userInfo.iat;
58
+ return userInfo
59
+ }
60
+
61
+ function uniIdMixin (Vue) {
62
+ Vue.prototype.uniIDHasRole = function (roleId) {
63
+ const {
64
+ role
65
+ } = getCurrentUserInfo();
66
+ return role.indexOf(roleId) > -1
67
+ };
68
+ Vue.prototype.uniIDHasPermission = function (permissionId) {
69
+ const {
70
+ permission
71
+ } = getCurrentUserInfo();
72
+ return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1
73
+ };
74
+ Vue.prototype.uniIDTokenValid = function () {
75
+ const {
76
+ tokenExpired
77
+ } = getCurrentUserInfo();
78
+ return tokenExpired > Date.now()
79
+ };
80
+ }
81
+
82
+ const _toString = Object.prototype.toString;
83
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
84
+
85
+ function isFn (fn) {
86
+ return typeof fn === 'function'
87
+ }
88
+
89
+ function isStr (str) {
90
+ return typeof str === 'string'
91
+ }
92
+
93
+ function isPlainObject (obj) {
94
+ return _toString.call(obj) === '[object Object]'
95
+ }
96
+
97
+ function hasOwn (obj, key) {
98
+ return hasOwnProperty.call(obj, key)
99
+ }
100
+
101
+ function noop () {}
102
+
103
+ /**
104
+ * Create a cached version of a pure function.
105
+ */
106
+ function cached (fn) {
107
+ const cache = Object.create(null);
108
+ return function cachedFn (str) {
109
+ const hit = cache[str];
110
+ return hit || (cache[str] = fn(str))
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Camelize a hyphen-delimited string.
116
+ */
117
+ const camelizeRE = /-(\w)/g;
118
+ const camelize = cached((str) => {
119
+ return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
120
+ });
121
+
122
+ const HOOKS = [
123
+ 'invoke',
124
+ 'success',
125
+ 'fail',
126
+ 'complete',
127
+ 'returnValue'
128
+ ];
129
+
130
+ const globalInterceptors = {};
131
+ const scopedInterceptors = {};
132
+
133
+ function mergeHook (parentVal, childVal) {
134
+ const res = childVal
135
+ ? parentVal
136
+ ? parentVal.concat(childVal)
137
+ : Array.isArray(childVal)
138
+ ? childVal : [childVal]
139
+ : parentVal;
140
+ return res
141
+ ? dedupeHooks(res)
142
+ : res
143
+ }
144
+
145
+ function dedupeHooks (hooks) {
146
+ const res = [];
147
+ for (let i = 0; i < hooks.length; i++) {
148
+ if (res.indexOf(hooks[i]) === -1) {
149
+ res.push(hooks[i]);
150
+ }
151
+ }
152
+ return res
153
+ }
154
+
155
+ function removeHook (hooks, hook) {
156
+ const index = hooks.indexOf(hook);
157
+ if (index !== -1) {
158
+ hooks.splice(index, 1);
159
+ }
160
+ }
161
+
162
+ function mergeInterceptorHook (interceptor, option) {
163
+ Object.keys(option).forEach(hook => {
164
+ if (HOOKS.indexOf(hook) !== -1 && isFn(option[hook])) {
165
+ interceptor[hook] = mergeHook(interceptor[hook], option[hook]);
166
+ }
167
+ });
168
+ }
169
+
170
+ function removeInterceptorHook (interceptor, option) {
171
+ if (!interceptor || !option) {
172
+ return
173
+ }
174
+ Object.keys(option).forEach(hook => {
175
+ if (HOOKS.indexOf(hook) !== -1 && isFn(option[hook])) {
176
+ removeHook(interceptor[hook], option[hook]);
177
+ }
178
+ });
179
+ }
180
+
181
+ function addInterceptor (method, option) {
182
+ if (typeof method === 'string' && isPlainObject(option)) {
183
+ mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), option);
184
+ } else if (isPlainObject(method)) {
185
+ mergeInterceptorHook(globalInterceptors, method);
186
+ }
187
+ }
188
+
189
+ function removeInterceptor (method, option) {
190
+ if (typeof method === 'string') {
191
+ if (isPlainObject(option)) {
192
+ removeInterceptorHook(scopedInterceptors[method], option);
193
+ } else {
194
+ delete scopedInterceptors[method];
195
+ }
196
+ } else if (isPlainObject(method)) {
197
+ removeInterceptorHook(globalInterceptors, method);
198
+ }
199
+ }
200
+
201
+ function wrapperHook (hook) {
202
+ return function (data) {
203
+ return hook(data) || data
204
+ }
205
+ }
206
+
207
+ function isPromise (obj) {
208
+ return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
209
+ }
210
+
211
+ function queue (hooks, data) {
212
+ let promise = false;
213
+ for (let i = 0; i < hooks.length; i++) {
214
+ const hook = hooks[i];
215
+ if (promise) {
216
+ promise = Promise.resolve(wrapperHook(hook));
217
+ } else {
218
+ const res = hook(data);
219
+ if (isPromise(res)) {
220
+ promise = Promise.resolve(res);
221
+ }
222
+ if (res === false) {
223
+ return {
224
+ then () { }
225
+ }
226
+ }
227
+ }
228
+ }
229
+ return promise || {
230
+ then (callback) {
231
+ return callback(data)
232
+ }
233
+ }
234
+ }
235
+
236
+ function wrapperOptions (interceptor, options = {}) {
237
+ ['success', 'fail', 'complete'].forEach(name => {
238
+ if (Array.isArray(interceptor[name])) {
239
+ const oldCallback = options[name];
240
+ options[name] = function callbackInterceptor (res) {
241
+ queue(interceptor[name], res).then((res) => {
242
+ /* eslint-disable no-mixed-operators */
243
+ return isFn(oldCallback) && oldCallback(res) || res
244
+ });
245
+ };
246
+ }
247
+ });
248
+ return options
249
+ }
250
+
251
+ function wrapperReturnValue (method, returnValue) {
252
+ const returnValueHooks = [];
253
+ if (Array.isArray(globalInterceptors.returnValue)) {
254
+ returnValueHooks.push(...globalInterceptors.returnValue);
255
+ }
256
+ const interceptor = scopedInterceptors[method];
257
+ if (interceptor && Array.isArray(interceptor.returnValue)) {
258
+ returnValueHooks.push(...interceptor.returnValue);
259
+ }
260
+ returnValueHooks.forEach(hook => {
261
+ returnValue = hook(returnValue) || returnValue;
262
+ });
263
+ return returnValue
264
+ }
265
+
266
+ function getApiInterceptorHooks (method) {
267
+ const interceptor = Object.create(null);
268
+ Object.keys(globalInterceptors).forEach(hook => {
269
+ if (hook !== 'returnValue') {
270
+ interceptor[hook] = globalInterceptors[hook].slice();
271
+ }
272
+ });
273
+ const scopedInterceptor = scopedInterceptors[method];
274
+ if (scopedInterceptor) {
275
+ Object.keys(scopedInterceptor).forEach(hook => {
276
+ if (hook !== 'returnValue') {
277
+ interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]);
278
+ }
279
+ });
280
+ }
281
+ return interceptor
282
+ }
283
+
284
+ function invokeApi (method, api, options, ...params) {
285
+ const interceptor = getApiInterceptorHooks(method);
286
+ if (interceptor && Object.keys(interceptor).length) {
287
+ if (Array.isArray(interceptor.invoke)) {
288
+ const res = queue(interceptor.invoke, options);
289
+ return res.then((options) => {
290
+ return api(wrapperOptions(interceptor, options), ...params)
291
+ })
292
+ } else {
293
+ return api(wrapperOptions(interceptor, options), ...params)
294
+ }
295
+ }
296
+ return api(options, ...params)
297
+ }
298
+
299
+ const promiseInterceptor = {
300
+ returnValue (res) {
301
+ if (!isPromise(res)) {
302
+ return res
303
+ }
304
+ return new Promise((resolve, reject) => {
305
+ res.then(res => {
306
+ if (res[0]) {
307
+ reject(res[0]);
308
+ } else {
309
+ resolve(res[1]);
310
+ }
311
+ });
312
+ })
313
+ }
314
+ };
315
+
316
+ const SYNC_API_RE =
317
+ /^\$|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/;
318
+
319
+ const CONTEXT_API_RE = /^create|Manager$/;
320
+
321
+ // Context例外情况
322
+ const CONTEXT_API_RE_EXC = ['createBLEConnection'];
323
+
324
+ // 同步例外情况
325
+ const ASYNC_API = ['createBLEConnection'];
326
+
327
+ const CALLBACK_API_RE = /^on|^off/;
328
+
329
+ function isContextApi (name) {
330
+ return CONTEXT_API_RE.test(name) && CONTEXT_API_RE_EXC.indexOf(name) === -1
331
+ }
332
+ function isSyncApi (name) {
333
+ return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1
334
+ }
335
+
336
+ function isCallbackApi (name) {
337
+ return CALLBACK_API_RE.test(name) && name !== 'onPush'
338
+ }
339
+
340
+ function handlePromise (promise) {
341
+ return promise.then(data => {
342
+ return [null, data]
343
+ })
344
+ .catch(err => [err])
345
+ }
346
+
347
+ function shouldPromise (name) {
348
+ if (
349
+ isContextApi(name) ||
350
+ isSyncApi(name) ||
351
+ isCallbackApi(name)
352
+ ) {
353
+ return false
354
+ }
355
+ return true
356
+ }
357
+
358
+ /* eslint-disable no-extend-native */
359
+ if (!Promise.prototype.finally) {
360
+ Promise.prototype.finally = function (callback) {
361
+ const promise = this.constructor;
362
+ return this.then(
363
+ value => promise.resolve(callback()).then(() => value),
364
+ reason => promise.resolve(callback()).then(() => {
365
+ throw reason
366
+ })
367
+ )
368
+ };
369
+ }
370
+
371
+ function promisify (name, api) {
372
+ if (!shouldPromise(name)) {
373
+ return api
374
+ }
375
+ return function promiseApi (options = {}, ...params) {
376
+ if (isFn(options.success) || isFn(options.fail) || isFn(options.complete)) {
377
+ return wrapperReturnValue(name, invokeApi(name, api, options, ...params))
378
+ }
379
+ return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
380
+ invokeApi(name, api, Object.assign({}, options, {
381
+ success: resolve,
382
+ fail: reject
383
+ }), ...params);
384
+ })))
385
+ }
386
+ }
387
+
388
+ const EPS = 1e-4;
389
+ const BASE_DEVICE_WIDTH = 750;
390
+ let isIOS = false;
391
+ let deviceWidth = 0;
392
+ let deviceDPR = 0;
393
+
394
+ function checkDeviceWidth () {
395
+ const {
396
+ platform,
397
+ pixelRatio,
398
+ windowWidth
399
+ } = xhs.getSystemInfoSync(); // uni=>xhs runtime 编译目标是 uni 对象,内部不允许直接使用 uni
400
+
401
+ deviceWidth = windowWidth;
402
+ deviceDPR = pixelRatio;
403
+ isIOS = platform === 'ios';
404
+ }
405
+
406
+ function upx2px (number, newDeviceWidth) {
407
+ if (deviceWidth === 0) {
408
+ checkDeviceWidth();
409
+ }
410
+
411
+ number = Number(number);
412
+ if (number === 0) {
413
+ return 0
414
+ }
415
+ let result = (number / BASE_DEVICE_WIDTH) * (newDeviceWidth || deviceWidth);
416
+ if (result < 0) {
417
+ result = -result;
418
+ }
419
+ result = Math.floor(result + EPS);
420
+ if (result === 0) {
421
+ if (deviceDPR === 1 || !isIOS) {
422
+ result = 1;
423
+ } else {
424
+ result = 0.5;
425
+ }
426
+ }
427
+ return number < 0 ? -result : result
428
+ }
429
+
430
+ function getLocale () {
431
+ // 优先使用 $locale
432
+ const app = getApp({
433
+ allowDefault: true
434
+ });
435
+ if (app && app.$vm) {
436
+ return app.$vm.$locale
437
+ }
438
+ return xhs.getSystemInfoSync().language || 'zh-Hans'
439
+ }
440
+
441
+ function setLocale (locale) {
442
+ const app = getApp();
443
+ if (!app) {
444
+ return false
445
+ }
446
+ const oldLocale = app.$vm.$locale;
447
+ if (oldLocale !== locale) {
448
+ app.$vm.$locale = locale;
449
+ onLocaleChangeCallbacks.forEach((fn) => fn({
450
+ locale
451
+ }));
452
+ return true
453
+ }
454
+ return false
455
+ }
456
+
457
+ const onLocaleChangeCallbacks = [];
458
+ function onLocaleChange (fn) {
459
+ if (onLocaleChangeCallbacks.indexOf(fn) === -1) {
460
+ onLocaleChangeCallbacks.push(fn);
461
+ }
462
+ }
463
+
464
+ if (typeof global !== 'undefined') {
465
+ global.getLocale = getLocale;
466
+ }
467
+
468
+ const interceptors = {
469
+ promiseInterceptor
470
+ };
471
+
472
+ var baseApi = /*#__PURE__*/Object.freeze({
473
+ __proto__: null,
474
+ upx2px: upx2px,
475
+ getLocale: getLocale,
476
+ setLocale: setLocale,
477
+ onLocaleChange: onLocaleChange,
478
+ addInterceptor: addInterceptor,
479
+ removeInterceptor: removeInterceptor,
480
+ interceptors: interceptors
481
+ });
482
+
483
+ // import navigateTo from 'uni-helpers/navigate-to'
484
+ // import redirectTo from '../../../mp-weixin/helpers/redirect-to'
485
+ // import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
486
+ // import getSystemInfo from '../../../mp-weixin/helpers/system-info'
487
+ // import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
488
+
489
+ // 需要做转换的 API 列表
490
+ const protocols = {
491
+ // navigateTo,
492
+ // redirectTo,
493
+ // previewImage,
494
+ // getSystemInfo,
495
+ // getSystemInfoSync: getSystemInfo,
496
+ // getUserProfile
497
+ };
498
+
499
+ // 不支持的 API 列表
500
+ // TODO: 补充
501
+ const todos = [
502
+ 'getSelectedTextRange'
503
+ ];
504
+
505
+ // 存在兼容性的 API 列表
506
+ const canIUses = [];
507
+
508
+ const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
509
+
510
+ function processCallback (methodName, method, returnValue) {
511
+ return function (res) {
512
+ return method(processReturnValue(methodName, res, returnValue))
513
+ }
514
+ }
515
+
516
+ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
517
+ if (isPlainObject(fromArgs)) { // 一般 api 的参数解析
518
+ const toArgs = keepFromArgs === true ? fromArgs : {}; // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
519
+ if (isFn(argsOption)) {
520
+ argsOption = argsOption(fromArgs, toArgs) || {};
521
+ }
522
+ for (const key in fromArgs) {
523
+ if (hasOwn(argsOption, key)) {
524
+ let keyOption = argsOption[key];
525
+ if (isFn(keyOption)) {
526
+ keyOption = keyOption(fromArgs[key], fromArgs, toArgs);
527
+ }
528
+ if (!keyOption) { // 不支持的参数
529
+ console.warn(`The '${methodName}' method of platform '小红书小程序' does not support option '${key}'`);
530
+ } else if (isStr(keyOption)) { // 重写参数 key
531
+ toArgs[keyOption] = fromArgs[key];
532
+ } else if (isPlainObject(keyOption)) { // {name:newName,value:value}可重新指定参数 key:value
533
+ toArgs[keyOption.name ? keyOption.name : key] = keyOption.value;
534
+ }
535
+ } else if (CALLBACKS.indexOf(key) !== -1) {
536
+ if (isFn(fromArgs[key])) {
537
+ toArgs[key] = processCallback(methodName, fromArgs[key], returnValue);
538
+ }
539
+ } else {
540
+ if (!keepFromArgs) {
541
+ toArgs[key] = fromArgs[key];
542
+ }
543
+ }
544
+ }
545
+ return toArgs
546
+ } else if (isFn(fromArgs)) {
547
+ fromArgs = processCallback(methodName, fromArgs, returnValue);
548
+ }
549
+ return fromArgs
550
+ }
551
+
552
+ function processReturnValue (methodName, res, returnValue, keepReturnValue = false) {
553
+ if (isFn(protocols.returnValue)) { // 处理通用 returnValue
554
+ res = protocols.returnValue(methodName, res);
555
+ }
556
+ return processArgs(methodName, res, returnValue, {}, keepReturnValue)
557
+ }
558
+
559
+ function wrapper (methodName, method) {
560
+ if (hasOwn(protocols, methodName)) {
561
+ const protocol = protocols[methodName];
562
+ if (!protocol) { // 暂不支持的 api
563
+ return function () {
564
+ console.error(`Platform '小红书小程序' does not support '${methodName}'.`);
565
+ }
566
+ }
567
+ return function (arg1, arg2) { // 目前 api 最多两个参数
568
+ let options = protocol;
569
+ if (isFn(protocol)) {
570
+ options = protocol(arg1);
571
+ }
572
+
573
+ arg1 = processArgs(methodName, arg1, options.args, options.returnValue);
574
+
575
+ const args = [arg1];
576
+ if (typeof arg2 !== 'undefined') {
577
+ args.push(arg2);
578
+ }
579
+ if (isFn(options.name)) {
580
+ methodName = options.name(arg1);
581
+ } else if (isStr(options.name)) {
582
+ methodName = options.name;
583
+ }
584
+ const returnValue = xhs[methodName].apply(xhs, args);
585
+ if (isSyncApi(methodName)) { // 同步 api
586
+ return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
587
+ }
588
+ return returnValue
589
+ }
590
+ }
591
+ return method
592
+ }
593
+
594
+ const todoApis = Object.create(null);
595
+
596
+ const TODOS = [
597
+ 'onTabBarMidButtonTap',
598
+ 'subscribePush',
599
+ 'unsubscribePush',
600
+ 'onPush',
601
+ 'offPush',
602
+ 'share'
603
+ ];
604
+
605
+ function createTodoApi (name) {
606
+ return function todoApi ({
607
+ fail,
608
+ complete
609
+ }) {
610
+ const res = {
611
+ errMsg: `${name}:fail method '${name}' not supported`
612
+ };
613
+ isFn(fail) && fail(res);
614
+ isFn(complete) && complete(res);
615
+ }
616
+ }
617
+
618
+ TODOS.forEach(function (name) {
619
+ todoApis[name] = createTodoApi(name);
620
+ });
621
+
622
+ var providers = {
623
+ oauth: ['xhs'],
624
+ share: ['xhs'],
625
+ payment: ['xhs'],
626
+ push: ['xhs']
627
+ };
628
+
629
+ function getProvider ({
630
+ service,
631
+ success,
632
+ fail,
633
+ complete
634
+ }) {
635
+ let res = false;
636
+ if (providers[service]) {
637
+ res = {
638
+ errMsg: 'getProvider:ok',
639
+ service,
640
+ provider: providers[service]
641
+ };
642
+ isFn(success) && success(res);
643
+ } else {
644
+ res = {
645
+ errMsg: 'getProvider:fail service not found'
646
+ };
647
+ isFn(fail) && fail(res);
648
+ }
649
+ isFn(complete) && complete(res);
650
+ }
651
+
652
+ var extraApi = /*#__PURE__*/Object.freeze({
653
+ __proto__: null,
654
+ getProvider: getProvider
655
+ });
656
+
657
+ const getEmitter = (function () {
658
+ let Emitter;
659
+ return function getUniEmitter () {
660
+ if (!Emitter) {
661
+ Emitter = new Vue();
662
+ }
663
+ return Emitter
664
+ }
665
+ })();
666
+
667
+ function apply (ctx, method, args) {
668
+ return ctx[method].apply(ctx, args)
669
+ }
670
+
671
+ function $on () {
672
+ return apply(getEmitter(), '$on', [...arguments])
673
+ }
674
+ function $off () {
675
+ return apply(getEmitter(), '$off', [...arguments])
676
+ }
677
+ function $once () {
678
+ return apply(getEmitter(), '$once', [...arguments])
679
+ }
680
+ function $emit () {
681
+ return apply(getEmitter(), '$emit', [...arguments])
682
+ }
683
+
684
+ var eventApi = /*#__PURE__*/Object.freeze({
685
+ __proto__: null,
686
+ $on: $on,
687
+ $off: $off,
688
+ $once: $once,
689
+ $emit: $emit
690
+ });
691
+
692
+ var api = /*#__PURE__*/Object.freeze({
693
+ __proto__: null
694
+ });
695
+
696
+ const MPPage = Page;
697
+ const MPComponent = Component;
698
+
699
+ const customizeRE = /:/g;
700
+
701
+ const customize = cached((str) => {
702
+ return camelize(str.replace(customizeRE, '-'))
703
+ });
704
+
705
+ function initTriggerEvent (mpInstance) {
706
+ const oldTriggerEvent = mpInstance.triggerEvent;
707
+ const newTriggerEvent = function (event, ...args) {
708
+ return oldTriggerEvent.apply(mpInstance, [customize(event), ...args])
709
+ };
710
+ try {
711
+ // 京东小程序 triggerEvent 为只读
712
+ mpInstance.triggerEvent = newTriggerEvent;
713
+ } catch (error) {
714
+ mpInstance._triggerEvent = newTriggerEvent;
715
+ }
716
+ }
717
+
718
+ function initHook (name, options, isComponent) {
719
+ const oldHook = options[name];
720
+ if (!oldHook) {
721
+ options[name] = function () {
722
+ initTriggerEvent(this);
723
+ };
724
+ } else {
725
+ options[name] = function (...args) {
726
+ initTriggerEvent(this);
727
+ return oldHook.apply(this, args)
728
+ };
729
+ }
730
+ }
731
+ if (!MPPage.__$wrappered) {
732
+ MPPage.__$wrappered = true;
733
+ Page = function (options = {}) {
734
+ initHook('onLoad', options);
735
+ return MPPage(options)
736
+ };
737
+ Page.after = MPPage.after;
738
+
739
+ Component = function (options = {}) {
740
+ initHook('created', options);
741
+ return MPComponent(options)
742
+ };
743
+ }
744
+
745
+ const PAGE_EVENT_HOOKS = [
746
+ 'onPullDownRefresh',
747
+ 'onReachBottom',
748
+ 'onAddToFavorites',
749
+ 'onShareTimeline',
750
+ 'onShareAppMessage',
751
+ 'onPageScroll',
752
+ 'onResize',
753
+ 'onTabItemTap'
754
+ ];
755
+
756
+ function initMocks (vm, mocks) {
757
+ const mpInstance = vm.$mp[vm.mpType];
758
+ mocks.forEach(mock => {
759
+ if (hasOwn(mpInstance, mock)) {
760
+ vm[mock] = mpInstance[mock];
761
+ }
762
+ });
763
+ }
764
+
765
+ function hasHook (hook, vueOptions) {
766
+ if (!vueOptions) {
767
+ return true
768
+ }
769
+
770
+ if (Vue.options && Array.isArray(Vue.options[hook])) {
771
+ return true
772
+ }
773
+
774
+ vueOptions = vueOptions.default || vueOptions;
775
+
776
+ if (isFn(vueOptions)) {
777
+ if (isFn(vueOptions.extendOptions[hook])) {
778
+ return true
779
+ }
780
+ if (vueOptions.super &&
781
+ vueOptions.super.options &&
782
+ Array.isArray(vueOptions.super.options[hook])) {
783
+ return true
784
+ }
785
+ return false
786
+ }
787
+
788
+ if (isFn(vueOptions[hook])) {
789
+ return true
790
+ }
791
+ const mixins = vueOptions.mixins;
792
+ if (Array.isArray(mixins)) {
793
+ return !!mixins.find(mixin => hasHook(hook, mixin))
794
+ }
795
+ }
796
+
797
+ function initHooks (mpOptions, hooks, vueOptions) {
798
+ hooks.forEach(hook => {
799
+ if (hasHook(hook, vueOptions)) {
800
+ mpOptions[hook] = function (args) {
801
+ return this.$vm && this.$vm.__call_hook(hook, args)
802
+ };
803
+ }
804
+ });
805
+ }
806
+
807
+ function initVueComponent (Vue, vueOptions) {
808
+ vueOptions = vueOptions.default || vueOptions;
809
+ let VueComponent;
810
+ if (isFn(vueOptions)) {
811
+ VueComponent = vueOptions;
812
+ } else {
813
+ VueComponent = Vue.extend(vueOptions);
814
+ }
815
+ vueOptions = VueComponent.options;
816
+ return [VueComponent, vueOptions]
817
+ }
818
+
819
+ function initSlots (vm, vueSlots) {
820
+ if (Array.isArray(vueSlots) && vueSlots.length) {
821
+ const $slots = Object.create(null);
822
+ vueSlots.forEach(slotName => {
823
+ $slots[slotName] = true;
824
+ });
825
+ vm.$scopedSlots = vm.$slots = $slots;
826
+ }
827
+ }
828
+
829
+ function initVueIds (vueIds, mpInstance) {
830
+ vueIds = (vueIds || '').split(',');
831
+ const len = vueIds.length;
832
+
833
+ if (len === 1) {
834
+ mpInstance._$vueId = vueIds[0];
835
+ } else if (len === 2) {
836
+ mpInstance._$vueId = vueIds[0];
837
+ mpInstance._$vuePid = vueIds[1];
838
+ }
839
+ }
840
+
841
+ function initData (vueOptions, context) {
842
+ let data = vueOptions.data || {};
843
+ const methods = vueOptions.methods || {};
844
+
845
+ if (typeof data === 'function') {
846
+ try {
847
+ data = data.call(context); // 支持 Vue.prototype 上挂的数据
848
+ } catch (e) {
849
+ if (process.env.VUE_APP_DEBUG) {
850
+ console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data);
851
+ }
852
+ }
853
+ } else {
854
+ try {
855
+ // 对 data 格式化
856
+ data = JSON.parse(JSON.stringify(data));
857
+ } catch (e) {}
858
+ }
859
+
860
+ if (!isPlainObject(data)) {
861
+ data = {};
862
+ }
863
+
864
+ Object.keys(methods).forEach(methodName => {
865
+ if (context.__lifecycle_hooks__.indexOf(methodName) === -1 && !hasOwn(data, methodName)) {
866
+ data[methodName] = methods[methodName];
867
+ }
868
+ });
869
+
870
+ return data
871
+ }
872
+
873
+ const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
874
+
875
+ function createObserver (name) {
876
+ return function observer (newVal, oldVal) {
877
+ if (this.$vm) {
878
+ this.$vm[name] = newVal; // 为了触发其他非 render watcher
879
+ }
880
+ }
881
+ }
882
+
883
+ function initBehaviors (vueOptions, initBehavior) {
884
+ const vueBehaviors = vueOptions.behaviors;
885
+ const vueExtends = vueOptions.extends;
886
+ const vueMixins = vueOptions.mixins;
887
+
888
+ let vueProps = vueOptions.props;
889
+
890
+ if (!vueProps) {
891
+ vueOptions.props = vueProps = [];
892
+ }
893
+
894
+ const behaviors = [];
895
+ if (Array.isArray(vueBehaviors)) {
896
+ vueBehaviors.forEach(behavior => {
897
+ behaviors.push(behavior.replace('uni://', `${"xhs"}://`));
898
+ if (behavior === 'uni://form-field') {
899
+ if (Array.isArray(vueProps)) {
900
+ vueProps.push('name');
901
+ vueProps.push('value');
902
+ } else {
903
+ vueProps.name = {
904
+ type: String,
905
+ default: ''
906
+ };
907
+ vueProps.value = {
908
+ type: [String, Number, Boolean, Array, Object, Date],
909
+ default: ''
910
+ };
911
+ }
912
+ }
913
+ });
914
+ }
915
+ if (isPlainObject(vueExtends) && vueExtends.props) {
916
+ behaviors.push(
917
+ initBehavior({
918
+ properties: initProperties(vueExtends.props, true)
919
+ })
920
+ );
921
+ }
922
+ if (Array.isArray(vueMixins)) {
923
+ vueMixins.forEach(vueMixin => {
924
+ if (isPlainObject(vueMixin) && vueMixin.props) {
925
+ behaviors.push(
926
+ initBehavior({
927
+ properties: initProperties(vueMixin.props, true)
928
+ })
929
+ );
930
+ }
931
+ });
932
+ }
933
+ return behaviors
934
+ }
935
+
936
+ function parsePropType (key, type, defaultValue, file) {
937
+ // [String]=>String
938
+ if (Array.isArray(type) && type.length === 1) {
939
+ return type[0]
940
+ }
941
+ return type
942
+ }
943
+
944
+ function initProperties (props, isBehavior = false, file = '') {
945
+ const properties = {};
946
+ if (!isBehavior) {
947
+ properties.vueId = {
948
+ type: String,
949
+ value: ''
950
+ };
951
+ // 用于字节跳动小程序模拟抽象节点
952
+ properties.generic = {
953
+ type: Object,
954
+ value: null
955
+ };
956
+ // scopedSlotsCompiler auto
957
+ properties.scopedSlotsCompiler = {
958
+ type: String,
959
+ value: ''
960
+ };
961
+ properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
962
+ type: null,
963
+ value: [],
964
+ observer: function (newVal, oldVal) {
965
+ const $slots = Object.create(null);
966
+ newVal.forEach(slotName => {
967
+ $slots[slotName] = true;
968
+ });
969
+ this.setData({
970
+ $slots
971
+ });
972
+ }
973
+ };
974
+ }
975
+ if (Array.isArray(props)) { // ['title']
976
+ props.forEach(key => {
977
+ properties[key] = {
978
+ type: null,
979
+ observer: createObserver(key)
980
+ };
981
+ });
982
+ } else if (isPlainObject(props)) { // {title:{type:String,default:''},content:String}
983
+ Object.keys(props).forEach(key => {
984
+ const opts = props[key];
985
+ if (isPlainObject(opts)) { // title:{type:String,default:''}
986
+ let value = opts.default;
987
+ if (isFn(value)) {
988
+ value = value();
989
+ }
990
+
991
+ opts.type = parsePropType(key, opts.type);
992
+
993
+ properties[key] = {
994
+ type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
995
+ value,
996
+ observer: createObserver(key)
997
+ };
998
+ } else { // content:String
999
+ const type = parsePropType(key, opts);
1000
+ properties[key] = {
1001
+ type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
1002
+ observer: createObserver(key)
1003
+ };
1004
+ }
1005
+ });
1006
+ }
1007
+ return properties
1008
+ }
1009
+
1010
+ function wrapper$1 (event) {
1011
+ // TODO 又得兼容 mpvue 的 mp 对象
1012
+ try {
1013
+ event.mp = JSON.parse(JSON.stringify(event));
1014
+ } catch (e) {}
1015
+
1016
+ event.stopPropagation = noop;
1017
+ event.preventDefault = noop;
1018
+
1019
+ event.target = event.target || {};
1020
+
1021
+ if (!hasOwn(event, 'detail')) {
1022
+ event.detail = {};
1023
+ }
1024
+
1025
+ if (hasOwn(event, 'markerId')) {
1026
+ event.detail = typeof event.detail === 'object' ? event.detail : {};
1027
+ event.detail.markerId = event.markerId;
1028
+ }
1029
+
1030
+ if (isPlainObject(event.detail)) {
1031
+ event.target = Object.assign({}, event.target, event.detail);
1032
+ }
1033
+
1034
+ return event
1035
+ }
1036
+
1037
+ function getExtraValue (vm, dataPathsArray) {
1038
+ let context = vm;
1039
+ dataPathsArray.forEach(dataPathArray => {
1040
+ const dataPath = dataPathArray[0];
1041
+ const value = dataPathArray[2];
1042
+ if (dataPath || typeof value !== 'undefined') { // ['','',index,'disable']
1043
+ const propPath = dataPathArray[1];
1044
+ const valuePath = dataPathArray[3];
1045
+
1046
+ let vFor;
1047
+ if (Number.isInteger(dataPath)) {
1048
+ vFor = dataPath;
1049
+ } else if (!dataPath) {
1050
+ vFor = context;
1051
+ } else if (typeof dataPath === 'string' && dataPath) {
1052
+ if (dataPath.indexOf('#s#') === 0) {
1053
+ vFor = dataPath.substr(3);
1054
+ } else {
1055
+ vFor = vm.__get_value(dataPath, context);
1056
+ }
1057
+ }
1058
+
1059
+ if (Number.isInteger(vFor)) {
1060
+ context = value;
1061
+ } else if (!propPath) {
1062
+ context = vFor[value];
1063
+ } else {
1064
+ if (Array.isArray(vFor)) {
1065
+ context = vFor.find(vForItem => {
1066
+ return vm.__get_value(propPath, vForItem) === value
1067
+ });
1068
+ } else if (isPlainObject(vFor)) {
1069
+ context = Object.keys(vFor).find(vForKey => {
1070
+ return vm.__get_value(propPath, vFor[vForKey]) === value
1071
+ });
1072
+ } else {
1073
+ console.error('v-for 暂不支持循环数据:', vFor);
1074
+ }
1075
+ }
1076
+
1077
+ if (valuePath) {
1078
+ context = vm.__get_value(valuePath, context);
1079
+ }
1080
+ }
1081
+ });
1082
+ return context
1083
+ }
1084
+
1085
+ function processEventExtra (vm, extra, event) {
1086
+ const extraObj = {};
1087
+
1088
+ if (Array.isArray(extra) && extra.length) {
1089
+ /**
1090
+ *[
1091
+ * ['data.items', 'data.id', item.data.id],
1092
+ * ['metas', 'id', meta.id]
1093
+ *],
1094
+ *[
1095
+ * ['data.items', 'data.id', item.data.id],
1096
+ * ['metas', 'id', meta.id]
1097
+ *],
1098
+ *'test'
1099
+ */
1100
+ extra.forEach((dataPath, index) => {
1101
+ if (typeof dataPath === 'string') {
1102
+ if (!dataPath) { // model,prop.sync
1103
+ extraObj['$' + index] = vm;
1104
+ } else {
1105
+ if (dataPath === '$event') { // $event
1106
+ extraObj['$' + index] = event;
1107
+ } else if (dataPath === 'arguments') {
1108
+ if (event.detail && event.detail.__args__) {
1109
+ extraObj['$' + index] = event.detail.__args__;
1110
+ } else {
1111
+ extraObj['$' + index] = [event];
1112
+ }
1113
+ } else if (dataPath.indexOf('$event.') === 0) { // $event.target.value
1114
+ extraObj['$' + index] = vm.__get_value(dataPath.replace('$event.', ''), event);
1115
+ } else {
1116
+ extraObj['$' + index] = vm.__get_value(dataPath);
1117
+ }
1118
+ }
1119
+ } else {
1120
+ extraObj['$' + index] = getExtraValue(vm, dataPath);
1121
+ }
1122
+ });
1123
+ }
1124
+
1125
+ return extraObj
1126
+ }
1127
+
1128
+ function getObjByArray (arr) {
1129
+ const obj = {};
1130
+ for (let i = 1; i < arr.length; i++) {
1131
+ const element = arr[i];
1132
+ obj[element[0]] = element[1];
1133
+ }
1134
+ return obj
1135
+ }
1136
+
1137
+ function processEventArgs (vm, event, args = [], extra = [], isCustom, methodName) {
1138
+ let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
1139
+ if (isCustom) { // 自定义事件
1140
+ isCustomMPEvent = event.currentTarget &&
1141
+ event.currentTarget.dataset &&
1142
+ event.currentTarget.dataset.comType === 'wx';
1143
+ if (!args.length) { // 无参数,直接传入 event 或 detail 数组
1144
+ if (isCustomMPEvent) {
1145
+ return [event]
1146
+ }
1147
+ return event.detail.__args__ || event.detail
1148
+ }
1149
+ }
1150
+
1151
+ const extraObj = processEventExtra(vm, extra, event);
1152
+
1153
+ const ret = [];
1154
+ args.forEach(arg => {
1155
+ if (arg === '$event') {
1156
+ if (methodName === '__set_model' && !isCustom) { // input v-model value
1157
+ ret.push(event.target.value);
1158
+ } else {
1159
+ if (isCustom && !isCustomMPEvent) {
1160
+ ret.push(event.detail.__args__[0]);
1161
+ } else { // wxcomponent 组件或内置组件
1162
+ ret.push(event);
1163
+ }
1164
+ }
1165
+ } else {
1166
+ if (Array.isArray(arg) && arg[0] === 'o') {
1167
+ ret.push(getObjByArray(arg));
1168
+ } else if (typeof arg === 'string' && hasOwn(extraObj, arg)) {
1169
+ ret.push(extraObj[arg]);
1170
+ } else {
1171
+ ret.push(arg);
1172
+ }
1173
+ }
1174
+ });
1175
+
1176
+ return ret
1177
+ }
1178
+
1179
+ const ONCE = '~';
1180
+ const CUSTOM = '^';
1181
+
1182
+ function isMatchEventType (eventType, optType) {
1183
+ return (eventType === optType) ||
1184
+ (
1185
+ optType === 'regionchange' &&
1186
+ (
1187
+ eventType === 'begin' ||
1188
+ eventType === 'end'
1189
+ )
1190
+ )
1191
+ }
1192
+
1193
+ function getContextVm (vm) {
1194
+ let $parent = vm.$parent;
1195
+ // 父组件是 scoped slots 或者其他自定义组件时继续查找
1196
+ while ($parent && $parent.$parent && ($parent.$options.generic || $parent.$parent.$options.generic || $parent.$scope._$vuePid)) {
1197
+ $parent = $parent.$parent;
1198
+ }
1199
+ return $parent && $parent.$parent
1200
+ }
1201
+
1202
+ function handleEvent (event) {
1203
+ event = wrapper$1(event);
1204
+
1205
+ // [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
1206
+ const dataset = (event.currentTarget || event.target).dataset;
1207
+ if (!dataset) {
1208
+ return console.warn('事件信息不存在')
1209
+ }
1210
+ const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
1211
+ if (!eventOpts) {
1212
+ return console.warn('事件信息不存在')
1213
+ }
1214
+
1215
+ // [['handle',[1,2,a]],['handle1',[1,2,a]]]
1216
+ const eventType = event.type;
1217
+
1218
+ const ret = [];
1219
+
1220
+ eventOpts.forEach(eventOpt => {
1221
+ let type = eventOpt[0];
1222
+ const eventsArray = eventOpt[1];
1223
+
1224
+ const isCustom = type.charAt(0) === CUSTOM;
1225
+ type = isCustom ? type.slice(1) : type;
1226
+ const isOnce = type.charAt(0) === ONCE;
1227
+ type = isOnce ? type.slice(1) : type;
1228
+
1229
+ if (eventsArray && isMatchEventType(eventType, type)) {
1230
+ eventsArray.forEach(eventArray => {
1231
+ const methodName = eventArray[0];
1232
+ if (methodName) {
1233
+ let handlerCtx = this.$vm;
1234
+ if (handlerCtx.$options.generic) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
1235
+ handlerCtx = getContextVm(handlerCtx) || handlerCtx;
1236
+ }
1237
+ if (methodName === '$emit') {
1238
+ handlerCtx.$emit.apply(handlerCtx,
1239
+ processEventArgs(
1240
+ this.$vm,
1241
+ event,
1242
+ eventArray[1],
1243
+ eventArray[2],
1244
+ isCustom,
1245
+ methodName
1246
+ ));
1247
+ return
1248
+ }
1249
+ const handler = handlerCtx[methodName];
1250
+ if (!isFn(handler)) {
1251
+ throw new Error(` _vm.${methodName} is not a function`)
1252
+ }
1253
+ if (isOnce) {
1254
+ if (handler.once) {
1255
+ return
1256
+ }
1257
+ handler.once = true;
1258
+ }
1259
+ let params = processEventArgs(
1260
+ this.$vm,
1261
+ event,
1262
+ eventArray[1],
1263
+ eventArray[2],
1264
+ isCustom,
1265
+ methodName
1266
+ );
1267
+ params = Array.isArray(params) ? params : [];
1268
+ // 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
1269
+ if (/=\s*\S+\.eventParams\s*\|\|\s*\S+\[['"]event-params['"]\]/.test(handler.toString())) {
1270
+ // eslint-disable-next-line no-sparse-arrays
1271
+ params = params.concat([, , , , , , , , , , event]);
1272
+ }
1273
+ ret.push(handler.apply(handlerCtx, params));
1274
+ }
1275
+ });
1276
+ }
1277
+ });
1278
+
1279
+ if (
1280
+ eventType === 'input' &&
1281
+ ret.length === 1 &&
1282
+ typeof ret[0] !== 'undefined'
1283
+ ) {
1284
+ return ret[0]
1285
+ }
1286
+ }
1287
+
1288
+ const messages = {};
1289
+
1290
+ let locale;
1291
+
1292
+ {
1293
+ locale = xhs.getSystemInfoSync().language;
1294
+ }
1295
+
1296
+ function initI18nMessages () {
1297
+ if (!isEnableLocale()) {
1298
+ return
1299
+ }
1300
+ const localeKeys = Object.keys(__uniConfig.locales);
1301
+ if (localeKeys.length) {
1302
+ localeKeys.forEach((locale) => {
1303
+ const curMessages = messages[locale];
1304
+ const userMessages = __uniConfig.locales[locale];
1305
+ if (curMessages) {
1306
+ Object.assign(curMessages, userMessages);
1307
+ } else {
1308
+ messages[locale] = userMessages;
1309
+ }
1310
+ });
1311
+ }
1312
+ }
1313
+
1314
+ initI18nMessages();
1315
+
1316
+ const i18n = initVueI18n(
1317
+ locale,
1318
+ {}
1319
+ );
1320
+ const t = i18n.t;
1321
+ const i18nMixin = (i18n.mixin = {
1322
+ beforeCreate () {
1323
+ const unwatch = i18n.i18n.watchLocale(() => {
1324
+ this.$forceUpdate();
1325
+ });
1326
+ this.$once('hook:beforeDestroy', function () {
1327
+ unwatch();
1328
+ });
1329
+ },
1330
+ methods: {
1331
+ $$t (key, values) {
1332
+ return t(key, values)
1333
+ }
1334
+ }
1335
+ });
1336
+ const setLocale$1 = i18n.setLocale;
1337
+ const getLocale$1 = i18n.getLocale;
1338
+
1339
+ function initAppLocale (Vue, appVm, locale) {
1340
+ const state = Vue.observable({
1341
+ locale: locale || i18n.getLocale()
1342
+ });
1343
+ const localeWatchers = [];
1344
+ appVm.$watchLocale = fn => {
1345
+ localeWatchers.push(fn);
1346
+ };
1347
+ Object.defineProperty(appVm, '$locale', {
1348
+ get () {
1349
+ return state.locale
1350
+ },
1351
+ set (v) {
1352
+ state.locale = v;
1353
+ localeWatchers.forEach(watch => watch(v));
1354
+ }
1355
+ });
1356
+ }
1357
+
1358
+ function isEnableLocale () {
1359
+ return typeof __uniConfig !== 'undefined' && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
1360
+ }
1361
+
1362
+ // export function initI18n() {
1363
+ // const localeKeys = Object.keys(__uniConfig.locales || {})
1364
+ // if (localeKeys.length) {
1365
+ // localeKeys.forEach((locale) =>
1366
+ // i18n.add(locale, __uniConfig.locales[locale])
1367
+ // )
1368
+ // }
1369
+ // }
1370
+
1371
+ class EventChannel {
1372
+ constructor (id, events) {
1373
+ this.id = id;
1374
+ this.listener = {};
1375
+ this.emitCache = {};
1376
+ if (events) {
1377
+ Object.keys(events).forEach(name => {
1378
+ this.on(name, events[name]);
1379
+ });
1380
+ }
1381
+ }
1382
+
1383
+ emit (eventName, ...args) {
1384
+ const fns = this.listener[eventName];
1385
+ if (!fns) {
1386
+ return (this.emitCache[eventName] || (this.emitCache[eventName] = [])).push(args)
1387
+ }
1388
+ fns.forEach(opt => {
1389
+ opt.fn.apply(opt.fn, args);
1390
+ });
1391
+ this.listener[eventName] = fns.filter(opt => opt.type !== 'once');
1392
+ }
1393
+
1394
+ on (eventName, fn) {
1395
+ this._addListener(eventName, 'on', fn);
1396
+ this._clearCache(eventName);
1397
+ }
1398
+
1399
+ once (eventName, fn) {
1400
+ this._addListener(eventName, 'once', fn);
1401
+ this._clearCache(eventName);
1402
+ }
1403
+
1404
+ off (eventName, fn) {
1405
+ const fns = this.listener[eventName];
1406
+ if (!fns) {
1407
+ return
1408
+ }
1409
+ if (fn) {
1410
+ for (let i = 0; i < fns.length;) {
1411
+ if (fns[i].fn === fn) {
1412
+ fns.splice(i, 1);
1413
+ i--;
1414
+ }
1415
+ i++;
1416
+ }
1417
+ } else {
1418
+ delete this.listener[eventName];
1419
+ }
1420
+ }
1421
+
1422
+ _clearCache (eventName) {
1423
+ const cacheArgs = this.emitCache[eventName];
1424
+ if (cacheArgs) {
1425
+ for (; cacheArgs.length > 0;) {
1426
+ this.emit.apply(this, [eventName].concat(cacheArgs.shift()));
1427
+ }
1428
+ }
1429
+ }
1430
+
1431
+ _addListener (eventName, type, fn) {
1432
+ (this.listener[eventName] || (this.listener[eventName] = [])).push({
1433
+ fn,
1434
+ type
1435
+ });
1436
+ }
1437
+ }
1438
+
1439
+ const eventChannels = {};
1440
+
1441
+ const eventChannelStack = [];
1442
+
1443
+ function getEventChannel (id) {
1444
+ if (id) {
1445
+ const eventChannel = eventChannels[id];
1446
+ delete eventChannels[id];
1447
+ return eventChannel
1448
+ }
1449
+ return eventChannelStack.shift()
1450
+ }
1451
+
1452
+ const hooks = [
1453
+ 'onShow',
1454
+ 'onHide',
1455
+ 'onError',
1456
+ 'onPageNotFound',
1457
+ 'onThemeChange',
1458
+ 'onUnhandledRejection'
1459
+ ];
1460
+
1461
+ function initEventChannel () {
1462
+ Vue.prototype.getOpenerEventChannel = function () {
1463
+ if (!this.__eventChannel__) {
1464
+ this.__eventChannel__ = new EventChannel();
1465
+ }
1466
+ return this.__eventChannel__
1467
+ };
1468
+ const callHook = Vue.prototype.__call_hook;
1469
+ Vue.prototype.__call_hook = function (hook, args) {
1470
+ if (hook === 'onLoad' && args && args.__id__) {
1471
+ this.__eventChannel__ = getEventChannel(args.__id__);
1472
+ delete args.__id__;
1473
+ }
1474
+ return callHook.call(this, hook, args)
1475
+ };
1476
+ }
1477
+
1478
+ function initScopedSlotsParams () {
1479
+ const center = {};
1480
+ const parents = {};
1481
+
1482
+ Vue.prototype.$hasScopedSlotsParams = function (vueId) {
1483
+ const has = center[vueId];
1484
+ if (!has) {
1485
+ parents[vueId] = this;
1486
+ this.$on('hook:destroyed', () => {
1487
+ delete parents[vueId];
1488
+ });
1489
+ }
1490
+ return has
1491
+ };
1492
+
1493
+ Vue.prototype.$getScopedSlotsParams = function (vueId, name, key) {
1494
+ const data = center[vueId];
1495
+ if (data) {
1496
+ const object = data[name] || {};
1497
+ return key ? object[key] : object
1498
+ } else {
1499
+ parents[vueId] = this;
1500
+ this.$on('hook:destroyed', () => {
1501
+ delete parents[vueId];
1502
+ });
1503
+ }
1504
+ };
1505
+
1506
+ Vue.prototype.$setScopedSlotsParams = function (name, value) {
1507
+ const vueIds = this.$options.propsData.vueId;
1508
+ if (vueIds) {
1509
+ const vueId = vueIds.split(',')[0];
1510
+ const object = center[vueId] = center[vueId] || {};
1511
+ object[name] = value;
1512
+ if (parents[vueId]) {
1513
+ parents[vueId].$forceUpdate();
1514
+ }
1515
+ }
1516
+ };
1517
+
1518
+ Vue.mixin({
1519
+ destroyed () {
1520
+ const propsData = this.$options.propsData;
1521
+ const vueId = propsData && propsData.vueId;
1522
+ if (vueId) {
1523
+ delete center[vueId];
1524
+ delete parents[vueId];
1525
+ }
1526
+ }
1527
+ });
1528
+ }
1529
+
1530
+ function parseBaseApp (vm, {
1531
+ mocks,
1532
+ initRefs
1533
+ }) {
1534
+ initEventChannel();
1535
+ {
1536
+ initScopedSlotsParams();
1537
+ }
1538
+ if (vm.$options.store) {
1539
+ Vue.prototype.$store = vm.$options.store;
1540
+ }
1541
+ uniIdMixin(Vue);
1542
+
1543
+ Vue.prototype.mpHost = "mp-xhs";
1544
+
1545
+ Vue.mixin({
1546
+ beforeCreate () {
1547
+ if (!this.$options.mpType) {
1548
+ return
1549
+ }
1550
+
1551
+ this.mpType = this.$options.mpType;
1552
+
1553
+ this.$mp = {
1554
+ data: {},
1555
+ [this.mpType]: this.$options.mpInstance
1556
+ };
1557
+
1558
+ this.$scope = this.$options.mpInstance;
1559
+
1560
+ delete this.$options.mpType;
1561
+ delete this.$options.mpInstance;
1562
+ if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
1563
+ const app = getApp();
1564
+ if (app.$vm && app.$vm.$i18n) {
1565
+ this._i18n = app.$vm.$i18n;
1566
+ }
1567
+ }
1568
+ if (this.mpType !== 'app') {
1569
+ initRefs(this);
1570
+ initMocks(this, mocks);
1571
+ }
1572
+ }
1573
+ });
1574
+
1575
+ const appOptions = {
1576
+ onLaunch (args) {
1577
+ if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
1578
+ return
1579
+ }
1580
+
1581
+ this.$vm = vm;
1582
+
1583
+ this.$vm.$mp = {
1584
+ app: this
1585
+ };
1586
+
1587
+ this.$vm.$scope = this;
1588
+ // vm 上也挂载 globalData
1589
+ this.$vm.globalData = this.globalData;
1590
+
1591
+ this.$vm._isMounted = true;
1592
+ this.$vm.__call_hook('mounted', args);
1593
+
1594
+ this.$vm.__call_hook('onLaunch', args);
1595
+ }
1596
+ };
1597
+
1598
+ // 兼容旧版本 globalData
1599
+ appOptions.globalData = vm.$options.globalData || {};
1600
+ // 将 methods 中的方法挂在 getApp() 中
1601
+ const methods = vm.$options.methods;
1602
+ if (methods) {
1603
+ Object.keys(methods).forEach(name => {
1604
+ appOptions[name] = methods[name];
1605
+ });
1606
+ }
1607
+
1608
+ initAppLocale(Vue, vm, xhs.getSystemInfoSync().language || 'zh-Hans');
1609
+
1610
+ initHooks(appOptions, hooks);
1611
+
1612
+ return appOptions
1613
+ }
1614
+
1615
+ const mocks = ['__route__', '__wxExparserNodeId__', '__wxWebviewId__'];
1616
+
1617
+ function findVmByVueId (vm, vuePid) {
1618
+ const $children = vm.$children;
1619
+ // 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
1620
+ for (let i = $children.length - 1; i >= 0; i--) {
1621
+ const childVm = $children[i];
1622
+ if (childVm.$scope._$vueId === vuePid) {
1623
+ return childVm
1624
+ }
1625
+ }
1626
+ // 反向递归查找
1627
+ let parentVm;
1628
+ for (let i = $children.length - 1; i >= 0; i--) {
1629
+ parentVm = findVmByVueId($children[i], vuePid);
1630
+ if (parentVm) {
1631
+ return parentVm
1632
+ }
1633
+ }
1634
+ }
1635
+
1636
+ function initBehavior (options) {
1637
+ return Behavior(options)
1638
+ }
1639
+
1640
+ function isPage () {
1641
+ return !!this.route
1642
+ }
1643
+
1644
+ function initRelation (detail) {
1645
+ this.triggerEvent('__l', detail);
1646
+ }
1647
+
1648
+ function selectAllComponents (mpInstance, selector, $refs) {
1649
+ const components = mpInstance.selectAllComponents(selector);
1650
+ components.forEach(component => {
1651
+ const ref = component.dataset.ref;
1652
+ $refs[ref] = component.$vm || component;
1653
+ });
1654
+ }
1655
+
1656
+ function initRefs (vm) {
1657
+ const mpInstance = vm.$scope;
1658
+ Object.defineProperty(vm, '$refs', {
1659
+ get () {
1660
+ const $refs = {};
1661
+ selectAllComponents(mpInstance, '.vue-ref', $refs);
1662
+ // TODO 暂不考虑 for 中的 scoped
1663
+ const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
1664
+ forComponents.forEach(component => {
1665
+ const ref = component.dataset.ref;
1666
+ if (!$refs[ref]) {
1667
+ $refs[ref] = [];
1668
+ }
1669
+ $refs[ref].push(component.$vm || component);
1670
+ });
1671
+ return $refs
1672
+ }
1673
+ });
1674
+ }
1675
+
1676
+ function handleLink (event) {
1677
+ const {
1678
+ vuePid,
1679
+ vueOptions
1680
+ } = event.detail || event.value; // detail 是微信,value 是百度(dipatch)
1681
+
1682
+ let parentVm;
1683
+
1684
+ if (vuePid) {
1685
+ parentVm = findVmByVueId(this.$vm, vuePid);
1686
+ }
1687
+
1688
+ if (!parentVm) {
1689
+ parentVm = this.$vm;
1690
+ }
1691
+
1692
+ vueOptions.parent = parentVm;
1693
+ }
1694
+
1695
+ function parseApp (vm) {
1696
+ return parseBaseApp(vm, {
1697
+ mocks,
1698
+ initRefs
1699
+ })
1700
+ }
1701
+
1702
+ function parseApp$1 (vm) {
1703
+ return parseApp(vm)
1704
+ }
1705
+
1706
+ function createApp (vm) {
1707
+ App(parseApp$1(vm));
1708
+ return vm
1709
+ }
1710
+
1711
+ const encodeReserveRE = /[!'()*]/g;
1712
+ const encodeReserveReplacer = c => '%' + c.charCodeAt(0).toString(16);
1713
+ const commaRE = /%2C/g;
1714
+
1715
+ // fixed encodeURIComponent which is more conformant to RFC3986:
1716
+ // - escapes [!'()*]
1717
+ // - preserve commas
1718
+ const encode = str => encodeURIComponent(str)
1719
+ .replace(encodeReserveRE, encodeReserveReplacer)
1720
+ .replace(commaRE, ',');
1721
+
1722
+ function stringifyQuery (obj, encodeStr = encode) {
1723
+ const res = obj ? Object.keys(obj).map(key => {
1724
+ const val = obj[key];
1725
+
1726
+ if (val === undefined) {
1727
+ return ''
1728
+ }
1729
+
1730
+ if (val === null) {
1731
+ return encodeStr(key)
1732
+ }
1733
+
1734
+ if (Array.isArray(val)) {
1735
+ const result = [];
1736
+ val.forEach(val2 => {
1737
+ if (val2 === undefined) {
1738
+ return
1739
+ }
1740
+ if (val2 === null) {
1741
+ result.push(encodeStr(key));
1742
+ } else {
1743
+ result.push(encodeStr(key) + '=' + encodeStr(val2));
1744
+ }
1745
+ });
1746
+ return result.join('&')
1747
+ }
1748
+
1749
+ return encodeStr(key) + '=' + encodeStr(val)
1750
+ }).filter(x => x.length > 0).join('&') : null;
1751
+ return res ? `?${res}` : ''
1752
+ }
1753
+
1754
+ const isComponent2 = xhs.canIUse('component2');
1755
+
1756
+ function initSpecialMethods (mpInstance) {
1757
+ if (!mpInstance.$vm) {
1758
+ return
1759
+ }
1760
+ let path = mpInstance.is || mpInstance.route;
1761
+ if (!path) {
1762
+ return
1763
+ }
1764
+ if (path.indexOf('/') === 0) {
1765
+ path = path.substr(1);
1766
+ }
1767
+ const specialMethods = xhs.specialMethods && xhs.specialMethods[path];
1768
+ if (specialMethods) {
1769
+ specialMethods.forEach(method => {
1770
+ if (isFn(mpInstance.$vm[method])) {
1771
+ mpInstance[method] = function (event) {
1772
+ if (hasOwn(event, 'markerId')) {
1773
+ event.detail = typeof event.detail === 'object' ? event.detail : {};
1774
+ event.detail.markerId = event.markerId;
1775
+ }
1776
+ // TODO normalizeEvent
1777
+ mpInstance.$vm[method](event);
1778
+ };
1779
+ }
1780
+ });
1781
+ }
1782
+ }
1783
+
1784
+ const handleWrap = function (mp, destory) {
1785
+ const vueId = mp.props.vueId;
1786
+ const list = mp.props['data-event-list'].split(',');
1787
+ list.forEach(eventName => {
1788
+ const key = `${eventName}${vueId}`;
1789
+ if (destory) {
1790
+ delete this[key];
1791
+ } else {
1792
+ // TODO remove handleRef
1793
+ this[key] = function () {
1794
+ mp.props[eventName].apply(this, arguments);
1795
+ };
1796
+ }
1797
+ });
1798
+ };
1799
+
1800
+ const hooks$1 = [
1801
+ 'onShow',
1802
+ 'onHide',
1803
+ 'onUnload'
1804
+ ];
1805
+
1806
+ hooks$1.push(...PAGE_EVENT_HOOKS);
1807
+
1808
+ function parsePage (vuePageOptions) {
1809
+ const [VueComponent, vueOptions] = initVueComponent(Vue, vuePageOptions);
1810
+
1811
+ const pageOptions = {
1812
+ mixins: initBehaviors(vueOptions, initBehavior),
1813
+ data: initData(vueOptions, Vue.prototype),
1814
+ onLoad (query) {
1815
+ const properties = this.props;
1816
+
1817
+ const options = {
1818
+ mpType: 'page',
1819
+ mpInstance: this,
1820
+ propsData: properties
1821
+ };
1822
+
1823
+ // 初始化 vue 实例
1824
+ this.$vm = new VueComponent(options);
1825
+
1826
+ initSpecialMethods(this);
1827
+
1828
+ // 触发首次 setData
1829
+ this.$vm.$mount();
1830
+
1831
+ const copyQuery = Object.assign({}, query);
1832
+ delete copyQuery.__id__;
1833
+
1834
+ this.$page = {
1835
+ fullPath: '/' + this.route + stringifyQuery(copyQuery)
1836
+ };
1837
+
1838
+ this.options = query;
1839
+ this.$vm.$mp.query = query; // 兼容 mpvue
1840
+ this.$vm.__call_hook('onLoad', query);
1841
+ },
1842
+ onReady () {
1843
+ // initChildVues(this)
1844
+ this.$vm._isMounted = true;
1845
+ this.$vm.__call_hook('mounted');
1846
+ this.$vm.__call_hook('onReady');
1847
+ },
1848
+ onUnload () {
1849
+ this.$vm.__call_hook('onUnload');
1850
+ this.$vm.$destroy();
1851
+ },
1852
+ // __r: handleRef,
1853
+ __e: handleEvent,
1854
+ __l: handleLink,
1855
+ __w: handleWrap,
1856
+ triggerEvent: function noop () {}
1857
+ };
1858
+
1859
+ initHooks(pageOptions, hooks$1, vuePageOptions);
1860
+
1861
+ if (Array.isArray(vueOptions.wxsCallMethods)) {
1862
+ vueOptions.wxsCallMethods.forEach(callMethod => {
1863
+ pageOptions[callMethod] = function (args) {
1864
+ return this.$vm[callMethod](args)
1865
+ };
1866
+ });
1867
+ }
1868
+
1869
+ return pageOptions
1870
+ }
1871
+
1872
+ function createPage (vuePageOptions) {
1873
+ {
1874
+ return Page(parsePage(vuePageOptions))
1875
+ }
1876
+ }
1877
+
1878
+ function parseBaseComponent (vueComponentOptions, {
1879
+ isPage,
1880
+ initRelation
1881
+ } = {}) {
1882
+ const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
1883
+
1884
+ const options = {
1885
+ multipleSlots: true,
1886
+ addGlobalClass: true,
1887
+ ...(vueOptions.options || {})
1888
+ };
1889
+
1890
+ const componentOptions = {
1891
+ options,
1892
+ data: initData(vueOptions, Vue.prototype),
1893
+ behaviors: initBehaviors(vueOptions, initBehavior),
1894
+ properties: initProperties(vueOptions.props, false, vueOptions.__file),
1895
+ lifetimes: {
1896
+ attached () {
1897
+ const properties = this.properties;
1898
+
1899
+ const options = {
1900
+ mpType: isPage.call(this) ? 'page' : 'component',
1901
+ mpInstance: this,
1902
+ propsData: properties
1903
+ };
1904
+
1905
+ initVueIds(properties.vueId, this);
1906
+
1907
+ // 处理父子关系
1908
+ initRelation.call(this, {
1909
+ vuePid: this._$vuePid,
1910
+ vueOptions: options
1911
+ });
1912
+
1913
+ // 初始化 vue 实例
1914
+ this.$vm = new VueComponent(options);
1915
+
1916
+ // 处理$slots,$scopedSlots(暂不支持动态变化$slots)
1917
+ initSlots(this.$vm, properties.vueSlots);
1918
+
1919
+ // 触发首次 setData
1920
+ this.$vm.$mount();
1921
+ },
1922
+ ready () {
1923
+ // 当组件 props 默认值为 true,初始化时传入 false 会导致 created,ready 触发, 但 attached 不触发
1924
+ // https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800
1925
+ if (this.$vm) {
1926
+ this.$vm._isMounted = true;
1927
+ this.$vm.__call_hook('mounted');
1928
+ this.$vm.__call_hook('onReady');
1929
+ }
1930
+ },
1931
+ detached () {
1932
+ this.$vm && this.$vm.$destroy();
1933
+ }
1934
+ },
1935
+ pageLifetimes: {
1936
+ show (args) {
1937
+ this.$vm && this.$vm.__call_hook('onPageShow', args);
1938
+ },
1939
+ hide () {
1940
+ this.$vm && this.$vm.__call_hook('onPageHide');
1941
+ },
1942
+ resize (size) {
1943
+ this.$vm && this.$vm.__call_hook('onPageResize', size);
1944
+ }
1945
+ },
1946
+ methods: {
1947
+ __l: handleLink,
1948
+ __e: handleEvent
1949
+ }
1950
+ };
1951
+ // externalClasses
1952
+ if (vueOptions.externalClasses) {
1953
+ componentOptions.externalClasses = vueOptions.externalClasses;
1954
+ }
1955
+
1956
+ if (Array.isArray(vueOptions.wxsCallMethods)) {
1957
+ vueOptions.wxsCallMethods.forEach(callMethod => {
1958
+ componentOptions.methods[callMethod] = function (args) {
1959
+ return this.$vm[callMethod](args)
1960
+ };
1961
+ });
1962
+ }
1963
+
1964
+ if (isPage) {
1965
+ return componentOptions
1966
+ }
1967
+ return [componentOptions, VueComponent]
1968
+ }
1969
+
1970
+ function parseComponent (vueComponentOptions) {
1971
+ return parseBaseComponent(vueComponentOptions, {
1972
+ isPage,
1973
+ initRelation
1974
+ })
1975
+ }
1976
+
1977
+ /**
1978
+ * 用于延迟调用 setData
1979
+ * 在 setData 真实调用的时机需执行 fixSetDataEnd
1980
+ * @param {*} mpInstance
1981
+ */
1982
+ function fixSetDataStart (mpInstance) {
1983
+ const setData = mpInstance.setData;
1984
+ const setDataArgs = [];
1985
+ mpInstance.setData = function () {
1986
+ setDataArgs.push(arguments);
1987
+ };
1988
+ mpInstance.__fixInitData = function () {
1989
+ this.setData = setData;
1990
+ const fn = () => {
1991
+ setDataArgs.forEach(args => {
1992
+ setData.apply(this, args);
1993
+ });
1994
+ };
1995
+ if (setDataArgs.length) {
1996
+ if (this.groupSetData) {
1997
+ this.groupSetData(fn);
1998
+ } else {
1999
+ fn();
2000
+ }
2001
+ }
2002
+ };
2003
+ }
2004
+ /**
2005
+ * 恢复真实的 setData 方法
2006
+ * @param {*} mpInstance
2007
+ */
2008
+ function fixSetDataEnd (mpInstance) {
2009
+ if (mpInstance.__fixInitData) {
2010
+ mpInstance.__fixInitData();
2011
+ delete mpInstance.__fixInitData;
2012
+ }
2013
+ }
2014
+
2015
+ // import parseBaseComponent from '../../../mp-weixin/runtime/wrapper/component-parser'
2016
+
2017
+ function parseComponent$1 (vueComponentOptions) {
2018
+ const componentOptions = parseComponent(vueComponentOptions);
2019
+ const oldAttached = componentOptions.lifetimes.attached;
2020
+ componentOptions.lifetimes.attached = function attached () {
2021
+ // 暂不区分版本
2022
+ if (isPage.call(this)) {
2023
+ fixSetDataStart(this);
2024
+ setTimeout(() => {
2025
+ fixSetDataEnd(this);
2026
+ }, 0);
2027
+ }
2028
+ oldAttached.call(this);
2029
+ };
2030
+ return componentOptions
2031
+ }
2032
+
2033
+ function createComponent (vueOptions) {
2034
+ {
2035
+ return Component(parseComponent$1(vueOptions))
2036
+ }
2037
+ }
2038
+
2039
+ function createSubpackageApp (vm) {
2040
+ const appOptions = parseApp$1(vm);
2041
+ const app = getApp({
2042
+ allowDefault: true
2043
+ });
2044
+ vm.$scope = app;
2045
+ const globalData = app.globalData;
2046
+ if (globalData) {
2047
+ Object.keys(appOptions.globalData).forEach(name => {
2048
+ if (!hasOwn(globalData, name)) {
2049
+ globalData[name] = appOptions.globalData[name];
2050
+ }
2051
+ });
2052
+ }
2053
+ Object.keys(appOptions).forEach(name => {
2054
+ if (!hasOwn(app, name)) {
2055
+ app[name] = appOptions[name];
2056
+ }
2057
+ });
2058
+ if (isFn(appOptions.onShow) && xhs.onAppShow) {
2059
+ xhs.onAppShow((...args) => {
2060
+ vm.__call_hook('onShow', args);
2061
+ });
2062
+ }
2063
+ if (isFn(appOptions.onHide) && xhs.onAppHide) {
2064
+ xhs.onAppHide((...args) => {
2065
+ vm.__call_hook('onHide', args);
2066
+ });
2067
+ }
2068
+ if (isFn(appOptions.onLaunch)) {
2069
+ const args = xhs.getLaunchOptionsSync && xhs.getLaunchOptionsSync();
2070
+ vm.__call_hook('onLaunch', args);
2071
+ }
2072
+ return vm
2073
+ }
2074
+
2075
+ function createPlugin (vm) {
2076
+ const appOptions = parseApp$1(vm);
2077
+ if (isFn(appOptions.onShow) && xhs.onAppShow) {
2078
+ xhs.onAppShow((...args) => {
2079
+ vm.__call_hook('onShow', args);
2080
+ });
2081
+ }
2082
+ if (isFn(appOptions.onHide) && xhs.onAppHide) {
2083
+ xhs.onAppHide((...args) => {
2084
+ vm.__call_hook('onHide', args);
2085
+ });
2086
+ }
2087
+ if (isFn(appOptions.onLaunch)) {
2088
+ const args = xhs.getLaunchOptionsSync && xhs.getLaunchOptionsSync();
2089
+ vm.__call_hook('onLaunch', args);
2090
+ }
2091
+ return vm
2092
+ }
2093
+
2094
+ todos.forEach(todoApi => {
2095
+ protocols[todoApi] = false;
2096
+ });
2097
+
2098
+ canIUses.forEach(canIUseApi => {
2099
+ const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name
2100
+ : canIUseApi;
2101
+ if (!xhs.canIUse(apiName)) {
2102
+ protocols[canIUseApi] = false;
2103
+ }
2104
+ });
2105
+
2106
+ let uni = {};
2107
+
2108
+ if (typeof Proxy !== 'undefined' && "mp-xhs" !== 'app-plus') {
2109
+ uni = new Proxy({}, {
2110
+ get (target, name) {
2111
+ if (hasOwn(target, name)) {
2112
+ return target[name]
2113
+ }
2114
+ if (baseApi[name]) {
2115
+ return baseApi[name]
2116
+ }
2117
+ if (api[name]) {
2118
+ return promisify(name, api[name])
2119
+ }
2120
+ {
2121
+ if (extraApi[name]) {
2122
+ return promisify(name, extraApi[name])
2123
+ }
2124
+ if (todoApis[name]) {
2125
+ return promisify(name, todoApis[name])
2126
+ }
2127
+ }
2128
+ if (eventApi[name]) {
2129
+ return eventApi[name]
2130
+ }
2131
+ if (!hasOwn(xhs, name) && !hasOwn(protocols, name)) {
2132
+ return
2133
+ }
2134
+ return promisify(name, wrapper(name, xhs[name]))
2135
+ },
2136
+ set (target, name, value) {
2137
+ target[name] = value;
2138
+ return true
2139
+ }
2140
+ });
2141
+ } else {
2142
+ Object.keys(baseApi).forEach(name => {
2143
+ uni[name] = baseApi[name];
2144
+ });
2145
+
2146
+ {
2147
+ Object.keys(todoApis).forEach(name => {
2148
+ uni[name] = promisify(name, todoApis[name]);
2149
+ });
2150
+ Object.keys(extraApi).forEach(name => {
2151
+ uni[name] = promisify(name, todoApis[name]);
2152
+ });
2153
+ }
2154
+
2155
+ Object.keys(eventApi).forEach(name => {
2156
+ uni[name] = eventApi[name];
2157
+ });
2158
+
2159
+ Object.keys(api).forEach(name => {
2160
+ uni[name] = promisify(name, api[name]);
2161
+ });
2162
+
2163
+ Object.keys(xhs).forEach(name => {
2164
+ if (hasOwn(xhs, name) || hasOwn(protocols, name)) {
2165
+ uni[name] = promisify(name, wrapper(name, xhs[name]));
2166
+ }
2167
+ });
2168
+ }
2169
+
2170
+ xhs.createApp = createApp;
2171
+ xhs.createPage = createPage;
2172
+ xhs.createComponent = createComponent;
2173
+ xhs.createSubpackageApp = createSubpackageApp;
2174
+ xhs.createPlugin = createPlugin;
2175
+
2176
+ var uni$1 = uni;
2177
+
2178
+ export default uni$1;
2179
+ export { createApp, createComponent, createPage, createPlugin, createSubpackageApp };