@dcloudio/uni-mp-baidu 2.0.0 → 2.0.1-33420211227001
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 +443 -130
- 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$|sendHostEvent|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,250 @@ function handleEvent (event) {
|
|
|
1589
1729
|
}
|
|
1590
1730
|
}
|
|
1591
1731
|
|
|
1592
|
-
const
|
|
1593
|
-
'onShow',
|
|
1594
|
-
'onHide',
|
|
1595
|
-
'onError',
|
|
1596
|
-
'onPageNotFound',
|
|
1597
|
-
'onThemeChange',
|
|
1598
|
-
'onUnhandledRejection'
|
|
1599
|
-
];
|
|
1732
|
+
const messages = {};
|
|
1600
1733
|
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
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
|
+
let locale;
|
|
1735
|
+
|
|
1736
|
+
{
|
|
1737
|
+
locale = swan.getSystemInfoSync().language;
|
|
1616
1738
|
}
|
|
1617
1739
|
|
|
1618
|
-
function
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
}) {
|
|
1622
|
-
initEventChannel$1();
|
|
1623
|
-
if (vm.$options.store) {
|
|
1624
|
-
Vue.prototype.$store = vm.$options.store;
|
|
1740
|
+
function initI18nMessages () {
|
|
1741
|
+
if (!isEnableLocale()) {
|
|
1742
|
+
return
|
|
1625
1743
|
}
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
if (
|
|
1632
|
-
|
|
1744
|
+
const localeKeys = Object.keys(__uniConfig.locales);
|
|
1745
|
+
if (localeKeys.length) {
|
|
1746
|
+
localeKeys.forEach((locale) => {
|
|
1747
|
+
const curMessages = messages[locale];
|
|
1748
|
+
const userMessages = __uniConfig.locales[locale];
|
|
1749
|
+
if (curMessages) {
|
|
1750
|
+
Object.assign(curMessages, userMessages);
|
|
1751
|
+
} else {
|
|
1752
|
+
messages[locale] = userMessages;
|
|
1633
1753
|
}
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1634
1757
|
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
this.$mp = {
|
|
1638
|
-
data: {},
|
|
1639
|
-
[this.mpType]: this.$options.mpInstance
|
|
1640
|
-
};
|
|
1641
|
-
|
|
1642
|
-
this.$scope = this.$options.mpInstance;
|
|
1758
|
+
initI18nMessages();
|
|
1643
1759
|
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1760
|
+
const i18n = initVueI18n(
|
|
1761
|
+
locale,
|
|
1762
|
+
{}
|
|
1763
|
+
);
|
|
1764
|
+
const t = i18n.t;
|
|
1765
|
+
const i18nMixin = (i18n.mixin = {
|
|
1766
|
+
beforeCreate () {
|
|
1767
|
+
const unwatch = i18n.i18n.watchLocale(() => {
|
|
1768
|
+
this.$forceUpdate();
|
|
1769
|
+
});
|
|
1770
|
+
this.$once('hook:beforeDestroy', function () {
|
|
1771
|
+
unwatch();
|
|
1772
|
+
});
|
|
1773
|
+
},
|
|
1774
|
+
methods: {
|
|
1775
|
+
$$t (key, values) {
|
|
1776
|
+
return t(key, values)
|
|
1656
1777
|
}
|
|
1657
|
-
}
|
|
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);
|
|
1778
|
+
}
|
|
1779
|
+
});
|
|
1780
|
+
const setLocale$1 = i18n.setLocale;
|
|
1781
|
+
const getLocale$1 = i18n.getLocale;
|
|
1677
1782
|
|
|
1678
|
-
|
|
1679
|
-
|
|
1783
|
+
function initAppLocale (Vue, appVm, locale) {
|
|
1784
|
+
const state = Vue.observable({
|
|
1785
|
+
locale: locale || i18n.getLocale()
|
|
1786
|
+
});
|
|
1787
|
+
const localeWatchers = [];
|
|
1788
|
+
appVm.$watchLocale = fn => {
|
|
1789
|
+
localeWatchers.push(fn);
|
|
1680
1790
|
};
|
|
1791
|
+
Object.defineProperty(appVm, '$locale', {
|
|
1792
|
+
get () {
|
|
1793
|
+
return state.locale
|
|
1794
|
+
},
|
|
1795
|
+
set (v) {
|
|
1796
|
+
state.locale = v;
|
|
1797
|
+
localeWatchers.forEach(watch => watch(v));
|
|
1798
|
+
}
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1681
1801
|
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
const methods = vm.$options.methods;
|
|
1686
|
-
if (methods) {
|
|
1687
|
-
Object.keys(methods).forEach(name => {
|
|
1688
|
-
appOptions[name] = methods[name];
|
|
1689
|
-
});
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
initHooks(appOptions, hooks);
|
|
1802
|
+
function isEnableLocale () {
|
|
1803
|
+
return typeof __uniConfig !== 'undefined' && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
|
|
1804
|
+
}
|
|
1693
1805
|
|
|
1694
|
-
|
|
1806
|
+
// export function initI18n() {
|
|
1807
|
+
// const localeKeys = Object.keys(__uniConfig.locales || {})
|
|
1808
|
+
// if (localeKeys.length) {
|
|
1809
|
+
// localeKeys.forEach((locale) =>
|
|
1810
|
+
// i18n.add(locale, __uniConfig.locales[locale])
|
|
1811
|
+
// )
|
|
1812
|
+
// }
|
|
1813
|
+
// }
|
|
1814
|
+
|
|
1815
|
+
const hooks = [
|
|
1816
|
+
'onShow',
|
|
1817
|
+
'onHide',
|
|
1818
|
+
'onError',
|
|
1819
|
+
'onPageNotFound',
|
|
1820
|
+
'onThemeChange',
|
|
1821
|
+
'onUnhandledRejection'
|
|
1822
|
+
];
|
|
1823
|
+
|
|
1824
|
+
function initEventChannel$1 () {
|
|
1825
|
+
Vue.prototype.getOpenerEventChannel = function () {
|
|
1826
|
+
if (!this.__eventChannel__) {
|
|
1827
|
+
this.__eventChannel__ = new EventChannel();
|
|
1828
|
+
}
|
|
1829
|
+
return this.__eventChannel__
|
|
1830
|
+
};
|
|
1831
|
+
const callHook = Vue.prototype.__call_hook;
|
|
1832
|
+
Vue.prototype.__call_hook = function (hook, args) {
|
|
1833
|
+
if (hook === 'onLoad' && args && args.__id__) {
|
|
1834
|
+
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1835
|
+
delete args.__id__;
|
|
1836
|
+
}
|
|
1837
|
+
return callHook.call(this, hook, args)
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
function initScopedSlotsParams () {
|
|
1842
|
+
const center = {};
|
|
1843
|
+
const parents = {};
|
|
1844
|
+
|
|
1845
|
+
Vue.prototype.$hasScopedSlotsParams = function (vueId) {
|
|
1846
|
+
const has = center[vueId];
|
|
1847
|
+
if (!has) {
|
|
1848
|
+
parents[vueId] = this;
|
|
1849
|
+
this.$on('hook:destroyed', () => {
|
|
1850
|
+
delete parents[vueId];
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
return has
|
|
1854
|
+
};
|
|
1855
|
+
|
|
1856
|
+
Vue.prototype.$getScopedSlotsParams = function (vueId, name, key) {
|
|
1857
|
+
const data = center[vueId];
|
|
1858
|
+
if (data) {
|
|
1859
|
+
const object = data[name] || {};
|
|
1860
|
+
return key ? object[key] : object
|
|
1861
|
+
} else {
|
|
1862
|
+
parents[vueId] = this;
|
|
1863
|
+
this.$on('hook:destroyed', () => {
|
|
1864
|
+
delete parents[vueId];
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1869
|
+
Vue.prototype.$setScopedSlotsParams = function (name, value) {
|
|
1870
|
+
const vueIds = this.$options.propsData.vueId;
|
|
1871
|
+
if (vueIds) {
|
|
1872
|
+
const vueId = vueIds.split(',')[0];
|
|
1873
|
+
const object = center[vueId] = center[vueId] || {};
|
|
1874
|
+
object[name] = value;
|
|
1875
|
+
if (parents[vueId]) {
|
|
1876
|
+
parents[vueId].$forceUpdate();
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
|
|
1881
|
+
Vue.mixin({
|
|
1882
|
+
destroyed () {
|
|
1883
|
+
const propsData = this.$options.propsData;
|
|
1884
|
+
const vueId = propsData && propsData.vueId;
|
|
1885
|
+
if (vueId) {
|
|
1886
|
+
delete center[vueId];
|
|
1887
|
+
delete parents[vueId];
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
function parseBaseApp (vm, {
|
|
1894
|
+
mocks,
|
|
1895
|
+
initRefs
|
|
1896
|
+
}) {
|
|
1897
|
+
initEventChannel$1();
|
|
1898
|
+
{
|
|
1899
|
+
initScopedSlotsParams();
|
|
1900
|
+
}
|
|
1901
|
+
if (vm.$options.store) {
|
|
1902
|
+
Vue.prototype.$store = vm.$options.store;
|
|
1903
|
+
}
|
|
1904
|
+
uniIdMixin(Vue);
|
|
1905
|
+
|
|
1906
|
+
Vue.prototype.mpHost = "mp-baidu";
|
|
1907
|
+
|
|
1908
|
+
Vue.mixin({
|
|
1909
|
+
beforeCreate () {
|
|
1910
|
+
if (!this.$options.mpType) {
|
|
1911
|
+
return
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
this.mpType = this.$options.mpType;
|
|
1915
|
+
|
|
1916
|
+
this.$mp = {
|
|
1917
|
+
data: {},
|
|
1918
|
+
[this.mpType]: this.$options.mpInstance
|
|
1919
|
+
};
|
|
1920
|
+
|
|
1921
|
+
this.$scope = this.$options.mpInstance;
|
|
1922
|
+
|
|
1923
|
+
delete this.$options.mpType;
|
|
1924
|
+
delete this.$options.mpInstance;
|
|
1925
|
+
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
|
|
1926
|
+
const app = getApp();
|
|
1927
|
+
if (app.$vm && app.$vm.$i18n) {
|
|
1928
|
+
this._i18n = app.$vm.$i18n;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
if (this.mpType !== 'app') {
|
|
1932
|
+
initRefs(this);
|
|
1933
|
+
initMocks(this, mocks);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
});
|
|
1937
|
+
|
|
1938
|
+
const appOptions = {
|
|
1939
|
+
onLaunch (args) {
|
|
1940
|
+
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1941
|
+
return
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
this.$vm = vm;
|
|
1945
|
+
|
|
1946
|
+
this.$vm.$mp = {
|
|
1947
|
+
app: this
|
|
1948
|
+
};
|
|
1949
|
+
|
|
1950
|
+
this.$vm.$scope = this;
|
|
1951
|
+
// vm 上也挂载 globalData
|
|
1952
|
+
this.$vm.globalData = this.globalData;
|
|
1953
|
+
|
|
1954
|
+
this.$vm._isMounted = true;
|
|
1955
|
+
this.$vm.__call_hook('mounted', args);
|
|
1956
|
+
|
|
1957
|
+
this.$vm.__call_hook('onLaunch', args);
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
|
|
1961
|
+
// 兼容旧版本 globalData
|
|
1962
|
+
appOptions.globalData = vm.$options.globalData || {};
|
|
1963
|
+
// 将 methods 中的方法挂在 getApp() 中
|
|
1964
|
+
const methods = vm.$options.methods;
|
|
1965
|
+
if (methods) {
|
|
1966
|
+
Object.keys(methods).forEach(name => {
|
|
1967
|
+
appOptions[name] = methods[name];
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
initAppLocale(Vue, vm, swan.getSystemInfoSync().language || 'zh-Hans');
|
|
1972
|
+
|
|
1973
|
+
initHooks(appOptions, hooks);
|
|
1974
|
+
|
|
1975
|
+
return appOptions
|
|
1695
1976
|
}
|
|
1696
1977
|
|
|
1697
1978
|
function findVmByVueId (vm, vuePid) {
|
|
@@ -1769,7 +2050,8 @@ const mocks = ['nodeId', 'componentName', '_componentId', 'uniquePrefix'];
|
|
|
1769
2050
|
function isPage () {
|
|
1770
2051
|
// 百度小程序组件的id,某些情况下可能是number类型的0,不能直接return !this.ownerId 判断当前组件是否是Page
|
|
1771
2052
|
// 否则会导致mounted不执行
|
|
1772
|
-
|
|
2053
|
+
// 基础库 3.290.33 及以上 ownerId 为 null
|
|
2054
|
+
return typeof this.ownerId === 'undefined' || this.ownerId === null
|
|
1773
2055
|
}
|
|
1774
2056
|
|
|
1775
2057
|
function initRelation (detail) {
|
|
@@ -1839,6 +2121,44 @@ function stringifyQuery (obj, encodeStr = encode) {
|
|
|
1839
2121
|
return res ? `?${res}` : ''
|
|
1840
2122
|
}
|
|
1841
2123
|
|
|
2124
|
+
/**
|
|
2125
|
+
* 用于延迟调用 setData
|
|
2126
|
+
* 在 setData 真实调用的时机需执行 fixSetDataEnd
|
|
2127
|
+
* @param {*} mpInstance
|
|
2128
|
+
*/
|
|
2129
|
+
function fixSetDataStart (mpInstance) {
|
|
2130
|
+
const setData = mpInstance.setData;
|
|
2131
|
+
const setDataArgs = [];
|
|
2132
|
+
mpInstance.setData = function () {
|
|
2133
|
+
setDataArgs.push(arguments);
|
|
2134
|
+
};
|
|
2135
|
+
mpInstance.__fixInitData = function () {
|
|
2136
|
+
this.setData = setData;
|
|
2137
|
+
const fn = () => {
|
|
2138
|
+
setDataArgs.forEach(args => {
|
|
2139
|
+
setData.apply(this, args);
|
|
2140
|
+
});
|
|
2141
|
+
};
|
|
2142
|
+
if (setDataArgs.length) {
|
|
2143
|
+
if (this.groupSetData) {
|
|
2144
|
+
this.groupSetData(fn);
|
|
2145
|
+
} else {
|
|
2146
|
+
fn();
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
}
|
|
2151
|
+
/**
|
|
2152
|
+
* 恢复真实的 setData 方法
|
|
2153
|
+
* @param {*} mpInstance
|
|
2154
|
+
*/
|
|
2155
|
+
function fixSetDataEnd (mpInstance) {
|
|
2156
|
+
if (mpInstance.__fixInitData) {
|
|
2157
|
+
mpInstance.__fixInitData();
|
|
2158
|
+
delete mpInstance.__fixInitData;
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
|
|
1842
2162
|
function parseBaseComponent (vueComponentOptions, {
|
|
1843
2163
|
isPage,
|
|
1844
2164
|
initRelation
|
|
@@ -1945,23 +2265,14 @@ function parseComponent (vueOptions) {
|
|
|
1945
2265
|
const oldAttached = componentOptions.lifetimes.attached;
|
|
1946
2266
|
// 百度小程序基础库 3.260 以上支持页面 onInit 生命周期,提前创建 vm 实例
|
|
1947
2267
|
componentOptions.lifetimes.onInit = function onInit (query) {
|
|
2268
|
+
// 百度小程序后续可能移除 pageinstance 属性,为向后兼容进行补充
|
|
2269
|
+
if (!this.pageinstance || !this.pageinstance.setData) {
|
|
2270
|
+
const pages = getCurrentPages();
|
|
2271
|
+
this.pageinstance = pages[pages.length - 1];
|
|
2272
|
+
}
|
|
2273
|
+
|
|
1948
2274
|
// 处理百度小程序 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
|
-
};
|
|
2275
|
+
fixSetDataStart(this);
|
|
1965
2276
|
oldAttached.call(this);
|
|
1966
2277
|
this.pageinstance.$vm = this.$vm;
|
|
1967
2278
|
this.$vm.__call_hook('onInit', query);
|
|
@@ -1970,7 +2281,8 @@ function parseComponent (vueOptions) {
|
|
|
1970
2281
|
if (!this.$vm) {
|
|
1971
2282
|
oldAttached.call(this);
|
|
1972
2283
|
} else {
|
|
1973
|
-
this
|
|
2284
|
+
initMocks(this.$vm, mocks);
|
|
2285
|
+
fixSetDataEnd(this);
|
|
1974
2286
|
}
|
|
1975
2287
|
if (isPage.call(this)) { // 百度 onLoad 在 attached 之前触发(基础库小于 3.70)
|
|
1976
2288
|
// 百度 当组件作为页面时 pageinstancce 不是原来组件的 instance
|
|
@@ -2107,6 +2419,7 @@ function createSubpackageApp (vm) {
|
|
|
2107
2419
|
const app = getApp({
|
|
2108
2420
|
allowDefault: true
|
|
2109
2421
|
});
|
|
2422
|
+
vm.$scope = app;
|
|
2110
2423
|
const globalData = app.globalData;
|
|
2111
2424
|
if (globalData) {
|
|
2112
2425
|
Object.keys(appOptions.globalData).forEach(name => {
|
|
@@ -2121,18 +2434,18 @@ function createSubpackageApp (vm) {
|
|
|
2121
2434
|
}
|
|
2122
2435
|
});
|
|
2123
2436
|
if (isFn(appOptions.onShow) && swan.onAppShow) {
|
|
2124
|
-
swan.onAppShow((...args) => {
|
|
2125
|
-
|
|
2437
|
+
swan.onAppShow((...args) => {
|
|
2438
|
+
vm.__call_hook('onShow', args);
|
|
2126
2439
|
});
|
|
2127
2440
|
}
|
|
2128
2441
|
if (isFn(appOptions.onHide) && swan.onAppHide) {
|
|
2129
|
-
swan.onAppHide((...args) => {
|
|
2130
|
-
|
|
2442
|
+
swan.onAppHide((...args) => {
|
|
2443
|
+
vm.__call_hook('onHide', args);
|
|
2131
2444
|
});
|
|
2132
2445
|
}
|
|
2133
2446
|
if (isFn(appOptions.onLaunch)) {
|
|
2134
2447
|
const args = swan.getLaunchOptionsSync && swan.getLaunchOptionsSync();
|
|
2135
|
-
|
|
2448
|
+
vm.__call_hook('onLaunch', args);
|
|
2136
2449
|
}
|
|
2137
2450
|
return vm
|
|
2138
2451
|
}
|