@dcloudio/uni-mp-jd 2.0.1-33920220121001
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 +202 -0
- package/README.md +11 -0
- package/dist/index.js +2055 -0
- package/lib/uni.compiler.js +119 -0
- package/lib/uni.config.js +24 -0
- package/package.json +21 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2055 @@
|
|
|
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 = ( jd).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
|
+
} = jd.getSystemInfoSync(); // uni=>jd 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 jd.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
|
+
const todos = [
|
|
501
|
+
'getSelectedTextRange'
|
|
502
|
+
];
|
|
503
|
+
|
|
504
|
+
// 存在兼容性的 API 列表
|
|
505
|
+
const canIUses = [];
|
|
506
|
+
|
|
507
|
+
const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
|
|
508
|
+
|
|
509
|
+
function processCallback (methodName, method, returnValue) {
|
|
510
|
+
return function (res) {
|
|
511
|
+
return method(processReturnValue(methodName, res, returnValue))
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
|
|
516
|
+
if (isPlainObject(fromArgs)) { // 一般 api 的参数解析
|
|
517
|
+
const toArgs = keepFromArgs === true ? fromArgs : {}; // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
|
|
518
|
+
if (isFn(argsOption)) {
|
|
519
|
+
argsOption = argsOption(fromArgs, toArgs) || {};
|
|
520
|
+
}
|
|
521
|
+
for (const key in fromArgs) {
|
|
522
|
+
if (hasOwn(argsOption, key)) {
|
|
523
|
+
let keyOption = argsOption[key];
|
|
524
|
+
if (isFn(keyOption)) {
|
|
525
|
+
keyOption = keyOption(fromArgs[key], fromArgs, toArgs);
|
|
526
|
+
}
|
|
527
|
+
if (!keyOption) { // 不支持的参数
|
|
528
|
+
console.warn(`The '${methodName}' method of platform '京东小程序' does not support option '${key}'`);
|
|
529
|
+
} else if (isStr(keyOption)) { // 重写参数 key
|
|
530
|
+
toArgs[keyOption] = fromArgs[key];
|
|
531
|
+
} else if (isPlainObject(keyOption)) { // {name:newName,value:value}可重新指定参数 key:value
|
|
532
|
+
toArgs[keyOption.name ? keyOption.name : key] = keyOption.value;
|
|
533
|
+
}
|
|
534
|
+
} else if (CALLBACKS.indexOf(key) !== -1) {
|
|
535
|
+
if (isFn(fromArgs[key])) {
|
|
536
|
+
toArgs[key] = processCallback(methodName, fromArgs[key], returnValue);
|
|
537
|
+
}
|
|
538
|
+
} else {
|
|
539
|
+
if (!keepFromArgs) {
|
|
540
|
+
toArgs[key] = fromArgs[key];
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return toArgs
|
|
545
|
+
} else if (isFn(fromArgs)) {
|
|
546
|
+
fromArgs = processCallback(methodName, fromArgs, returnValue);
|
|
547
|
+
}
|
|
548
|
+
return fromArgs
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function processReturnValue (methodName, res, returnValue, keepReturnValue = false) {
|
|
552
|
+
if (isFn(protocols.returnValue)) { // 处理通用 returnValue
|
|
553
|
+
res = protocols.returnValue(methodName, res);
|
|
554
|
+
}
|
|
555
|
+
return processArgs(methodName, res, returnValue, {}, keepReturnValue)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function wrapper (methodName, method) {
|
|
559
|
+
if (hasOwn(protocols, methodName)) {
|
|
560
|
+
const protocol = protocols[methodName];
|
|
561
|
+
if (!protocol) { // 暂不支持的 api
|
|
562
|
+
return function () {
|
|
563
|
+
console.error(`Platform '京东小程序' does not support '${methodName}'.`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return function (arg1, arg2) { // 目前 api 最多两个参数
|
|
567
|
+
let options = protocol;
|
|
568
|
+
if (isFn(protocol)) {
|
|
569
|
+
options = protocol(arg1);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
arg1 = processArgs(methodName, arg1, options.args, options.returnValue);
|
|
573
|
+
|
|
574
|
+
const args = [arg1];
|
|
575
|
+
if (typeof arg2 !== 'undefined') {
|
|
576
|
+
args.push(arg2);
|
|
577
|
+
}
|
|
578
|
+
if (isFn(options.name)) {
|
|
579
|
+
methodName = options.name(arg1);
|
|
580
|
+
} else if (isStr(options.name)) {
|
|
581
|
+
methodName = options.name;
|
|
582
|
+
}
|
|
583
|
+
const returnValue = jd[methodName].apply(jd, args);
|
|
584
|
+
if (isSyncApi(methodName)) { // 同步 api
|
|
585
|
+
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
|
|
586
|
+
}
|
|
587
|
+
return returnValue
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return method
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const todoApis = Object.create(null);
|
|
594
|
+
|
|
595
|
+
const TODOS = [
|
|
596
|
+
'onTabBarMidButtonTap',
|
|
597
|
+
'subscribePush',
|
|
598
|
+
'unsubscribePush',
|
|
599
|
+
'onPush',
|
|
600
|
+
'offPush',
|
|
601
|
+
'share'
|
|
602
|
+
];
|
|
603
|
+
|
|
604
|
+
function createTodoApi (name) {
|
|
605
|
+
return function todoApi ({
|
|
606
|
+
fail,
|
|
607
|
+
complete
|
|
608
|
+
}) {
|
|
609
|
+
const res = {
|
|
610
|
+
errMsg: `${name}:fail method '${name}' not supported`
|
|
611
|
+
};
|
|
612
|
+
isFn(fail) && fail(res);
|
|
613
|
+
isFn(complete) && complete(res);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
TODOS.forEach(function (name) {
|
|
618
|
+
todoApis[name] = createTodoApi(name);
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
var providers = {
|
|
622
|
+
oauth: ['jd'],
|
|
623
|
+
share: ['jd'],
|
|
624
|
+
payment: ['jd'],
|
|
625
|
+
push: ['jd']
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
function getProvider ({
|
|
629
|
+
service,
|
|
630
|
+
success,
|
|
631
|
+
fail,
|
|
632
|
+
complete
|
|
633
|
+
}) {
|
|
634
|
+
let res = false;
|
|
635
|
+
if (providers[service]) {
|
|
636
|
+
res = {
|
|
637
|
+
errMsg: 'getProvider:ok',
|
|
638
|
+
service,
|
|
639
|
+
provider: providers[service]
|
|
640
|
+
};
|
|
641
|
+
isFn(success) && success(res);
|
|
642
|
+
} else {
|
|
643
|
+
res = {
|
|
644
|
+
errMsg: 'getProvider:fail service not found'
|
|
645
|
+
};
|
|
646
|
+
isFn(fail) && fail(res);
|
|
647
|
+
}
|
|
648
|
+
isFn(complete) && complete(res);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
var extraApi = /*#__PURE__*/Object.freeze({
|
|
652
|
+
__proto__: null,
|
|
653
|
+
getProvider: getProvider
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
const getEmitter = (function () {
|
|
657
|
+
let Emitter;
|
|
658
|
+
return function getUniEmitter () {
|
|
659
|
+
if (!Emitter) {
|
|
660
|
+
Emitter = new Vue();
|
|
661
|
+
}
|
|
662
|
+
return Emitter
|
|
663
|
+
}
|
|
664
|
+
})();
|
|
665
|
+
|
|
666
|
+
function apply (ctx, method, args) {
|
|
667
|
+
return ctx[method].apply(ctx, args)
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function $on () {
|
|
671
|
+
return apply(getEmitter(), '$on', [...arguments])
|
|
672
|
+
}
|
|
673
|
+
function $off () {
|
|
674
|
+
return apply(getEmitter(), '$off', [...arguments])
|
|
675
|
+
}
|
|
676
|
+
function $once () {
|
|
677
|
+
return apply(getEmitter(), '$once', [...arguments])
|
|
678
|
+
}
|
|
679
|
+
function $emit () {
|
|
680
|
+
return apply(getEmitter(), '$emit', [...arguments])
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
var eventApi = /*#__PURE__*/Object.freeze({
|
|
684
|
+
__proto__: null,
|
|
685
|
+
$on: $on,
|
|
686
|
+
$off: $off,
|
|
687
|
+
$once: $once,
|
|
688
|
+
$emit: $emit
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
var api = /*#__PURE__*/Object.freeze({
|
|
692
|
+
__proto__: null
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
const MPPage = Page;
|
|
696
|
+
const MPComponent = Component;
|
|
697
|
+
|
|
698
|
+
const customizeRE = /:/g;
|
|
699
|
+
|
|
700
|
+
const customize = cached((str) => {
|
|
701
|
+
return camelize(str.replace(customizeRE, '-'))
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
function initTriggerEvent (mpInstance) {
|
|
705
|
+
const oldTriggerEvent = mpInstance.triggerEvent;
|
|
706
|
+
const newTriggerEvent = function (event, ...args) {
|
|
707
|
+
return oldTriggerEvent.apply(mpInstance, [customize(event), ...args])
|
|
708
|
+
};
|
|
709
|
+
try {
|
|
710
|
+
// 京东小程序 triggerEvent 为只读
|
|
711
|
+
mpInstance.triggerEvent = newTriggerEvent;
|
|
712
|
+
} catch (error) {
|
|
713
|
+
mpInstance._triggerEvent = newTriggerEvent;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function initHook (name, options, isComponent) {
|
|
718
|
+
const oldHook = options[name];
|
|
719
|
+
if (!oldHook) {
|
|
720
|
+
options[name] = function () {
|
|
721
|
+
initTriggerEvent(this);
|
|
722
|
+
};
|
|
723
|
+
} else {
|
|
724
|
+
options[name] = function (...args) {
|
|
725
|
+
initTriggerEvent(this);
|
|
726
|
+
return oldHook.apply(this, args)
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
if (!MPPage.__$wrappered) {
|
|
731
|
+
MPPage.__$wrappered = true;
|
|
732
|
+
Page = function (options = {}) {
|
|
733
|
+
initHook('onLoad', options);
|
|
734
|
+
return MPPage(options)
|
|
735
|
+
};
|
|
736
|
+
Page.after = MPPage.after;
|
|
737
|
+
|
|
738
|
+
Component = function (options = {}) {
|
|
739
|
+
initHook('created', options);
|
|
740
|
+
return MPComponent(options)
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
const PAGE_EVENT_HOOKS = [
|
|
745
|
+
'onPullDownRefresh',
|
|
746
|
+
'onReachBottom',
|
|
747
|
+
'onAddToFavorites',
|
|
748
|
+
'onShareTimeline',
|
|
749
|
+
'onShareAppMessage',
|
|
750
|
+
'onPageScroll',
|
|
751
|
+
'onResize',
|
|
752
|
+
'onTabItemTap'
|
|
753
|
+
];
|
|
754
|
+
|
|
755
|
+
function initMocks (vm, mocks) {
|
|
756
|
+
const mpInstance = vm.$mp[vm.mpType];
|
|
757
|
+
mocks.forEach(mock => {
|
|
758
|
+
if (hasOwn(mpInstance, mock)) {
|
|
759
|
+
vm[mock] = mpInstance[mock];
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function hasHook (hook, vueOptions) {
|
|
765
|
+
if (!vueOptions) {
|
|
766
|
+
return true
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
if (Vue.options && Array.isArray(Vue.options[hook])) {
|
|
770
|
+
return true
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
vueOptions = vueOptions.default || vueOptions;
|
|
774
|
+
|
|
775
|
+
if (isFn(vueOptions)) {
|
|
776
|
+
if (isFn(vueOptions.extendOptions[hook])) {
|
|
777
|
+
return true
|
|
778
|
+
}
|
|
779
|
+
if (vueOptions.super &&
|
|
780
|
+
vueOptions.super.options &&
|
|
781
|
+
Array.isArray(vueOptions.super.options[hook])) {
|
|
782
|
+
return true
|
|
783
|
+
}
|
|
784
|
+
return false
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
if (isFn(vueOptions[hook])) {
|
|
788
|
+
return true
|
|
789
|
+
}
|
|
790
|
+
const mixins = vueOptions.mixins;
|
|
791
|
+
if (Array.isArray(mixins)) {
|
|
792
|
+
return !!mixins.find(mixin => hasHook(hook, mixin))
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function initHooks (mpOptions, hooks, vueOptions) {
|
|
797
|
+
hooks.forEach(hook => {
|
|
798
|
+
if (hasHook(hook, vueOptions)) {
|
|
799
|
+
mpOptions[hook] = function (args) {
|
|
800
|
+
return this.$vm && this.$vm.__call_hook(hook, args)
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
function initVueComponent (Vue, vueOptions) {
|
|
807
|
+
vueOptions = vueOptions.default || vueOptions;
|
|
808
|
+
let VueComponent;
|
|
809
|
+
if (isFn(vueOptions)) {
|
|
810
|
+
VueComponent = vueOptions;
|
|
811
|
+
} else {
|
|
812
|
+
VueComponent = Vue.extend(vueOptions);
|
|
813
|
+
}
|
|
814
|
+
vueOptions = VueComponent.options;
|
|
815
|
+
return [VueComponent, vueOptions]
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
function initSlots (vm, vueSlots) {
|
|
819
|
+
if (Array.isArray(vueSlots) && vueSlots.length) {
|
|
820
|
+
const $slots = Object.create(null);
|
|
821
|
+
vueSlots.forEach(slotName => {
|
|
822
|
+
$slots[slotName] = true;
|
|
823
|
+
});
|
|
824
|
+
vm.$scopedSlots = vm.$slots = $slots;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
function initVueIds (vueIds, mpInstance) {
|
|
829
|
+
vueIds = (vueIds || '').split(',');
|
|
830
|
+
const len = vueIds.length;
|
|
831
|
+
|
|
832
|
+
if (len === 1) {
|
|
833
|
+
mpInstance._$vueId = vueIds[0];
|
|
834
|
+
} else if (len === 2) {
|
|
835
|
+
mpInstance._$vueId = vueIds[0];
|
|
836
|
+
mpInstance._$vuePid = vueIds[1];
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function initData (vueOptions, context) {
|
|
841
|
+
let data = vueOptions.data || {};
|
|
842
|
+
const methods = vueOptions.methods || {};
|
|
843
|
+
|
|
844
|
+
if (typeof data === 'function') {
|
|
845
|
+
try {
|
|
846
|
+
data = data.call(context); // 支持 Vue.prototype 上挂的数据
|
|
847
|
+
} catch (e) {
|
|
848
|
+
if (process.env.VUE_APP_DEBUG) {
|
|
849
|
+
console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
} else {
|
|
853
|
+
try {
|
|
854
|
+
// 对 data 格式化
|
|
855
|
+
data = JSON.parse(JSON.stringify(data));
|
|
856
|
+
} catch (e) {}
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
if (!isPlainObject(data)) {
|
|
860
|
+
data = {};
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
Object.keys(methods).forEach(methodName => {
|
|
864
|
+
if (context.__lifecycle_hooks__.indexOf(methodName) === -1 && !hasOwn(data, methodName)) {
|
|
865
|
+
data[methodName] = methods[methodName];
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
return data
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
|
|
873
|
+
|
|
874
|
+
function createObserver (name) {
|
|
875
|
+
return function observer (newVal, oldVal) {
|
|
876
|
+
if (this.$vm) {
|
|
877
|
+
this.$vm[name] = newVal; // 为了触发其他非 render watcher
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
function initBehaviors (vueOptions, initBehavior) {
|
|
883
|
+
const vueBehaviors = vueOptions.behaviors;
|
|
884
|
+
const vueExtends = vueOptions.extends;
|
|
885
|
+
const vueMixins = vueOptions.mixins;
|
|
886
|
+
|
|
887
|
+
let vueProps = vueOptions.props;
|
|
888
|
+
|
|
889
|
+
if (!vueProps) {
|
|
890
|
+
vueOptions.props = vueProps = [];
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
const behaviors = [];
|
|
894
|
+
if (Array.isArray(vueBehaviors)) {
|
|
895
|
+
vueBehaviors.forEach(behavior => {
|
|
896
|
+
behaviors.push(behavior.replace('uni://', `${"jd"}://`));
|
|
897
|
+
if (behavior === 'uni://form-field') {
|
|
898
|
+
if (Array.isArray(vueProps)) {
|
|
899
|
+
vueProps.push('name');
|
|
900
|
+
vueProps.push('value');
|
|
901
|
+
} else {
|
|
902
|
+
vueProps.name = {
|
|
903
|
+
type: String,
|
|
904
|
+
default: ''
|
|
905
|
+
};
|
|
906
|
+
vueProps.value = {
|
|
907
|
+
type: [String, Number, Boolean, Array, Object, Date],
|
|
908
|
+
default: ''
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
if (isPlainObject(vueExtends) && vueExtends.props) {
|
|
915
|
+
behaviors.push(
|
|
916
|
+
initBehavior({
|
|
917
|
+
properties: initProperties(vueExtends.props, true)
|
|
918
|
+
})
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
if (Array.isArray(vueMixins)) {
|
|
922
|
+
vueMixins.forEach(vueMixin => {
|
|
923
|
+
if (isPlainObject(vueMixin) && vueMixin.props) {
|
|
924
|
+
behaviors.push(
|
|
925
|
+
initBehavior({
|
|
926
|
+
properties: initProperties(vueMixin.props, true)
|
|
927
|
+
})
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
return behaviors
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
function parsePropType (key, type, defaultValue, file) {
|
|
936
|
+
// [String]=>String
|
|
937
|
+
if (Array.isArray(type) && type.length === 1) {
|
|
938
|
+
return type[0]
|
|
939
|
+
}
|
|
940
|
+
return type
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function initProperties (props, isBehavior = false, file = '') {
|
|
944
|
+
const properties = {};
|
|
945
|
+
if (!isBehavior) {
|
|
946
|
+
properties.vueId = {
|
|
947
|
+
type: String,
|
|
948
|
+
value: ''
|
|
949
|
+
};
|
|
950
|
+
// 用于字节跳动小程序模拟抽象节点
|
|
951
|
+
properties.generic = {
|
|
952
|
+
type: Object,
|
|
953
|
+
value: null
|
|
954
|
+
};
|
|
955
|
+
// scopedSlotsCompiler auto
|
|
956
|
+
properties.scopedSlotsCompiler = {
|
|
957
|
+
type: String,
|
|
958
|
+
value: ''
|
|
959
|
+
};
|
|
960
|
+
properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
|
|
961
|
+
type: null,
|
|
962
|
+
value: [],
|
|
963
|
+
observer: function (newVal, oldVal) {
|
|
964
|
+
const $slots = Object.create(null);
|
|
965
|
+
newVal.forEach(slotName => {
|
|
966
|
+
$slots[slotName] = true;
|
|
967
|
+
});
|
|
968
|
+
this.setData({
|
|
969
|
+
$slots
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
if (Array.isArray(props)) { // ['title']
|
|
975
|
+
props.forEach(key => {
|
|
976
|
+
properties[key] = {
|
|
977
|
+
type: null,
|
|
978
|
+
observer: createObserver(key)
|
|
979
|
+
};
|
|
980
|
+
});
|
|
981
|
+
} else if (isPlainObject(props)) { // {title:{type:String,default:''},content:String}
|
|
982
|
+
Object.keys(props).forEach(key => {
|
|
983
|
+
const opts = props[key];
|
|
984
|
+
if (isPlainObject(opts)) { // title:{type:String,default:''}
|
|
985
|
+
let value = opts.default;
|
|
986
|
+
if (isFn(value)) {
|
|
987
|
+
value = value();
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
opts.type = parsePropType(key, opts.type);
|
|
991
|
+
|
|
992
|
+
properties[key] = {
|
|
993
|
+
type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
|
|
994
|
+
value,
|
|
995
|
+
observer: createObserver(key)
|
|
996
|
+
};
|
|
997
|
+
} else { // content:String
|
|
998
|
+
const type = parsePropType(key, opts);
|
|
999
|
+
properties[key] = {
|
|
1000
|
+
type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
|
|
1001
|
+
observer: createObserver(key)
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
return properties
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function wrapper$1 (event) {
|
|
1010
|
+
// TODO 又得兼容 mpvue 的 mp 对象
|
|
1011
|
+
try {
|
|
1012
|
+
event.mp = JSON.parse(JSON.stringify(event));
|
|
1013
|
+
} catch (e) {}
|
|
1014
|
+
|
|
1015
|
+
event.stopPropagation = noop;
|
|
1016
|
+
event.preventDefault = noop;
|
|
1017
|
+
|
|
1018
|
+
event.target = event.target || {};
|
|
1019
|
+
|
|
1020
|
+
if (!hasOwn(event, 'detail')) {
|
|
1021
|
+
event.detail = {};
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
if (hasOwn(event, 'markerId')) {
|
|
1025
|
+
event.detail = typeof event.detail === 'object' ? event.detail : {};
|
|
1026
|
+
event.detail.markerId = event.markerId;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
if (isPlainObject(event.detail)) {
|
|
1030
|
+
event.target = Object.assign({}, event.target, event.detail);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
return event
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
function getExtraValue (vm, dataPathsArray) {
|
|
1037
|
+
let context = vm;
|
|
1038
|
+
dataPathsArray.forEach(dataPathArray => {
|
|
1039
|
+
const dataPath = dataPathArray[0];
|
|
1040
|
+
const value = dataPathArray[2];
|
|
1041
|
+
if (dataPath || typeof value !== 'undefined') { // ['','',index,'disable']
|
|
1042
|
+
const propPath = dataPathArray[1];
|
|
1043
|
+
const valuePath = dataPathArray[3];
|
|
1044
|
+
|
|
1045
|
+
let vFor;
|
|
1046
|
+
if (Number.isInteger(dataPath)) {
|
|
1047
|
+
vFor = dataPath;
|
|
1048
|
+
} else if (!dataPath) {
|
|
1049
|
+
vFor = context;
|
|
1050
|
+
} else if (typeof dataPath === 'string' && dataPath) {
|
|
1051
|
+
if (dataPath.indexOf('#s#') === 0) {
|
|
1052
|
+
vFor = dataPath.substr(3);
|
|
1053
|
+
} else {
|
|
1054
|
+
vFor = vm.__get_value(dataPath, context);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
if (Number.isInteger(vFor)) {
|
|
1059
|
+
context = value;
|
|
1060
|
+
} else if (!propPath) {
|
|
1061
|
+
context = vFor[value];
|
|
1062
|
+
} else {
|
|
1063
|
+
if (Array.isArray(vFor)) {
|
|
1064
|
+
context = vFor.find(vForItem => {
|
|
1065
|
+
return vm.__get_value(propPath, vForItem) === value
|
|
1066
|
+
});
|
|
1067
|
+
} else if (isPlainObject(vFor)) {
|
|
1068
|
+
context = Object.keys(vFor).find(vForKey => {
|
|
1069
|
+
return vm.__get_value(propPath, vFor[vForKey]) === value
|
|
1070
|
+
});
|
|
1071
|
+
} else {
|
|
1072
|
+
console.error('v-for 暂不支持循环数据:', vFor);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
if (valuePath) {
|
|
1077
|
+
context = vm.__get_value(valuePath, context);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
return context
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function processEventExtra (vm, extra, event) {
|
|
1085
|
+
const extraObj = {};
|
|
1086
|
+
|
|
1087
|
+
if (Array.isArray(extra) && extra.length) {
|
|
1088
|
+
/**
|
|
1089
|
+
*[
|
|
1090
|
+
* ['data.items', 'data.id', item.data.id],
|
|
1091
|
+
* ['metas', 'id', meta.id]
|
|
1092
|
+
*],
|
|
1093
|
+
*[
|
|
1094
|
+
* ['data.items', 'data.id', item.data.id],
|
|
1095
|
+
* ['metas', 'id', meta.id]
|
|
1096
|
+
*],
|
|
1097
|
+
*'test'
|
|
1098
|
+
*/
|
|
1099
|
+
extra.forEach((dataPath, index) => {
|
|
1100
|
+
if (typeof dataPath === 'string') {
|
|
1101
|
+
if (!dataPath) { // model,prop.sync
|
|
1102
|
+
extraObj['$' + index] = vm;
|
|
1103
|
+
} else {
|
|
1104
|
+
if (dataPath === '$event') { // $event
|
|
1105
|
+
extraObj['$' + index] = event;
|
|
1106
|
+
} else if (dataPath === 'arguments') {
|
|
1107
|
+
if (event.detail && event.detail.__args__) {
|
|
1108
|
+
extraObj['$' + index] = event.detail.__args__;
|
|
1109
|
+
} else {
|
|
1110
|
+
extraObj['$' + index] = [event];
|
|
1111
|
+
}
|
|
1112
|
+
} else if (dataPath.indexOf('$event.') === 0) { // $event.target.value
|
|
1113
|
+
extraObj['$' + index] = vm.__get_value(dataPath.replace('$event.', ''), event);
|
|
1114
|
+
} else {
|
|
1115
|
+
extraObj['$' + index] = vm.__get_value(dataPath);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
} else {
|
|
1119
|
+
extraObj['$' + index] = getExtraValue(vm, dataPath);
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
return extraObj
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function getObjByArray (arr) {
|
|
1128
|
+
const obj = {};
|
|
1129
|
+
for (let i = 1; i < arr.length; i++) {
|
|
1130
|
+
const element = arr[i];
|
|
1131
|
+
obj[element[0]] = element[1];
|
|
1132
|
+
}
|
|
1133
|
+
return obj
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
function processEventArgs (vm, event, args = [], extra = [], isCustom, methodName) {
|
|
1137
|
+
let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
|
|
1138
|
+
if (isCustom) { // 自定义事件
|
|
1139
|
+
isCustomMPEvent = event.currentTarget &&
|
|
1140
|
+
event.currentTarget.dataset &&
|
|
1141
|
+
event.currentTarget.dataset.comType === 'wx';
|
|
1142
|
+
if (!args.length) { // 无参数,直接传入 event 或 detail 数组
|
|
1143
|
+
if (isCustomMPEvent) {
|
|
1144
|
+
return [event]
|
|
1145
|
+
}
|
|
1146
|
+
return event.detail.__args__ || event.detail
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
const extraObj = processEventExtra(vm, extra, event);
|
|
1151
|
+
|
|
1152
|
+
const ret = [];
|
|
1153
|
+
args.forEach(arg => {
|
|
1154
|
+
if (arg === '$event') {
|
|
1155
|
+
if (methodName === '__set_model' && !isCustom) { // input v-model value
|
|
1156
|
+
ret.push(event.target.value);
|
|
1157
|
+
} else {
|
|
1158
|
+
if (isCustom && !isCustomMPEvent) {
|
|
1159
|
+
ret.push(event.detail.__args__[0]);
|
|
1160
|
+
} else { // wxcomponent 组件或内置组件
|
|
1161
|
+
ret.push(event);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
} else {
|
|
1165
|
+
if (Array.isArray(arg) && arg[0] === 'o') {
|
|
1166
|
+
ret.push(getObjByArray(arg));
|
|
1167
|
+
} else if (typeof arg === 'string' && hasOwn(extraObj, arg)) {
|
|
1168
|
+
ret.push(extraObj[arg]);
|
|
1169
|
+
} else {
|
|
1170
|
+
ret.push(arg);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
return ret
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
const ONCE = '~';
|
|
1179
|
+
const CUSTOM = '^';
|
|
1180
|
+
|
|
1181
|
+
function isMatchEventType (eventType, optType) {
|
|
1182
|
+
return (eventType === optType) ||
|
|
1183
|
+
(
|
|
1184
|
+
optType === 'regionchange' &&
|
|
1185
|
+
(
|
|
1186
|
+
eventType === 'begin' ||
|
|
1187
|
+
eventType === 'end'
|
|
1188
|
+
)
|
|
1189
|
+
)
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
function getContextVm (vm) {
|
|
1193
|
+
let $parent = vm.$parent;
|
|
1194
|
+
// 父组件是 scoped slots 或者其他自定义组件时继续查找
|
|
1195
|
+
while ($parent && $parent.$parent && ($parent.$options.generic || $parent.$parent.$options.generic || $parent.$scope._$vuePid)) {
|
|
1196
|
+
$parent = $parent.$parent;
|
|
1197
|
+
}
|
|
1198
|
+
return $parent && $parent.$parent
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
function handleEvent (event) {
|
|
1202
|
+
event = wrapper$1(event);
|
|
1203
|
+
|
|
1204
|
+
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
|
|
1205
|
+
const dataset = (event.currentTarget || event.target).dataset;
|
|
1206
|
+
if (!dataset) {
|
|
1207
|
+
return console.warn('事件信息不存在')
|
|
1208
|
+
}
|
|
1209
|
+
const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
|
|
1210
|
+
if (!eventOpts) {
|
|
1211
|
+
return console.warn('事件信息不存在')
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
|
|
1215
|
+
const eventType = event.type;
|
|
1216
|
+
|
|
1217
|
+
const ret = [];
|
|
1218
|
+
|
|
1219
|
+
eventOpts.forEach(eventOpt => {
|
|
1220
|
+
let type = eventOpt[0];
|
|
1221
|
+
const eventsArray = eventOpt[1];
|
|
1222
|
+
|
|
1223
|
+
const isCustom = type.charAt(0) === CUSTOM;
|
|
1224
|
+
type = isCustom ? type.slice(1) : type;
|
|
1225
|
+
const isOnce = type.charAt(0) === ONCE;
|
|
1226
|
+
type = isOnce ? type.slice(1) : type;
|
|
1227
|
+
|
|
1228
|
+
if (eventsArray && isMatchEventType(eventType, type)) {
|
|
1229
|
+
eventsArray.forEach(eventArray => {
|
|
1230
|
+
const methodName = eventArray[0];
|
|
1231
|
+
if (methodName) {
|
|
1232
|
+
let handlerCtx = this.$vm;
|
|
1233
|
+
if (handlerCtx.$options.generic) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
|
|
1234
|
+
handlerCtx = getContextVm(handlerCtx) || handlerCtx;
|
|
1235
|
+
}
|
|
1236
|
+
if (methodName === '$emit') {
|
|
1237
|
+
handlerCtx.$emit.apply(handlerCtx,
|
|
1238
|
+
processEventArgs(
|
|
1239
|
+
this.$vm,
|
|
1240
|
+
event,
|
|
1241
|
+
eventArray[1],
|
|
1242
|
+
eventArray[2],
|
|
1243
|
+
isCustom,
|
|
1244
|
+
methodName
|
|
1245
|
+
));
|
|
1246
|
+
return
|
|
1247
|
+
}
|
|
1248
|
+
const handler = handlerCtx[methodName];
|
|
1249
|
+
if (!isFn(handler)) {
|
|
1250
|
+
throw new Error(` _vm.${methodName} is not a function`)
|
|
1251
|
+
}
|
|
1252
|
+
if (isOnce) {
|
|
1253
|
+
if (handler.once) {
|
|
1254
|
+
return
|
|
1255
|
+
}
|
|
1256
|
+
handler.once = true;
|
|
1257
|
+
}
|
|
1258
|
+
let params = processEventArgs(
|
|
1259
|
+
this.$vm,
|
|
1260
|
+
event,
|
|
1261
|
+
eventArray[1],
|
|
1262
|
+
eventArray[2],
|
|
1263
|
+
isCustom,
|
|
1264
|
+
methodName
|
|
1265
|
+
);
|
|
1266
|
+
params = Array.isArray(params) ? params : [];
|
|
1267
|
+
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
|
|
1268
|
+
if (/=\s*\S+\.eventParams\s*\|\|\s*\S+\[['"]event-params['"]\]/.test(handler.toString())) {
|
|
1269
|
+
// eslint-disable-next-line no-sparse-arrays
|
|
1270
|
+
params = params.concat([, , , , , , , , , , event]);
|
|
1271
|
+
}
|
|
1272
|
+
ret.push(handler.apply(handlerCtx, params));
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
if (
|
|
1279
|
+
eventType === 'input' &&
|
|
1280
|
+
ret.length === 1 &&
|
|
1281
|
+
typeof ret[0] !== 'undefined'
|
|
1282
|
+
) {
|
|
1283
|
+
return ret[0]
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
const messages = {};
|
|
1288
|
+
|
|
1289
|
+
let locale;
|
|
1290
|
+
|
|
1291
|
+
{
|
|
1292
|
+
locale = jd.getSystemInfoSync().language;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
function initI18nMessages () {
|
|
1296
|
+
if (!isEnableLocale()) {
|
|
1297
|
+
return
|
|
1298
|
+
}
|
|
1299
|
+
const localeKeys = Object.keys(__uniConfig.locales);
|
|
1300
|
+
if (localeKeys.length) {
|
|
1301
|
+
localeKeys.forEach((locale) => {
|
|
1302
|
+
const curMessages = messages[locale];
|
|
1303
|
+
const userMessages = __uniConfig.locales[locale];
|
|
1304
|
+
if (curMessages) {
|
|
1305
|
+
Object.assign(curMessages, userMessages);
|
|
1306
|
+
} else {
|
|
1307
|
+
messages[locale] = userMessages;
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
initI18nMessages();
|
|
1314
|
+
|
|
1315
|
+
const i18n = initVueI18n(
|
|
1316
|
+
locale,
|
|
1317
|
+
{}
|
|
1318
|
+
);
|
|
1319
|
+
const t = i18n.t;
|
|
1320
|
+
const i18nMixin = (i18n.mixin = {
|
|
1321
|
+
beforeCreate () {
|
|
1322
|
+
const unwatch = i18n.i18n.watchLocale(() => {
|
|
1323
|
+
this.$forceUpdate();
|
|
1324
|
+
});
|
|
1325
|
+
this.$once('hook:beforeDestroy', function () {
|
|
1326
|
+
unwatch();
|
|
1327
|
+
});
|
|
1328
|
+
},
|
|
1329
|
+
methods: {
|
|
1330
|
+
$$t (key, values) {
|
|
1331
|
+
return t(key, values)
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
const setLocale$1 = i18n.setLocale;
|
|
1336
|
+
const getLocale$1 = i18n.getLocale;
|
|
1337
|
+
|
|
1338
|
+
function initAppLocale (Vue, appVm, locale) {
|
|
1339
|
+
const state = Vue.observable({
|
|
1340
|
+
locale: locale || i18n.getLocale()
|
|
1341
|
+
});
|
|
1342
|
+
const localeWatchers = [];
|
|
1343
|
+
appVm.$watchLocale = fn => {
|
|
1344
|
+
localeWatchers.push(fn);
|
|
1345
|
+
};
|
|
1346
|
+
Object.defineProperty(appVm, '$locale', {
|
|
1347
|
+
get () {
|
|
1348
|
+
return state.locale
|
|
1349
|
+
},
|
|
1350
|
+
set (v) {
|
|
1351
|
+
state.locale = v;
|
|
1352
|
+
localeWatchers.forEach(watch => watch(v));
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
function isEnableLocale () {
|
|
1358
|
+
return typeof __uniConfig !== 'undefined' && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
// export function initI18n() {
|
|
1362
|
+
// const localeKeys = Object.keys(__uniConfig.locales || {})
|
|
1363
|
+
// if (localeKeys.length) {
|
|
1364
|
+
// localeKeys.forEach((locale) =>
|
|
1365
|
+
// i18n.add(locale, __uniConfig.locales[locale])
|
|
1366
|
+
// )
|
|
1367
|
+
// }
|
|
1368
|
+
// }
|
|
1369
|
+
|
|
1370
|
+
class EventChannel {
|
|
1371
|
+
constructor (id, events) {
|
|
1372
|
+
this.id = id;
|
|
1373
|
+
this.listener = {};
|
|
1374
|
+
this.emitCache = {};
|
|
1375
|
+
if (events) {
|
|
1376
|
+
Object.keys(events).forEach(name => {
|
|
1377
|
+
this.on(name, events[name]);
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
emit (eventName, ...args) {
|
|
1383
|
+
const fns = this.listener[eventName];
|
|
1384
|
+
if (!fns) {
|
|
1385
|
+
return (this.emitCache[eventName] || (this.emitCache[eventName] = [])).push(args)
|
|
1386
|
+
}
|
|
1387
|
+
fns.forEach(opt => {
|
|
1388
|
+
opt.fn.apply(opt.fn, args);
|
|
1389
|
+
});
|
|
1390
|
+
this.listener[eventName] = fns.filter(opt => opt.type !== 'once');
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
on (eventName, fn) {
|
|
1394
|
+
this._addListener(eventName, 'on', fn);
|
|
1395
|
+
this._clearCache(eventName);
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
once (eventName, fn) {
|
|
1399
|
+
this._addListener(eventName, 'once', fn);
|
|
1400
|
+
this._clearCache(eventName);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
off (eventName, fn) {
|
|
1404
|
+
const fns = this.listener[eventName];
|
|
1405
|
+
if (!fns) {
|
|
1406
|
+
return
|
|
1407
|
+
}
|
|
1408
|
+
if (fn) {
|
|
1409
|
+
for (let i = 0; i < fns.length;) {
|
|
1410
|
+
if (fns[i].fn === fn) {
|
|
1411
|
+
fns.splice(i, 1);
|
|
1412
|
+
i--;
|
|
1413
|
+
}
|
|
1414
|
+
i++;
|
|
1415
|
+
}
|
|
1416
|
+
} else {
|
|
1417
|
+
delete this.listener[eventName];
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
_clearCache (eventName) {
|
|
1422
|
+
const cacheArgs = this.emitCache[eventName];
|
|
1423
|
+
if (cacheArgs) {
|
|
1424
|
+
for (; cacheArgs.length > 0;) {
|
|
1425
|
+
this.emit.apply(this, [eventName].concat(cacheArgs.shift()));
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
_addListener (eventName, type, fn) {
|
|
1431
|
+
(this.listener[eventName] || (this.listener[eventName] = [])).push({
|
|
1432
|
+
fn,
|
|
1433
|
+
type
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
const eventChannels = {};
|
|
1439
|
+
|
|
1440
|
+
const eventChannelStack = [];
|
|
1441
|
+
|
|
1442
|
+
function getEventChannel (id) {
|
|
1443
|
+
if (id) {
|
|
1444
|
+
const eventChannel = eventChannels[id];
|
|
1445
|
+
delete eventChannels[id];
|
|
1446
|
+
return eventChannel
|
|
1447
|
+
}
|
|
1448
|
+
return eventChannelStack.shift()
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
const hooks = [
|
|
1452
|
+
'onShow',
|
|
1453
|
+
'onHide',
|
|
1454
|
+
'onError',
|
|
1455
|
+
'onPageNotFound',
|
|
1456
|
+
'onThemeChange',
|
|
1457
|
+
'onUnhandledRejection'
|
|
1458
|
+
];
|
|
1459
|
+
|
|
1460
|
+
function initEventChannel () {
|
|
1461
|
+
Vue.prototype.getOpenerEventChannel = function () {
|
|
1462
|
+
if (!this.__eventChannel__) {
|
|
1463
|
+
this.__eventChannel__ = new EventChannel();
|
|
1464
|
+
}
|
|
1465
|
+
return this.__eventChannel__
|
|
1466
|
+
};
|
|
1467
|
+
const callHook = Vue.prototype.__call_hook;
|
|
1468
|
+
Vue.prototype.__call_hook = function (hook, args) {
|
|
1469
|
+
if (hook === 'onLoad' && args && args.__id__) {
|
|
1470
|
+
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1471
|
+
delete args.__id__;
|
|
1472
|
+
}
|
|
1473
|
+
return callHook.call(this, hook, args)
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
function initScopedSlotsParams () {
|
|
1478
|
+
const center = {};
|
|
1479
|
+
const parents = {};
|
|
1480
|
+
|
|
1481
|
+
Vue.prototype.$hasScopedSlotsParams = function (vueId) {
|
|
1482
|
+
const has = center[vueId];
|
|
1483
|
+
if (!has) {
|
|
1484
|
+
parents[vueId] = this;
|
|
1485
|
+
this.$on('hook:destroyed', () => {
|
|
1486
|
+
delete parents[vueId];
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
return has
|
|
1490
|
+
};
|
|
1491
|
+
|
|
1492
|
+
Vue.prototype.$getScopedSlotsParams = function (vueId, name, key) {
|
|
1493
|
+
const data = center[vueId];
|
|
1494
|
+
if (data) {
|
|
1495
|
+
const object = data[name] || {};
|
|
1496
|
+
return key ? object[key] : object
|
|
1497
|
+
} else {
|
|
1498
|
+
parents[vueId] = this;
|
|
1499
|
+
this.$on('hook:destroyed', () => {
|
|
1500
|
+
delete parents[vueId];
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1505
|
+
Vue.prototype.$setScopedSlotsParams = function (name, value) {
|
|
1506
|
+
const vueIds = this.$options.propsData.vueId;
|
|
1507
|
+
if (vueIds) {
|
|
1508
|
+
const vueId = vueIds.split(',')[0];
|
|
1509
|
+
const object = center[vueId] = center[vueId] || {};
|
|
1510
|
+
object[name] = value;
|
|
1511
|
+
if (parents[vueId]) {
|
|
1512
|
+
parents[vueId].$forceUpdate();
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
|
|
1517
|
+
Vue.mixin({
|
|
1518
|
+
destroyed () {
|
|
1519
|
+
const propsData = this.$options.propsData;
|
|
1520
|
+
const vueId = propsData && propsData.vueId;
|
|
1521
|
+
if (vueId) {
|
|
1522
|
+
delete center[vueId];
|
|
1523
|
+
delete parents[vueId];
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
function parseBaseApp (vm, {
|
|
1530
|
+
mocks,
|
|
1531
|
+
initRefs
|
|
1532
|
+
}) {
|
|
1533
|
+
initEventChannel();
|
|
1534
|
+
{
|
|
1535
|
+
initScopedSlotsParams();
|
|
1536
|
+
}
|
|
1537
|
+
if (vm.$options.store) {
|
|
1538
|
+
Vue.prototype.$store = vm.$options.store;
|
|
1539
|
+
}
|
|
1540
|
+
uniIdMixin(Vue);
|
|
1541
|
+
|
|
1542
|
+
Vue.prototype.mpHost = "mp-jd";
|
|
1543
|
+
|
|
1544
|
+
Vue.mixin({
|
|
1545
|
+
beforeCreate () {
|
|
1546
|
+
if (!this.$options.mpType) {
|
|
1547
|
+
return
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
this.mpType = this.$options.mpType;
|
|
1551
|
+
|
|
1552
|
+
this.$mp = {
|
|
1553
|
+
data: {},
|
|
1554
|
+
[this.mpType]: this.$options.mpInstance
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
this.$scope = this.$options.mpInstance;
|
|
1558
|
+
|
|
1559
|
+
delete this.$options.mpType;
|
|
1560
|
+
delete this.$options.mpInstance;
|
|
1561
|
+
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
|
|
1562
|
+
const app = getApp();
|
|
1563
|
+
if (app.$vm && app.$vm.$i18n) {
|
|
1564
|
+
this._i18n = app.$vm.$i18n;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
if (this.mpType !== 'app') {
|
|
1568
|
+
initRefs(this);
|
|
1569
|
+
initMocks(this, mocks);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
|
|
1574
|
+
const appOptions = {
|
|
1575
|
+
onLaunch (args) {
|
|
1576
|
+
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1577
|
+
return
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
this.$vm = vm;
|
|
1581
|
+
|
|
1582
|
+
this.$vm.$mp = {
|
|
1583
|
+
app: this
|
|
1584
|
+
};
|
|
1585
|
+
|
|
1586
|
+
this.$vm.$scope = this;
|
|
1587
|
+
// vm 上也挂载 globalData
|
|
1588
|
+
this.$vm.globalData = this.globalData;
|
|
1589
|
+
|
|
1590
|
+
this.$vm._isMounted = true;
|
|
1591
|
+
this.$vm.__call_hook('mounted', args);
|
|
1592
|
+
|
|
1593
|
+
this.$vm.__call_hook('onLaunch', args);
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
|
|
1597
|
+
// 兼容旧版本 globalData
|
|
1598
|
+
appOptions.globalData = vm.$options.globalData || {};
|
|
1599
|
+
// 将 methods 中的方法挂在 getApp() 中
|
|
1600
|
+
const methods = vm.$options.methods;
|
|
1601
|
+
if (methods) {
|
|
1602
|
+
Object.keys(methods).forEach(name => {
|
|
1603
|
+
appOptions[name] = methods[name];
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
initAppLocale(Vue, vm, jd.getSystemInfoSync().language || 'zh-Hans');
|
|
1608
|
+
|
|
1609
|
+
initHooks(appOptions, hooks);
|
|
1610
|
+
|
|
1611
|
+
return appOptions
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
const mocks = ['__route__', '__wxExparserNodeId__', '__wxWebviewId__'];
|
|
1615
|
+
|
|
1616
|
+
function findVmByVueId (vm, vuePid) {
|
|
1617
|
+
const $children = vm.$children;
|
|
1618
|
+
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
|
|
1619
|
+
for (let i = $children.length - 1; i >= 0; i--) {
|
|
1620
|
+
const childVm = $children[i];
|
|
1621
|
+
if (childVm.$scope._$vueId === vuePid) {
|
|
1622
|
+
return childVm
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
// 反向递归查找
|
|
1626
|
+
let parentVm;
|
|
1627
|
+
for (let i = $children.length - 1; i >= 0; i--) {
|
|
1628
|
+
parentVm = findVmByVueId($children[i], vuePid);
|
|
1629
|
+
if (parentVm) {
|
|
1630
|
+
return parentVm
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
function initBehavior (options) {
|
|
1636
|
+
return Behavior(options)
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
function isPage () {
|
|
1640
|
+
return !!this.route
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
function initRelation (detail) {
|
|
1644
|
+
this.triggerEvent('__l', detail);
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
function selectAllComponents (mpInstance, selector, $refs) {
|
|
1648
|
+
const components = mpInstance.selectAllComponents(selector);
|
|
1649
|
+
components.forEach(component => {
|
|
1650
|
+
const ref = component.dataset.ref;
|
|
1651
|
+
$refs[ref] = component.$vm || component;
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
function initRefs (vm) {
|
|
1656
|
+
const mpInstance = vm.$scope;
|
|
1657
|
+
Object.defineProperty(vm, '$refs', {
|
|
1658
|
+
get () {
|
|
1659
|
+
const $refs = {};
|
|
1660
|
+
selectAllComponents(mpInstance, '.vue-ref', $refs);
|
|
1661
|
+
// TODO 暂不考虑 for 中的 scoped
|
|
1662
|
+
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
|
|
1663
|
+
forComponents.forEach(component => {
|
|
1664
|
+
const ref = component.dataset.ref;
|
|
1665
|
+
if (!$refs[ref]) {
|
|
1666
|
+
$refs[ref] = [];
|
|
1667
|
+
}
|
|
1668
|
+
$refs[ref].push(component.$vm || component);
|
|
1669
|
+
});
|
|
1670
|
+
return $refs
|
|
1671
|
+
}
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
function handleLink (event) {
|
|
1676
|
+
const {
|
|
1677
|
+
vuePid,
|
|
1678
|
+
vueOptions
|
|
1679
|
+
} = event.detail || event.value; // detail 是微信,value 是百度(dipatch)
|
|
1680
|
+
|
|
1681
|
+
let parentVm;
|
|
1682
|
+
|
|
1683
|
+
if (vuePid) {
|
|
1684
|
+
parentVm = findVmByVueId(this.$vm, vuePid);
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
if (!parentVm) {
|
|
1688
|
+
parentVm = this.$vm;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
vueOptions.parent = parentVm;
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
function parseApp (vm) {
|
|
1695
|
+
return parseBaseApp(vm, {
|
|
1696
|
+
mocks,
|
|
1697
|
+
initRefs
|
|
1698
|
+
})
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
function parseApp$1 (vm) {
|
|
1702
|
+
return parseApp(vm)
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
function createApp (vm) {
|
|
1706
|
+
App(parseApp$1(vm));
|
|
1707
|
+
return vm
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
const encodeReserveRE = /[!'()*]/g;
|
|
1711
|
+
const encodeReserveReplacer = c => '%' + c.charCodeAt(0).toString(16);
|
|
1712
|
+
const commaRE = /%2C/g;
|
|
1713
|
+
|
|
1714
|
+
// fixed encodeURIComponent which is more conformant to RFC3986:
|
|
1715
|
+
// - escapes [!'()*]
|
|
1716
|
+
// - preserve commas
|
|
1717
|
+
const encode = str => encodeURIComponent(str)
|
|
1718
|
+
.replace(encodeReserveRE, encodeReserveReplacer)
|
|
1719
|
+
.replace(commaRE, ',');
|
|
1720
|
+
|
|
1721
|
+
function stringifyQuery (obj, encodeStr = encode) {
|
|
1722
|
+
const res = obj ? Object.keys(obj).map(key => {
|
|
1723
|
+
const val = obj[key];
|
|
1724
|
+
|
|
1725
|
+
if (val === undefined) {
|
|
1726
|
+
return ''
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
if (val === null) {
|
|
1730
|
+
return encodeStr(key)
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
if (Array.isArray(val)) {
|
|
1734
|
+
const result = [];
|
|
1735
|
+
val.forEach(val2 => {
|
|
1736
|
+
if (val2 === undefined) {
|
|
1737
|
+
return
|
|
1738
|
+
}
|
|
1739
|
+
if (val2 === null) {
|
|
1740
|
+
result.push(encodeStr(key));
|
|
1741
|
+
} else {
|
|
1742
|
+
result.push(encodeStr(key) + '=' + encodeStr(val2));
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
return result.join('&')
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
return encodeStr(key) + '=' + encodeStr(val)
|
|
1749
|
+
}).filter(x => x.length > 0).join('&') : null;
|
|
1750
|
+
return res ? `?${res}` : ''
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
function parseBaseComponent (vueComponentOptions, {
|
|
1754
|
+
isPage,
|
|
1755
|
+
initRelation
|
|
1756
|
+
} = {}) {
|
|
1757
|
+
const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
|
|
1758
|
+
|
|
1759
|
+
const options = {
|
|
1760
|
+
multipleSlots: true,
|
|
1761
|
+
addGlobalClass: true,
|
|
1762
|
+
...(vueOptions.options || {})
|
|
1763
|
+
};
|
|
1764
|
+
|
|
1765
|
+
const componentOptions = {
|
|
1766
|
+
options,
|
|
1767
|
+
data: initData(vueOptions, Vue.prototype),
|
|
1768
|
+
behaviors: initBehaviors(vueOptions, initBehavior),
|
|
1769
|
+
properties: initProperties(vueOptions.props, false, vueOptions.__file),
|
|
1770
|
+
lifetimes: {
|
|
1771
|
+
attached () {
|
|
1772
|
+
const properties = this.properties;
|
|
1773
|
+
|
|
1774
|
+
const options = {
|
|
1775
|
+
mpType: isPage.call(this) ? 'page' : 'component',
|
|
1776
|
+
mpInstance: this,
|
|
1777
|
+
propsData: properties
|
|
1778
|
+
};
|
|
1779
|
+
|
|
1780
|
+
initVueIds(properties.vueId, this);
|
|
1781
|
+
|
|
1782
|
+
// 处理父子关系
|
|
1783
|
+
initRelation.call(this, {
|
|
1784
|
+
vuePid: this._$vuePid,
|
|
1785
|
+
vueOptions: options
|
|
1786
|
+
});
|
|
1787
|
+
|
|
1788
|
+
// 初始化 vue 实例
|
|
1789
|
+
this.$vm = new VueComponent(options);
|
|
1790
|
+
|
|
1791
|
+
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
|
|
1792
|
+
initSlots(this.$vm, properties.vueSlots);
|
|
1793
|
+
|
|
1794
|
+
// 触发首次 setData
|
|
1795
|
+
this.$vm.$mount();
|
|
1796
|
+
},
|
|
1797
|
+
ready () {
|
|
1798
|
+
// 当组件 props 默认值为 true,初始化时传入 false 会导致 created,ready 触发, 但 attached 不触发
|
|
1799
|
+
// https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800
|
|
1800
|
+
if (this.$vm) {
|
|
1801
|
+
this.$vm._isMounted = true;
|
|
1802
|
+
this.$vm.__call_hook('mounted');
|
|
1803
|
+
this.$vm.__call_hook('onReady');
|
|
1804
|
+
}
|
|
1805
|
+
},
|
|
1806
|
+
detached () {
|
|
1807
|
+
this.$vm && this.$vm.$destroy();
|
|
1808
|
+
}
|
|
1809
|
+
},
|
|
1810
|
+
pageLifetimes: {
|
|
1811
|
+
show (args) {
|
|
1812
|
+
this.$vm && this.$vm.__call_hook('onPageShow', args);
|
|
1813
|
+
},
|
|
1814
|
+
hide () {
|
|
1815
|
+
this.$vm && this.$vm.__call_hook('onPageHide');
|
|
1816
|
+
},
|
|
1817
|
+
resize (size) {
|
|
1818
|
+
this.$vm && this.$vm.__call_hook('onPageResize', size);
|
|
1819
|
+
}
|
|
1820
|
+
},
|
|
1821
|
+
methods: {
|
|
1822
|
+
__l: handleLink,
|
|
1823
|
+
__e: handleEvent
|
|
1824
|
+
}
|
|
1825
|
+
};
|
|
1826
|
+
// externalClasses
|
|
1827
|
+
if (vueOptions.externalClasses) {
|
|
1828
|
+
componentOptions.externalClasses = vueOptions.externalClasses;
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
if (Array.isArray(vueOptions.wxsCallMethods)) {
|
|
1832
|
+
vueOptions.wxsCallMethods.forEach(callMethod => {
|
|
1833
|
+
componentOptions.methods[callMethod] = function (args) {
|
|
1834
|
+
return this.$vm[callMethod](args)
|
|
1835
|
+
};
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
if (isPage) {
|
|
1840
|
+
return componentOptions
|
|
1841
|
+
}
|
|
1842
|
+
return [componentOptions, VueComponent]
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
function parseComponent (vueComponentOptions) {
|
|
1846
|
+
return parseBaseComponent(vueComponentOptions, {
|
|
1847
|
+
isPage,
|
|
1848
|
+
initRelation
|
|
1849
|
+
})
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
function parseComponent$1 (vueComponentOptions) {
|
|
1853
|
+
const componentOptions = parseComponent(vueComponentOptions);
|
|
1854
|
+
// 京东小程序 lifetimes 存在兼容问题
|
|
1855
|
+
const lifetimes = componentOptions.lifetimes;
|
|
1856
|
+
Object.keys(lifetimes).forEach(key => {
|
|
1857
|
+
componentOptions[key] = lifetimes[key];
|
|
1858
|
+
});
|
|
1859
|
+
return componentOptions
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
const hooks$1 = [
|
|
1863
|
+
'onShow',
|
|
1864
|
+
'onHide',
|
|
1865
|
+
'onUnload'
|
|
1866
|
+
];
|
|
1867
|
+
|
|
1868
|
+
hooks$1.push(...PAGE_EVENT_HOOKS);
|
|
1869
|
+
|
|
1870
|
+
function parseBasePage (vuePageOptions, {
|
|
1871
|
+
isPage,
|
|
1872
|
+
initRelation
|
|
1873
|
+
}) {
|
|
1874
|
+
const pageOptions = parseComponent$1(vuePageOptions);
|
|
1875
|
+
|
|
1876
|
+
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
|
|
1877
|
+
|
|
1878
|
+
pageOptions.methods.onLoad = function (query) {
|
|
1879
|
+
this.options = query;
|
|
1880
|
+
const copyQuery = Object.assign({}, query);
|
|
1881
|
+
delete copyQuery.__id__;
|
|
1882
|
+
this.$page = {
|
|
1883
|
+
fullPath: '/' + (this.route || this.is) + stringifyQuery(copyQuery)
|
|
1884
|
+
};
|
|
1885
|
+
this.$vm.$mp.query = query; // 兼容 mpvue
|
|
1886
|
+
this.$vm.__call_hook('onLoad', query);
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1889
|
+
return pageOptions
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
function parsePage (vuePageOptions) {
|
|
1893
|
+
return parseBasePage(vuePageOptions, {
|
|
1894
|
+
isPage,
|
|
1895
|
+
initRelation
|
|
1896
|
+
})
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
function parsePage$1 (vuePageOptions) {
|
|
1900
|
+
return parsePage(vuePageOptions)
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
function createPage (vuePageOptions) {
|
|
1904
|
+
{
|
|
1905
|
+
return Component(parsePage$1(vuePageOptions))
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
function createComponent (vueOptions) {
|
|
1910
|
+
{
|
|
1911
|
+
return Component(parseComponent$1(vueOptions))
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
function createSubpackageApp (vm) {
|
|
1916
|
+
const appOptions = parseApp$1(vm);
|
|
1917
|
+
const app = getApp({
|
|
1918
|
+
allowDefault: true
|
|
1919
|
+
});
|
|
1920
|
+
vm.$scope = app;
|
|
1921
|
+
const globalData = app.globalData;
|
|
1922
|
+
if (globalData) {
|
|
1923
|
+
Object.keys(appOptions.globalData).forEach(name => {
|
|
1924
|
+
if (!hasOwn(globalData, name)) {
|
|
1925
|
+
globalData[name] = appOptions.globalData[name];
|
|
1926
|
+
}
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
Object.keys(appOptions).forEach(name => {
|
|
1930
|
+
if (!hasOwn(app, name)) {
|
|
1931
|
+
app[name] = appOptions[name];
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
if (isFn(appOptions.onShow) && jd.onAppShow) {
|
|
1935
|
+
jd.onAppShow((...args) => {
|
|
1936
|
+
vm.__call_hook('onShow', args);
|
|
1937
|
+
});
|
|
1938
|
+
}
|
|
1939
|
+
if (isFn(appOptions.onHide) && jd.onAppHide) {
|
|
1940
|
+
jd.onAppHide((...args) => {
|
|
1941
|
+
vm.__call_hook('onHide', args);
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
if (isFn(appOptions.onLaunch)) {
|
|
1945
|
+
const args = jd.getLaunchOptionsSync && jd.getLaunchOptionsSync();
|
|
1946
|
+
vm.__call_hook('onLaunch', args);
|
|
1947
|
+
}
|
|
1948
|
+
return vm
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
function createPlugin (vm) {
|
|
1952
|
+
const appOptions = parseApp$1(vm);
|
|
1953
|
+
if (isFn(appOptions.onShow) && jd.onAppShow) {
|
|
1954
|
+
jd.onAppShow((...args) => {
|
|
1955
|
+
vm.__call_hook('onShow', args);
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
if (isFn(appOptions.onHide) && jd.onAppHide) {
|
|
1959
|
+
jd.onAppHide((...args) => {
|
|
1960
|
+
vm.__call_hook('onHide', args);
|
|
1961
|
+
});
|
|
1962
|
+
}
|
|
1963
|
+
if (isFn(appOptions.onLaunch)) {
|
|
1964
|
+
const args = jd.getLaunchOptionsSync && jd.getLaunchOptionsSync();
|
|
1965
|
+
vm.__call_hook('onLaunch', args);
|
|
1966
|
+
}
|
|
1967
|
+
return vm
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
todos.forEach(todoApi => {
|
|
1971
|
+
protocols[todoApi] = false;
|
|
1972
|
+
});
|
|
1973
|
+
|
|
1974
|
+
canIUses.forEach(canIUseApi => {
|
|
1975
|
+
const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name
|
|
1976
|
+
: canIUseApi;
|
|
1977
|
+
if (!jd.canIUse(apiName)) {
|
|
1978
|
+
protocols[canIUseApi] = false;
|
|
1979
|
+
}
|
|
1980
|
+
});
|
|
1981
|
+
|
|
1982
|
+
let uni = {};
|
|
1983
|
+
|
|
1984
|
+
if (typeof Proxy !== 'undefined' && "mp-jd" !== 'app-plus') {
|
|
1985
|
+
uni = new Proxy({}, {
|
|
1986
|
+
get (target, name) {
|
|
1987
|
+
if (hasOwn(target, name)) {
|
|
1988
|
+
return target[name]
|
|
1989
|
+
}
|
|
1990
|
+
if (baseApi[name]) {
|
|
1991
|
+
return baseApi[name]
|
|
1992
|
+
}
|
|
1993
|
+
if (api[name]) {
|
|
1994
|
+
return promisify(name, api[name])
|
|
1995
|
+
}
|
|
1996
|
+
{
|
|
1997
|
+
if (extraApi[name]) {
|
|
1998
|
+
return promisify(name, extraApi[name])
|
|
1999
|
+
}
|
|
2000
|
+
if (todoApis[name]) {
|
|
2001
|
+
return promisify(name, todoApis[name])
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
if (eventApi[name]) {
|
|
2005
|
+
return eventApi[name]
|
|
2006
|
+
}
|
|
2007
|
+
if (!hasOwn(jd, name) && !hasOwn(protocols, name)) {
|
|
2008
|
+
return
|
|
2009
|
+
}
|
|
2010
|
+
return promisify(name, wrapper(name, jd[name]))
|
|
2011
|
+
},
|
|
2012
|
+
set (target, name, value) {
|
|
2013
|
+
target[name] = value;
|
|
2014
|
+
return true
|
|
2015
|
+
}
|
|
2016
|
+
});
|
|
2017
|
+
} else {
|
|
2018
|
+
Object.keys(baseApi).forEach(name => {
|
|
2019
|
+
uni[name] = baseApi[name];
|
|
2020
|
+
});
|
|
2021
|
+
|
|
2022
|
+
{
|
|
2023
|
+
Object.keys(todoApis).forEach(name => {
|
|
2024
|
+
uni[name] = promisify(name, todoApis[name]);
|
|
2025
|
+
});
|
|
2026
|
+
Object.keys(extraApi).forEach(name => {
|
|
2027
|
+
uni[name] = promisify(name, todoApis[name]);
|
|
2028
|
+
});
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
Object.keys(eventApi).forEach(name => {
|
|
2032
|
+
uni[name] = eventApi[name];
|
|
2033
|
+
});
|
|
2034
|
+
|
|
2035
|
+
Object.keys(api).forEach(name => {
|
|
2036
|
+
uni[name] = promisify(name, api[name]);
|
|
2037
|
+
});
|
|
2038
|
+
|
|
2039
|
+
Object.keys(jd).forEach(name => {
|
|
2040
|
+
if (hasOwn(jd, name) || hasOwn(protocols, name)) {
|
|
2041
|
+
uni[name] = promisify(name, wrapper(name, jd[name]));
|
|
2042
|
+
}
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
jd.createApp = createApp;
|
|
2047
|
+
jd.createPage = createPage;
|
|
2048
|
+
jd.createComponent = createComponent;
|
|
2049
|
+
jd.createSubpackageApp = createSubpackageApp;
|
|
2050
|
+
jd.createPlugin = createPlugin;
|
|
2051
|
+
|
|
2052
|
+
var uni$1 = uni;
|
|
2053
|
+
|
|
2054
|
+
export default uni$1;
|
|
2055
|
+
export { createApp, createComponent, createPage, createPlugin, createSubpackageApp };
|