@dcloudio/uni-mp-toutiao 2.0.0 → 2.0.1-32920211122002
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 +400 -136
- package/dist/uni.api.esm.js +519 -154
- package/dist/uni.mp.esm.js +547 -213
- package/lib/uni.compiler.js +11 -1
- 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 = ( tt).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 tt.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: tt.canIUse(nName) ? nName : oName
|
|
692
|
+
};
|
|
693
|
+
|
|
563
694
|
// 不支持的 API 列表
|
|
564
695
|
const todos = [
|
|
565
696
|
'preloadPage',
|
|
@@ -664,6 +795,7 @@ const protocols = {
|
|
|
664
795
|
previewImage,
|
|
665
796
|
getSystemInfo,
|
|
666
797
|
getSystemInfoSync: getSystemInfo,
|
|
798
|
+
getUserProfile,
|
|
667
799
|
connectSocket: {
|
|
668
800
|
args: {
|
|
669
801
|
method: false
|
|
@@ -1029,7 +1161,11 @@ function initTriggerEvent (mpInstance) {
|
|
|
1029
1161
|
};
|
|
1030
1162
|
}
|
|
1031
1163
|
|
|
1032
|
-
function initHook (name, options) {
|
|
1164
|
+
function initHook (name, options, isComponent) {
|
|
1165
|
+
{
|
|
1166
|
+
// fix by Lxh 字节自定义组件Component构造器文档上写有created,但是实测只触发了lifetimes上的created
|
|
1167
|
+
isComponent && (options = options.lifetimes);
|
|
1168
|
+
}
|
|
1033
1169
|
const oldHook = options[name];
|
|
1034
1170
|
if (!oldHook) {
|
|
1035
1171
|
options[name] = function () {
|
|
@@ -1051,7 +1187,7 @@ if (!MPPage.__$wrappered) {
|
|
|
1051
1187
|
Page.after = MPPage.after;
|
|
1052
1188
|
|
|
1053
1189
|
Component = function (options = {}) {
|
|
1054
|
-
initHook('created', options);
|
|
1190
|
+
initHook('created', options, true);
|
|
1055
1191
|
return MPComponent(options)
|
|
1056
1192
|
};
|
|
1057
1193
|
}
|
|
@@ -1267,6 +1403,11 @@ function initProperties (props, isBehavior = false, file = '') {
|
|
|
1267
1403
|
type: Object,
|
|
1268
1404
|
value: null
|
|
1269
1405
|
};
|
|
1406
|
+
// scopedSlotsCompiler auto
|
|
1407
|
+
properties.scopedSlotsCompiler = {
|
|
1408
|
+
type: String,
|
|
1409
|
+
value: ''
|
|
1410
|
+
};
|
|
1270
1411
|
properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
|
|
1271
1412
|
type: null,
|
|
1272
1413
|
value: [],
|
|
@@ -1594,109 +1735,215 @@ function handleEvent (event) {
|
|
|
1594
1735
|
}
|
|
1595
1736
|
}
|
|
1596
1737
|
|
|
1597
|
-
|
|
1598
|
-
'onShow',
|
|
1599
|
-
'onHide',
|
|
1600
|
-
'onError',
|
|
1601
|
-
'onPageNotFound',
|
|
1602
|
-
'onThemeChange',
|
|
1603
|
-
'onUnhandledRejection'
|
|
1604
|
-
];
|
|
1738
|
+
let locale;
|
|
1605
1739
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
if (!this.__eventChannel__) {
|
|
1609
|
-
this.__eventChannel__ = new EventChannel();
|
|
1610
|
-
}
|
|
1611
|
-
return this.__eventChannel__
|
|
1612
|
-
};
|
|
1613
|
-
const callHook = Vue.prototype.__call_hook;
|
|
1614
|
-
Vue.prototype.__call_hook = function (hook, args) {
|
|
1615
|
-
if (hook === 'onLoad' && args && args.__id__) {
|
|
1616
|
-
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1617
|
-
delete args.__id__;
|
|
1618
|
-
}
|
|
1619
|
-
return callHook.call(this, hook, args)
|
|
1620
|
-
};
|
|
1740
|
+
{
|
|
1741
|
+
locale = tt.getSystemInfoSync().language;
|
|
1621
1742
|
}
|
|
1622
1743
|
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1744
|
+
const i18n = initVueI18n(
|
|
1745
|
+
locale,
|
|
1746
|
+
{}
|
|
1747
|
+
);
|
|
1748
|
+
const t = i18n.t;
|
|
1749
|
+
const i18nMixin = (i18n.mixin = {
|
|
1750
|
+
beforeCreate () {
|
|
1751
|
+
const unwatch = i18n.i18n.watchLocale(() => {
|
|
1752
|
+
this.$forceUpdate();
|
|
1753
|
+
});
|
|
1754
|
+
this.$once('hook:beforeDestroy', function () {
|
|
1755
|
+
unwatch();
|
|
1756
|
+
});
|
|
1757
|
+
},
|
|
1758
|
+
methods: {
|
|
1759
|
+
$$t (key, values) {
|
|
1760
|
+
return t(key, values)
|
|
1761
|
+
}
|
|
1630
1762
|
}
|
|
1763
|
+
});
|
|
1764
|
+
const setLocale$1 = i18n.setLocale;
|
|
1765
|
+
const getLocale$1 = i18n.getLocale;
|
|
1631
1766
|
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
beforeCreate () {
|
|
1636
|
-
if (!this.$options.mpType) {
|
|
1637
|
-
return
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
this.mpType = this.$options.mpType;
|
|
1641
|
-
|
|
1642
|
-
this.$mp = {
|
|
1643
|
-
data: {},
|
|
1644
|
-
[this.mpType]: this.$options.mpInstance
|
|
1645
|
-
};
|
|
1646
|
-
|
|
1647
|
-
this.$scope = this.$options.mpInstance;
|
|
1648
|
-
|
|
1649
|
-
delete this.$options.mpType;
|
|
1650
|
-
delete this.$options.mpInstance;
|
|
1651
|
-
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
|
|
1652
|
-
const app = getApp();
|
|
1653
|
-
if (app.$vm && app.$vm.$i18n) {
|
|
1654
|
-
this._i18n = app.$vm.$i18n;
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
if (this.mpType !== 'app') {
|
|
1658
|
-
initRefs(this);
|
|
1659
|
-
initMocks(this, mocks);
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1767
|
+
function initAppLocale (Vue, appVm, locale) {
|
|
1768
|
+
const state = Vue.observable({
|
|
1769
|
+
locale: locale || i18n.getLocale()
|
|
1662
1770
|
});
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1667
|
-
return
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
this.$vm = vm;
|
|
1671
|
-
|
|
1672
|
-
this.$vm.$mp = {
|
|
1673
|
-
app: this
|
|
1674
|
-
};
|
|
1675
|
-
|
|
1676
|
-
this.$vm.$scope = this;
|
|
1677
|
-
// vm 上也挂载 globalData
|
|
1678
|
-
this.$vm.globalData = this.globalData;
|
|
1679
|
-
|
|
1680
|
-
this.$vm._isMounted = true;
|
|
1681
|
-
this.$vm.__call_hook('mounted', args);
|
|
1682
|
-
|
|
1683
|
-
this.$vm.__call_hook('onLaunch', args);
|
|
1684
|
-
}
|
|
1771
|
+
const localeWatchers = [];
|
|
1772
|
+
appVm.$watchLocale = fn => {
|
|
1773
|
+
localeWatchers.push(fn);
|
|
1685
1774
|
};
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1775
|
+
Object.defineProperty(appVm, '$locale', {
|
|
1776
|
+
get () {
|
|
1777
|
+
return state.locale
|
|
1778
|
+
},
|
|
1779
|
+
set (v) {
|
|
1780
|
+
state.locale = v;
|
|
1781
|
+
localeWatchers.forEach(watch => watch(v));
|
|
1782
|
+
}
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
const hooks = [
|
|
1787
|
+
'onShow',
|
|
1788
|
+
'onHide',
|
|
1789
|
+
'onError',
|
|
1790
|
+
'onPageNotFound',
|
|
1791
|
+
'onThemeChange',
|
|
1792
|
+
'onUnhandledRejection'
|
|
1793
|
+
];
|
|
1794
|
+
|
|
1795
|
+
function initEventChannel$1 () {
|
|
1796
|
+
Vue.prototype.getOpenerEventChannel = function () {
|
|
1797
|
+
if (!this.__eventChannel__) {
|
|
1798
|
+
this.__eventChannel__ = new EventChannel();
|
|
1799
|
+
}
|
|
1800
|
+
return this.__eventChannel__
|
|
1801
|
+
};
|
|
1802
|
+
const callHook = Vue.prototype.__call_hook;
|
|
1803
|
+
Vue.prototype.__call_hook = function (hook, args) {
|
|
1804
|
+
if (hook === 'onLoad' && args && args.__id__) {
|
|
1805
|
+
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1806
|
+
delete args.__id__;
|
|
1807
|
+
}
|
|
1808
|
+
return callHook.call(this, hook, args)
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
function initScopedSlotsParams () {
|
|
1813
|
+
const center = {};
|
|
1814
|
+
const parents = {};
|
|
1815
|
+
|
|
1816
|
+
Vue.prototype.$hasScopedSlotsParams = function (vueId) {
|
|
1817
|
+
const has = center[vueId];
|
|
1818
|
+
if (!has) {
|
|
1819
|
+
parents[vueId] = this;
|
|
1820
|
+
this.$on('hook:destroyed', () => {
|
|
1821
|
+
delete parents[vueId];
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
return has
|
|
1825
|
+
};
|
|
1826
|
+
|
|
1827
|
+
Vue.prototype.$getScopedSlotsParams = function (vueId, name, key) {
|
|
1828
|
+
const data = center[vueId];
|
|
1829
|
+
if (data) {
|
|
1830
|
+
const object = data[name] || {};
|
|
1831
|
+
return key ? object[key] : object
|
|
1832
|
+
} else {
|
|
1833
|
+
parents[vueId] = this;
|
|
1834
|
+
this.$on('hook:destroyed', () => {
|
|
1835
|
+
delete parents[vueId];
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1838
|
+
};
|
|
1839
|
+
|
|
1840
|
+
Vue.prototype.$setScopedSlotsParams = function (name, value) {
|
|
1841
|
+
const vueIds = this.$options.propsData.vueId;
|
|
1842
|
+
if (vueIds) {
|
|
1843
|
+
const vueId = vueIds.split(',')[0];
|
|
1844
|
+
const object = center[vueId] = center[vueId] || {};
|
|
1845
|
+
object[name] = value;
|
|
1846
|
+
if (parents[vueId]) {
|
|
1847
|
+
parents[vueId].$forceUpdate();
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
|
|
1852
|
+
Vue.mixin({
|
|
1853
|
+
destroyed () {
|
|
1854
|
+
const propsData = this.$options.propsData;
|
|
1855
|
+
const vueId = propsData && propsData.vueId;
|
|
1856
|
+
if (vueId) {
|
|
1857
|
+
delete center[vueId];
|
|
1858
|
+
delete parents[vueId];
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
function parseBaseApp (vm, {
|
|
1865
|
+
mocks,
|
|
1866
|
+
initRefs
|
|
1867
|
+
}) {
|
|
1868
|
+
initEventChannel$1();
|
|
1869
|
+
{
|
|
1870
|
+
initScopedSlotsParams();
|
|
1871
|
+
}
|
|
1872
|
+
if (vm.$options.store) {
|
|
1873
|
+
Vue.prototype.$store = vm.$options.store;
|
|
1874
|
+
}
|
|
1875
|
+
uniIdMixin(Vue);
|
|
1876
|
+
|
|
1877
|
+
Vue.prototype.mpHost = "mp-toutiao";
|
|
1878
|
+
|
|
1879
|
+
Vue.mixin({
|
|
1880
|
+
beforeCreate () {
|
|
1881
|
+
if (!this.$options.mpType) {
|
|
1882
|
+
return
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
this.mpType = this.$options.mpType;
|
|
1886
|
+
|
|
1887
|
+
this.$mp = {
|
|
1888
|
+
data: {},
|
|
1889
|
+
[this.mpType]: this.$options.mpInstance
|
|
1890
|
+
};
|
|
1891
|
+
|
|
1892
|
+
this.$scope = this.$options.mpInstance;
|
|
1893
|
+
|
|
1894
|
+
delete this.$options.mpType;
|
|
1895
|
+
delete this.$options.mpInstance;
|
|
1896
|
+
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
|
|
1897
|
+
const app = getApp();
|
|
1898
|
+
if (app.$vm && app.$vm.$i18n) {
|
|
1899
|
+
this._i18n = app.$vm.$i18n;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
if (this.mpType !== 'app') {
|
|
1903
|
+
initRefs(this);
|
|
1904
|
+
initMocks(this, mocks);
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
});
|
|
1908
|
+
|
|
1909
|
+
const appOptions = {
|
|
1910
|
+
onLaunch (args) {
|
|
1911
|
+
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1912
|
+
return
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
this.$vm = vm;
|
|
1916
|
+
|
|
1917
|
+
this.$vm.$mp = {
|
|
1918
|
+
app: this
|
|
1919
|
+
};
|
|
1920
|
+
|
|
1921
|
+
this.$vm.$scope = this;
|
|
1922
|
+
// vm 上也挂载 globalData
|
|
1923
|
+
this.$vm.globalData = this.globalData;
|
|
1924
|
+
|
|
1925
|
+
this.$vm._isMounted = true;
|
|
1926
|
+
this.$vm.__call_hook('mounted', args);
|
|
1927
|
+
|
|
1928
|
+
this.$vm.__call_hook('onLaunch', args);
|
|
1929
|
+
}
|
|
1930
|
+
};
|
|
1931
|
+
|
|
1932
|
+
// 兼容旧版本 globalData
|
|
1933
|
+
appOptions.globalData = vm.$options.globalData || {};
|
|
1934
|
+
// 将 methods 中的方法挂在 getApp() 中
|
|
1935
|
+
const methods = vm.$options.methods;
|
|
1936
|
+
if (methods) {
|
|
1937
|
+
Object.keys(methods).forEach(name => {
|
|
1938
|
+
appOptions[name] = methods[name];
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
initAppLocale(Vue, vm, tt.getSystemInfoSync().language || 'zh-Hans');
|
|
1943
|
+
|
|
1944
|
+
initHooks(appOptions, hooks);
|
|
1945
|
+
|
|
1946
|
+
return appOptions
|
|
1700
1947
|
}
|
|
1701
1948
|
|
|
1702
1949
|
function findVmByVueId (vm, vuePid) {
|
|
@@ -2010,34 +2257,50 @@ function parseBaseComponent (vueComponentOptions, {
|
|
|
2010
2257
|
return [componentOptions, VueComponent]
|
|
2011
2258
|
}
|
|
2012
2259
|
|
|
2260
|
+
const components = [];
|
|
2261
|
+
|
|
2013
2262
|
function parseComponent (vueOptions) {
|
|
2014
2263
|
const [componentOptions, VueComponent] = parseBaseComponent(vueOptions);
|
|
2015
2264
|
|
|
2265
|
+
// 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
|
|
2266
|
+
componentOptions.lifetimes.created = function created () {
|
|
2267
|
+
components.push(this);
|
|
2268
|
+
};
|
|
2269
|
+
|
|
2016
2270
|
componentOptions.lifetimes.attached = function attached () {
|
|
2017
|
-
|
|
2271
|
+
this.__lifetimes_attached = function () {
|
|
2272
|
+
const properties = this.properties;
|
|
2018
2273
|
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2274
|
+
const options = {
|
|
2275
|
+
mpType: isPage.call(this) ? 'page' : 'component',
|
|
2276
|
+
mpInstance: this,
|
|
2277
|
+
propsData: properties
|
|
2278
|
+
};
|
|
2024
2279
|
|
|
2025
|
-
|
|
2280
|
+
initVueIds(properties.vueId, this);
|
|
2026
2281
|
|
|
2027
|
-
|
|
2028
|
-
|
|
2282
|
+
// 初始化 vue 实例
|
|
2283
|
+
this.$vm = new VueComponent(options);
|
|
2029
2284
|
|
|
2030
|
-
|
|
2031
|
-
|
|
2285
|
+
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
|
|
2286
|
+
initSlots(this.$vm, properties.vueSlots);
|
|
2032
2287
|
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2288
|
+
// 处理父子关系
|
|
2289
|
+
initRelation.call(this, {
|
|
2290
|
+
vuePid: this._$vuePid,
|
|
2291
|
+
mpInstance: this
|
|
2292
|
+
});
|
|
2038
2293
|
|
|
2039
|
-
|
|
2040
|
-
|
|
2294
|
+
// 触发首次 setData
|
|
2295
|
+
this.$vm.$mount();
|
|
2296
|
+
};
|
|
2297
|
+
let component = this;
|
|
2298
|
+
while (component && component.__lifetimes_attached && components[0] && component === components[0]) {
|
|
2299
|
+
components.shift();
|
|
2300
|
+
component.__lifetimes_attached();
|
|
2301
|
+
delete component.__lifetimes_attached;
|
|
2302
|
+
component = components[0];
|
|
2303
|
+
}
|
|
2041
2304
|
};
|
|
2042
2305
|
|
|
2043
2306
|
// ready 比 handleLink 还早,初始化逻辑放到 handleLink 中
|
|
@@ -2127,6 +2390,7 @@ function createSubpackageApp (vm) {
|
|
|
2127
2390
|
const app = getApp({
|
|
2128
2391
|
allowDefault: true
|
|
2129
2392
|
});
|
|
2393
|
+
vm.$scope = app;
|
|
2130
2394
|
const globalData = app.globalData;
|
|
2131
2395
|
if (globalData) {
|
|
2132
2396
|
Object.keys(appOptions.globalData).forEach(name => {
|
|
@@ -2141,18 +2405,18 @@ function createSubpackageApp (vm) {
|
|
|
2141
2405
|
}
|
|
2142
2406
|
});
|
|
2143
2407
|
if (isFn(appOptions.onShow) && tt.onAppShow) {
|
|
2144
|
-
tt.onAppShow((...args) => {
|
|
2145
|
-
|
|
2408
|
+
tt.onAppShow((...args) => {
|
|
2409
|
+
vm.__call_hook('onShow', args);
|
|
2146
2410
|
});
|
|
2147
2411
|
}
|
|
2148
2412
|
if (isFn(appOptions.onHide) && tt.onAppHide) {
|
|
2149
|
-
tt.onAppHide((...args) => {
|
|
2150
|
-
|
|
2413
|
+
tt.onAppHide((...args) => {
|
|
2414
|
+
vm.__call_hook('onHide', args);
|
|
2151
2415
|
});
|
|
2152
2416
|
}
|
|
2153
2417
|
if (isFn(appOptions.onLaunch)) {
|
|
2154
2418
|
const args = tt.getLaunchOptionsSync && tt.getLaunchOptionsSync();
|
|
2155
|
-
|
|
2419
|
+
vm.__call_hook('onLaunch', args);
|
|
2156
2420
|
}
|
|
2157
2421
|
return vm
|
|
2158
2422
|
}
|