@dcloudio/uni-mp-baidu 2.0.0 → 2.0.1-alpha-32920211110001
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 +413 -135
- package/dist/uni.api.esm.js +528 -160
- package/dist/uni.mp.esm.js +593 -208
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,83 @@
|
|
|
1
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 = ( swan).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
|
+
}
|
|
2
81
|
|
|
3
82
|
const _toString = Object.prototype.toString;
|
|
4
83
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
@@ -142,7 +221,7 @@ function queue (hooks, data) {
|
|
|
142
221
|
}
|
|
143
222
|
if (res === false) {
|
|
144
223
|
return {
|
|
145
|
-
then () {}
|
|
224
|
+
then () { }
|
|
146
225
|
}
|
|
147
226
|
}
|
|
148
227
|
}
|
|
@@ -190,15 +269,15 @@ function getApiInterceptorHooks (method) {
|
|
|
190
269
|
if (hook !== 'returnValue') {
|
|
191
270
|
interceptor[hook] = globalInterceptors[hook].slice();
|
|
192
271
|
}
|
|
193
|
-
});
|
|
194
|
-
const scopedInterceptor = scopedInterceptors[method];
|
|
195
|
-
if (scopedInterceptor) {
|
|
196
|
-
Object.keys(scopedInterceptor).forEach(hook => {
|
|
197
|
-
if (hook !== 'returnValue') {
|
|
198
|
-
interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
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
|
+
}
|
|
202
281
|
return interceptor
|
|
203
282
|
}
|
|
204
283
|
|
|
@@ -222,16 +301,20 @@ const promiseInterceptor = {
|
|
|
222
301
|
if (!isPromise(res)) {
|
|
223
302
|
return res
|
|
224
303
|
}
|
|
225
|
-
return
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
+
});
|
|
229
312
|
})
|
|
230
313
|
}
|
|
231
314
|
};
|
|
232
315
|
|
|
233
316
|
const SYNC_API_RE =
|
|
234
|
-
/^\$|Window$|WindowStyle$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
|
|
317
|
+
/^\$|Window$|WindowStyle$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/;
|
|
235
318
|
|
|
236
319
|
const CONTEXT_API_RE = /^create|Manager$/;
|
|
237
320
|
|
|
@@ -344,6 +427,44 @@ function upx2px (number, newDeviceWidth) {
|
|
|
344
427
|
return number < 0 ? -result : result
|
|
345
428
|
}
|
|
346
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 swan.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
|
+
|
|
347
468
|
const interceptors = {
|
|
348
469
|
promiseInterceptor
|
|
349
470
|
};
|
|
@@ -351,6 +472,9 @@ const interceptors = {
|
|
|
351
472
|
var baseApi = /*#__PURE__*/Object.freeze({
|
|
352
473
|
__proto__: null,
|
|
353
474
|
upx2px: upx2px,
|
|
475
|
+
getLocale: getLocale,
|
|
476
|
+
setLocale: setLocale,
|
|
477
|
+
onLocaleChange: onLocaleChange,
|
|
354
478
|
addInterceptor: addInterceptor,
|
|
355
479
|
removeInterceptor: removeInterceptor,
|
|
356
480
|
interceptors: interceptors
|
|
@@ -560,6 +684,13 @@ var getSystemInfo = {
|
|
|
560
684
|
}
|
|
561
685
|
};
|
|
562
686
|
|
|
687
|
+
const oName = 'getUserInfo';
|
|
688
|
+
const nName = 'getUserProfile';
|
|
689
|
+
|
|
690
|
+
var getUserProfile = {
|
|
691
|
+
name: swan.canIUse(nName) ? nName : oName
|
|
692
|
+
};
|
|
693
|
+
|
|
563
694
|
// 不支持的 API 列表
|
|
564
695
|
const todos = [
|
|
565
696
|
'preloadPage',
|
|
@@ -646,6 +777,7 @@ const protocols = {
|
|
|
646
777
|
previewImage,
|
|
647
778
|
getSystemInfo,
|
|
648
779
|
getSystemInfoSync: getSystemInfo,
|
|
780
|
+
getUserProfile,
|
|
649
781
|
getRecorderManager: {
|
|
650
782
|
returnValue (fromRet) {
|
|
651
783
|
fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded');
|
|
@@ -679,6 +811,9 @@ const protocols = {
|
|
|
679
811
|
getAccountInfoSync: {
|
|
680
812
|
name: 'getEnvInfoSync',
|
|
681
813
|
returnValue: _handleEnvInfo
|
|
814
|
+
},
|
|
815
|
+
login: {
|
|
816
|
+
name: 'getLoginCode'
|
|
682
817
|
}
|
|
683
818
|
};
|
|
684
819
|
|
|
@@ -998,7 +1133,7 @@ function initTriggerEvent (mpInstance) {
|
|
|
998
1133
|
};
|
|
999
1134
|
}
|
|
1000
1135
|
|
|
1001
|
-
function initHook (name, options) {
|
|
1136
|
+
function initHook (name, options, isComponent) {
|
|
1002
1137
|
const oldHook = options[name];
|
|
1003
1138
|
if (!oldHook) {
|
|
1004
1139
|
options[name] = function () {
|
|
@@ -1252,6 +1387,11 @@ function initProperties (props, isBehavior = false, file = '') {
|
|
|
1252
1387
|
type: Object,
|
|
1253
1388
|
value: null
|
|
1254
1389
|
};
|
|
1390
|
+
// scopedSlotsCompiler auto
|
|
1391
|
+
properties.scopedSlotsCompiler = {
|
|
1392
|
+
type: String,
|
|
1393
|
+
value: ''
|
|
1394
|
+
};
|
|
1255
1395
|
properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
|
|
1256
1396
|
type: null,
|
|
1257
1397
|
value: [],
|
|
@@ -1589,109 +1729,215 @@ function handleEvent (event) {
|
|
|
1589
1729
|
}
|
|
1590
1730
|
}
|
|
1591
1731
|
|
|
1592
|
-
|
|
1593
|
-
'onShow',
|
|
1594
|
-
'onHide',
|
|
1595
|
-
'onError',
|
|
1596
|
-
'onPageNotFound',
|
|
1597
|
-
'onThemeChange',
|
|
1598
|
-
'onUnhandledRejection'
|
|
1599
|
-
];
|
|
1732
|
+
let locale;
|
|
1600
1733
|
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
if (!this.__eventChannel__) {
|
|
1604
|
-
this.__eventChannel__ = new EventChannel();
|
|
1605
|
-
}
|
|
1606
|
-
return this.__eventChannel__
|
|
1607
|
-
};
|
|
1608
|
-
const callHook = Vue.prototype.__call_hook;
|
|
1609
|
-
Vue.prototype.__call_hook = function (hook, args) {
|
|
1610
|
-
if (hook === 'onLoad' && args && args.__id__) {
|
|
1611
|
-
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1612
|
-
delete args.__id__;
|
|
1613
|
-
}
|
|
1614
|
-
return callHook.call(this, hook, args)
|
|
1615
|
-
};
|
|
1734
|
+
{
|
|
1735
|
+
locale = swan.getSystemInfoSync().language;
|
|
1616
1736
|
}
|
|
1617
1737
|
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1738
|
+
const i18n = initVueI18n(
|
|
1739
|
+
locale,
|
|
1740
|
+
{}
|
|
1741
|
+
);
|
|
1742
|
+
const t = i18n.t;
|
|
1743
|
+
const i18nMixin = (i18n.mixin = {
|
|
1744
|
+
beforeCreate () {
|
|
1745
|
+
const unwatch = i18n.i18n.watchLocale(() => {
|
|
1746
|
+
this.$forceUpdate();
|
|
1747
|
+
});
|
|
1748
|
+
this.$once('hook:beforeDestroy', function () {
|
|
1749
|
+
unwatch();
|
|
1750
|
+
});
|
|
1751
|
+
},
|
|
1752
|
+
methods: {
|
|
1753
|
+
$$t (key, values) {
|
|
1754
|
+
return t(key, values)
|
|
1755
|
+
}
|
|
1625
1756
|
}
|
|
1757
|
+
});
|
|
1758
|
+
const setLocale$1 = i18n.setLocale;
|
|
1759
|
+
const getLocale$1 = i18n.getLocale;
|
|
1626
1760
|
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
beforeCreate () {
|
|
1631
|
-
if (!this.$options.mpType) {
|
|
1632
|
-
return
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
this.mpType = this.$options.mpType;
|
|
1636
|
-
|
|
1637
|
-
this.$mp = {
|
|
1638
|
-
data: {},
|
|
1639
|
-
[this.mpType]: this.$options.mpInstance
|
|
1640
|
-
};
|
|
1641
|
-
|
|
1642
|
-
this.$scope = this.$options.mpInstance;
|
|
1643
|
-
|
|
1644
|
-
delete this.$options.mpType;
|
|
1645
|
-
delete this.$options.mpInstance;
|
|
1646
|
-
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
|
|
1647
|
-
const app = getApp();
|
|
1648
|
-
if (app.$vm && app.$vm.$i18n) {
|
|
1649
|
-
this._i18n = app.$vm.$i18n;
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
if (this.mpType !== 'app') {
|
|
1653
|
-
initRefs(this);
|
|
1654
|
-
initMocks(this, mocks);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1761
|
+
function initAppLocale (Vue, appVm, locale) {
|
|
1762
|
+
const state = Vue.observable({
|
|
1763
|
+
locale: locale || i18n.getLocale()
|
|
1657
1764
|
});
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1662
|
-
return
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
|
-
this.$vm = vm;
|
|
1666
|
-
|
|
1667
|
-
this.$vm.$mp = {
|
|
1668
|
-
app: this
|
|
1669
|
-
};
|
|
1670
|
-
|
|
1671
|
-
this.$vm.$scope = this;
|
|
1672
|
-
// vm 上也挂载 globalData
|
|
1673
|
-
this.$vm.globalData = this.globalData;
|
|
1674
|
-
|
|
1675
|
-
this.$vm._isMounted = true;
|
|
1676
|
-
this.$vm.__call_hook('mounted', args);
|
|
1677
|
-
|
|
1678
|
-
this.$vm.__call_hook('onLaunch', args);
|
|
1679
|
-
}
|
|
1765
|
+
const localeWatchers = [];
|
|
1766
|
+
appVm.$watchLocale = fn => {
|
|
1767
|
+
localeWatchers.push(fn);
|
|
1680
1768
|
};
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1769
|
+
Object.defineProperty(appVm, '$locale', {
|
|
1770
|
+
get () {
|
|
1771
|
+
return state.locale
|
|
1772
|
+
},
|
|
1773
|
+
set (v) {
|
|
1774
|
+
state.locale = v;
|
|
1775
|
+
localeWatchers.forEach(watch => watch(v));
|
|
1776
|
+
}
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
const hooks = [
|
|
1781
|
+
'onShow',
|
|
1782
|
+
'onHide',
|
|
1783
|
+
'onError',
|
|
1784
|
+
'onPageNotFound',
|
|
1785
|
+
'onThemeChange',
|
|
1786
|
+
'onUnhandledRejection'
|
|
1787
|
+
];
|
|
1788
|
+
|
|
1789
|
+
function initEventChannel$1 () {
|
|
1790
|
+
Vue.prototype.getOpenerEventChannel = function () {
|
|
1791
|
+
if (!this.__eventChannel__) {
|
|
1792
|
+
this.__eventChannel__ = new EventChannel();
|
|
1793
|
+
}
|
|
1794
|
+
return this.__eventChannel__
|
|
1795
|
+
};
|
|
1796
|
+
const callHook = Vue.prototype.__call_hook;
|
|
1797
|
+
Vue.prototype.__call_hook = function (hook, args) {
|
|
1798
|
+
if (hook === 'onLoad' && args && args.__id__) {
|
|
1799
|
+
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1800
|
+
delete args.__id__;
|
|
1801
|
+
}
|
|
1802
|
+
return callHook.call(this, hook, args)
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
function initScopedSlotsParams () {
|
|
1807
|
+
const center = {};
|
|
1808
|
+
const parents = {};
|
|
1809
|
+
|
|
1810
|
+
Vue.prototype.$hasScopedSlotsParams = function (vueId) {
|
|
1811
|
+
const has = center[vueId];
|
|
1812
|
+
if (!has) {
|
|
1813
|
+
parents[vueId] = this;
|
|
1814
|
+
this.$on('hook:destroyed', () => {
|
|
1815
|
+
delete parents[vueId];
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
return has
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1821
|
+
Vue.prototype.$getScopedSlotsParams = function (vueId, name, key) {
|
|
1822
|
+
const data = center[vueId];
|
|
1823
|
+
if (data) {
|
|
1824
|
+
const object = data[name] || {};
|
|
1825
|
+
return key ? object[key] : object
|
|
1826
|
+
} else {
|
|
1827
|
+
parents[vueId] = this;
|
|
1828
|
+
this.$on('hook:destroyed', () => {
|
|
1829
|
+
delete parents[vueId];
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
};
|
|
1833
|
+
|
|
1834
|
+
Vue.prototype.$setScopedSlotsParams = function (name, value) {
|
|
1835
|
+
const vueIds = this.$options.propsData.vueId;
|
|
1836
|
+
if (vueIds) {
|
|
1837
|
+
const vueId = vueIds.split(',')[0];
|
|
1838
|
+
const object = center[vueId] = center[vueId] || {};
|
|
1839
|
+
object[name] = value;
|
|
1840
|
+
if (parents[vueId]) {
|
|
1841
|
+
parents[vueId].$forceUpdate();
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
|
|
1846
|
+
Vue.mixin({
|
|
1847
|
+
destroyed () {
|
|
1848
|
+
const propsData = this.$options.propsData;
|
|
1849
|
+
const vueId = propsData && propsData.vueId;
|
|
1850
|
+
if (vueId) {
|
|
1851
|
+
delete center[vueId];
|
|
1852
|
+
delete parents[vueId];
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
function parseBaseApp (vm, {
|
|
1859
|
+
mocks,
|
|
1860
|
+
initRefs
|
|
1861
|
+
}) {
|
|
1862
|
+
initEventChannel$1();
|
|
1863
|
+
{
|
|
1864
|
+
initScopedSlotsParams();
|
|
1865
|
+
}
|
|
1866
|
+
if (vm.$options.store) {
|
|
1867
|
+
Vue.prototype.$store = vm.$options.store;
|
|
1868
|
+
}
|
|
1869
|
+
uniIdMixin(Vue);
|
|
1870
|
+
|
|
1871
|
+
Vue.prototype.mpHost = "mp-baidu";
|
|
1872
|
+
|
|
1873
|
+
Vue.mixin({
|
|
1874
|
+
beforeCreate () {
|
|
1875
|
+
if (!this.$options.mpType) {
|
|
1876
|
+
return
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
this.mpType = this.$options.mpType;
|
|
1880
|
+
|
|
1881
|
+
this.$mp = {
|
|
1882
|
+
data: {},
|
|
1883
|
+
[this.mpType]: this.$options.mpInstance
|
|
1884
|
+
};
|
|
1885
|
+
|
|
1886
|
+
this.$scope = this.$options.mpInstance;
|
|
1887
|
+
|
|
1888
|
+
delete this.$options.mpType;
|
|
1889
|
+
delete this.$options.mpInstance;
|
|
1890
|
+
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
|
|
1891
|
+
const app = getApp();
|
|
1892
|
+
if (app.$vm && app.$vm.$i18n) {
|
|
1893
|
+
this._i18n = app.$vm.$i18n;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
if (this.mpType !== 'app') {
|
|
1897
|
+
initRefs(this);
|
|
1898
|
+
initMocks(this, mocks);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
|
|
1903
|
+
const appOptions = {
|
|
1904
|
+
onLaunch (args) {
|
|
1905
|
+
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1906
|
+
return
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
this.$vm = vm;
|
|
1910
|
+
|
|
1911
|
+
this.$vm.$mp = {
|
|
1912
|
+
app: this
|
|
1913
|
+
};
|
|
1914
|
+
|
|
1915
|
+
this.$vm.$scope = this;
|
|
1916
|
+
// vm 上也挂载 globalData
|
|
1917
|
+
this.$vm.globalData = this.globalData;
|
|
1918
|
+
|
|
1919
|
+
this.$vm._isMounted = true;
|
|
1920
|
+
this.$vm.__call_hook('mounted', args);
|
|
1921
|
+
|
|
1922
|
+
this.$vm.__call_hook('onLaunch', args);
|
|
1923
|
+
}
|
|
1924
|
+
};
|
|
1925
|
+
|
|
1926
|
+
// 兼容旧版本 globalData
|
|
1927
|
+
appOptions.globalData = vm.$options.globalData || {};
|
|
1928
|
+
// 将 methods 中的方法挂在 getApp() 中
|
|
1929
|
+
const methods = vm.$options.methods;
|
|
1930
|
+
if (methods) {
|
|
1931
|
+
Object.keys(methods).forEach(name => {
|
|
1932
|
+
appOptions[name] = methods[name];
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
initAppLocale(Vue, vm, swan.getSystemInfoSync().language || 'zh-Hans');
|
|
1937
|
+
|
|
1938
|
+
initHooks(appOptions, hooks);
|
|
1939
|
+
|
|
1940
|
+
return appOptions
|
|
1695
1941
|
}
|
|
1696
1942
|
|
|
1697
1943
|
function findVmByVueId (vm, vuePid) {
|
|
@@ -1769,7 +2015,8 @@ const mocks = ['nodeId', 'componentName', '_componentId', 'uniquePrefix'];
|
|
|
1769
2015
|
function isPage () {
|
|
1770
2016
|
// 百度小程序组件的id,某些情况下可能是number类型的0,不能直接return !this.ownerId 判断当前组件是否是Page
|
|
1771
2017
|
// 否则会导致mounted不执行
|
|
1772
|
-
|
|
2018
|
+
// 基础库 3.290.33 及以上 ownerId 为 null
|
|
2019
|
+
return typeof this.ownerId === 'undefined' || this.ownerId === null
|
|
1773
2020
|
}
|
|
1774
2021
|
|
|
1775
2022
|
function initRelation (detail) {
|
|
@@ -1839,6 +2086,44 @@ function stringifyQuery (obj, encodeStr = encode) {
|
|
|
1839
2086
|
return res ? `?${res}` : ''
|
|
1840
2087
|
}
|
|
1841
2088
|
|
|
2089
|
+
/**
|
|
2090
|
+
* 用于延迟调用 setData
|
|
2091
|
+
* 在 setData 真实调用的时机需执行 fixSetDataEnd
|
|
2092
|
+
* @param {*} mpInstance
|
|
2093
|
+
*/
|
|
2094
|
+
function fixSetDataStart (mpInstance) {
|
|
2095
|
+
const setData = mpInstance.setData;
|
|
2096
|
+
const setDataArgs = [];
|
|
2097
|
+
mpInstance.setData = function () {
|
|
2098
|
+
setDataArgs.push(arguments);
|
|
2099
|
+
};
|
|
2100
|
+
mpInstance.__fixInitData = function () {
|
|
2101
|
+
this.setData = setData;
|
|
2102
|
+
const fn = () => {
|
|
2103
|
+
setDataArgs.forEach(args => {
|
|
2104
|
+
setData.apply(this, args);
|
|
2105
|
+
});
|
|
2106
|
+
};
|
|
2107
|
+
if (setDataArgs.length) {
|
|
2108
|
+
if (this.groupSetData) {
|
|
2109
|
+
this.groupSetData(fn);
|
|
2110
|
+
} else {
|
|
2111
|
+
fn();
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* 恢复真实的 setData 方法
|
|
2118
|
+
* @param {*} mpInstance
|
|
2119
|
+
*/
|
|
2120
|
+
function fixSetDataEnd (mpInstance) {
|
|
2121
|
+
if (mpInstance.__fixInitData) {
|
|
2122
|
+
mpInstance.__fixInitData();
|
|
2123
|
+
delete mpInstance.__fixInitData;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
|
|
1842
2127
|
function parseBaseComponent (vueComponentOptions, {
|
|
1843
2128
|
isPage,
|
|
1844
2129
|
initRelation
|
|
@@ -1945,23 +2230,14 @@ function parseComponent (vueOptions) {
|
|
|
1945
2230
|
const oldAttached = componentOptions.lifetimes.attached;
|
|
1946
2231
|
// 百度小程序基础库 3.260 以上支持页面 onInit 生命周期,提前创建 vm 实例
|
|
1947
2232
|
componentOptions.lifetimes.onInit = function onInit (query) {
|
|
2233
|
+
// 百度小程序后续可能移除 pageinstance 属性,为向后兼容进行补充
|
|
2234
|
+
if (!this.pageinstance || !this.pageinstance.setData) {
|
|
2235
|
+
const pages = getCurrentPages();
|
|
2236
|
+
this.pageinstance = pages[pages.length - 1];
|
|
2237
|
+
}
|
|
2238
|
+
|
|
1948
2239
|
// 处理百度小程序 onInit 生命周期调用 setData 无效的问题
|
|
1949
|
-
|
|
1950
|
-
const setDataArgs = [];
|
|
1951
|
-
this.setData = function () {
|
|
1952
|
-
setDataArgs.push(arguments);
|
|
1953
|
-
};
|
|
1954
|
-
this.__fixInitData = function () {
|
|
1955
|
-
delete this.__fixInitData;
|
|
1956
|
-
this.setData = setData;
|
|
1957
|
-
if (setDataArgs.length) {
|
|
1958
|
-
this.groupSetData(() => {
|
|
1959
|
-
setDataArgs.forEach(args => {
|
|
1960
|
-
setData.apply(this, args);
|
|
1961
|
-
});
|
|
1962
|
-
});
|
|
1963
|
-
}
|
|
1964
|
-
};
|
|
2240
|
+
fixSetDataStart(this);
|
|
1965
2241
|
oldAttached.call(this);
|
|
1966
2242
|
this.pageinstance.$vm = this.$vm;
|
|
1967
2243
|
this.$vm.__call_hook('onInit', query);
|
|
@@ -1970,7 +2246,8 @@ function parseComponent (vueOptions) {
|
|
|
1970
2246
|
if (!this.$vm) {
|
|
1971
2247
|
oldAttached.call(this);
|
|
1972
2248
|
} else {
|
|
1973
|
-
this
|
|
2249
|
+
initMocks(this.$vm, mocks);
|
|
2250
|
+
fixSetDataEnd(this);
|
|
1974
2251
|
}
|
|
1975
2252
|
if (isPage.call(this)) { // 百度 onLoad 在 attached 之前触发(基础库小于 3.70)
|
|
1976
2253
|
// 百度 当组件作为页面时 pageinstancce 不是原来组件的 instance
|
|
@@ -2107,6 +2384,7 @@ function createSubpackageApp (vm) {
|
|
|
2107
2384
|
const app = getApp({
|
|
2108
2385
|
allowDefault: true
|
|
2109
2386
|
});
|
|
2387
|
+
vm.$scope = app;
|
|
2110
2388
|
const globalData = app.globalData;
|
|
2111
2389
|
if (globalData) {
|
|
2112
2390
|
Object.keys(appOptions.globalData).forEach(name => {
|
|
@@ -2121,18 +2399,18 @@ function createSubpackageApp (vm) {
|
|
|
2121
2399
|
}
|
|
2122
2400
|
});
|
|
2123
2401
|
if (isFn(appOptions.onShow) && swan.onAppShow) {
|
|
2124
|
-
swan.onAppShow((...args) => {
|
|
2125
|
-
|
|
2402
|
+
swan.onAppShow((...args) => {
|
|
2403
|
+
vm.__call_hook('onShow', args);
|
|
2126
2404
|
});
|
|
2127
2405
|
}
|
|
2128
2406
|
if (isFn(appOptions.onHide) && swan.onAppHide) {
|
|
2129
|
-
swan.onAppHide((...args) => {
|
|
2130
|
-
|
|
2407
|
+
swan.onAppHide((...args) => {
|
|
2408
|
+
vm.__call_hook('onHide', args);
|
|
2131
2409
|
});
|
|
2132
2410
|
}
|
|
2133
2411
|
if (isFn(appOptions.onLaunch)) {
|
|
2134
2412
|
const args = swan.getLaunchOptionsSync && swan.getLaunchOptionsSync();
|
|
2135
|
-
|
|
2413
|
+
vm.__call_hook('onLaunch', args);
|
|
2136
2414
|
}
|
|
2137
2415
|
return vm
|
|
2138
2416
|
}
|