@dcloudio/uni-mp-qq 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 +367 -123
- package/dist/uni.api.esm.js +500 -132
- package/dist/uni.mp.esm.js +518 -187
- 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 = ( wx).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 wx.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,12 +684,20 @@ var getSystemInfo = {
|
|
|
560
684
|
}
|
|
561
685
|
};
|
|
562
686
|
|
|
687
|
+
const oName = 'getUserInfo';
|
|
688
|
+
const nName = 'getUserProfile';
|
|
689
|
+
|
|
690
|
+
var getUserProfile = {
|
|
691
|
+
name: wx.canIUse(nName) ? nName : oName
|
|
692
|
+
};
|
|
693
|
+
|
|
563
694
|
const protocols = {
|
|
564
695
|
navigateTo,
|
|
565
696
|
redirectTo,
|
|
566
697
|
previewImage,
|
|
567
698
|
getSystemInfo,
|
|
568
|
-
getSystemInfoSync: getSystemInfo
|
|
699
|
+
getSystemInfoSync: getSystemInfo,
|
|
700
|
+
getUserProfile
|
|
569
701
|
};
|
|
570
702
|
const todos = [
|
|
571
703
|
'preloadPage',
|
|
@@ -937,7 +1069,7 @@ function initTriggerEvent (mpInstance) {
|
|
|
937
1069
|
};
|
|
938
1070
|
}
|
|
939
1071
|
|
|
940
|
-
function initHook (name, options) {
|
|
1072
|
+
function initHook (name, options, isComponent) {
|
|
941
1073
|
const oldHook = options[name];
|
|
942
1074
|
if (!oldHook) {
|
|
943
1075
|
options[name] = function () {
|
|
@@ -1175,6 +1307,11 @@ function initProperties (props, isBehavior = false, file = '') {
|
|
|
1175
1307
|
type: Object,
|
|
1176
1308
|
value: null
|
|
1177
1309
|
};
|
|
1310
|
+
// scopedSlotsCompiler auto
|
|
1311
|
+
properties.scopedSlotsCompiler = {
|
|
1312
|
+
type: String,
|
|
1313
|
+
value: ''
|
|
1314
|
+
};
|
|
1178
1315
|
properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
|
|
1179
1316
|
type: null,
|
|
1180
1317
|
value: [],
|
|
@@ -1502,114 +1639,220 @@ function handleEvent (event) {
|
|
|
1502
1639
|
}
|
|
1503
1640
|
}
|
|
1504
1641
|
|
|
1505
|
-
|
|
1506
|
-
'onShow',
|
|
1507
|
-
'onHide',
|
|
1508
|
-
'onError',
|
|
1509
|
-
'onPageNotFound',
|
|
1510
|
-
'onThemeChange',
|
|
1511
|
-
'onUnhandledRejection'
|
|
1512
|
-
];
|
|
1642
|
+
let locale;
|
|
1513
1643
|
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
if (!this.__eventChannel__) {
|
|
1517
|
-
this.__eventChannel__ = new EventChannel();
|
|
1518
|
-
}
|
|
1519
|
-
return this.__eventChannel__
|
|
1520
|
-
};
|
|
1521
|
-
const callHook = Vue.prototype.__call_hook;
|
|
1522
|
-
Vue.prototype.__call_hook = function (hook, args) {
|
|
1523
|
-
if (hook === 'onLoad' && args && args.__id__) {
|
|
1524
|
-
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1525
|
-
delete args.__id__;
|
|
1526
|
-
}
|
|
1527
|
-
return callHook.call(this, hook, args)
|
|
1528
|
-
};
|
|
1644
|
+
{
|
|
1645
|
+
locale = wx.getSystemInfoSync().language;
|
|
1529
1646
|
}
|
|
1530
1647
|
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1648
|
+
const i18n = initVueI18n(
|
|
1649
|
+
locale,
|
|
1650
|
+
{}
|
|
1651
|
+
);
|
|
1652
|
+
const t = i18n.t;
|
|
1653
|
+
const i18nMixin = (i18n.mixin = {
|
|
1654
|
+
beforeCreate () {
|
|
1655
|
+
const unwatch = i18n.i18n.watchLocale(() => {
|
|
1656
|
+
this.$forceUpdate();
|
|
1657
|
+
});
|
|
1658
|
+
this.$once('hook:beforeDestroy', function () {
|
|
1659
|
+
unwatch();
|
|
1660
|
+
});
|
|
1661
|
+
},
|
|
1662
|
+
methods: {
|
|
1663
|
+
$$t (key, values) {
|
|
1664
|
+
return t(key, values)
|
|
1665
|
+
}
|
|
1538
1666
|
}
|
|
1667
|
+
});
|
|
1668
|
+
const setLocale$1 = i18n.setLocale;
|
|
1669
|
+
const getLocale$1 = i18n.getLocale;
|
|
1539
1670
|
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
beforeCreate () {
|
|
1544
|
-
if (!this.$options.mpType) {
|
|
1545
|
-
return
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
this.mpType = this.$options.mpType;
|
|
1549
|
-
|
|
1550
|
-
this.$mp = {
|
|
1551
|
-
data: {},
|
|
1552
|
-
[this.mpType]: this.$options.mpInstance
|
|
1553
|
-
};
|
|
1554
|
-
|
|
1555
|
-
this.$scope = this.$options.mpInstance;
|
|
1556
|
-
|
|
1557
|
-
delete this.$options.mpType;
|
|
1558
|
-
delete this.$options.mpInstance;
|
|
1559
|
-
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
|
|
1560
|
-
const app = getApp();
|
|
1561
|
-
if (app.$vm && app.$vm.$i18n) {
|
|
1562
|
-
this._i18n = app.$vm.$i18n;
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
if (this.mpType !== 'app') {
|
|
1566
|
-
initRefs(this);
|
|
1567
|
-
initMocks(this, mocks);
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1671
|
+
function initAppLocale (Vue, appVm, locale) {
|
|
1672
|
+
const state = Vue.observable({
|
|
1673
|
+
locale: locale || i18n.getLocale()
|
|
1570
1674
|
});
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1575
|
-
return
|
|
1576
|
-
}
|
|
1577
|
-
{
|
|
1578
|
-
if (wx.canIUse && !wx.canIUse('nextTick')) { // 事实 上2.2.3 即可,简单使用 2.3.0 的 nextTick 判断
|
|
1579
|
-
console.error('当前微信基础库版本过低,请将 微信开发者工具-详情-项目设置-调试基础库版本 更换为`2.3.0`以上');
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
this.$vm = vm;
|
|
1584
|
-
|
|
1585
|
-
this.$vm.$mp = {
|
|
1586
|
-
app: this
|
|
1587
|
-
};
|
|
1588
|
-
|
|
1589
|
-
this.$vm.$scope = this;
|
|
1590
|
-
// vm 上也挂载 globalData
|
|
1591
|
-
this.$vm.globalData = this.globalData;
|
|
1592
|
-
|
|
1593
|
-
this.$vm._isMounted = true;
|
|
1594
|
-
this.$vm.__call_hook('mounted', args);
|
|
1595
|
-
|
|
1596
|
-
this.$vm.__call_hook('onLaunch', args);
|
|
1597
|
-
}
|
|
1675
|
+
const localeWatchers = [];
|
|
1676
|
+
appVm.$watchLocale = fn => {
|
|
1677
|
+
localeWatchers.push(fn);
|
|
1598
1678
|
};
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1679
|
+
Object.defineProperty(appVm, '$locale', {
|
|
1680
|
+
get () {
|
|
1681
|
+
return state.locale
|
|
1682
|
+
},
|
|
1683
|
+
set (v) {
|
|
1684
|
+
state.locale = v;
|
|
1685
|
+
localeWatchers.forEach(watch => watch(v));
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
const hooks = [
|
|
1691
|
+
'onShow',
|
|
1692
|
+
'onHide',
|
|
1693
|
+
'onError',
|
|
1694
|
+
'onPageNotFound',
|
|
1695
|
+
'onThemeChange',
|
|
1696
|
+
'onUnhandledRejection'
|
|
1697
|
+
];
|
|
1698
|
+
|
|
1699
|
+
function initEventChannel$1 () {
|
|
1700
|
+
Vue.prototype.getOpenerEventChannel = function () {
|
|
1701
|
+
if (!this.__eventChannel__) {
|
|
1702
|
+
this.__eventChannel__ = new EventChannel();
|
|
1703
|
+
}
|
|
1704
|
+
return this.__eventChannel__
|
|
1705
|
+
};
|
|
1706
|
+
const callHook = Vue.prototype.__call_hook;
|
|
1707
|
+
Vue.prototype.__call_hook = function (hook, args) {
|
|
1708
|
+
if (hook === 'onLoad' && args && args.__id__) {
|
|
1709
|
+
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1710
|
+
delete args.__id__;
|
|
1711
|
+
}
|
|
1712
|
+
return callHook.call(this, hook, args)
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
function initScopedSlotsParams () {
|
|
1717
|
+
const center = {};
|
|
1718
|
+
const parents = {};
|
|
1719
|
+
|
|
1720
|
+
Vue.prototype.$hasScopedSlotsParams = function (vueId) {
|
|
1721
|
+
const has = center[vueId];
|
|
1722
|
+
if (!has) {
|
|
1723
|
+
parents[vueId] = this;
|
|
1724
|
+
this.$on('hook:destroyed', () => {
|
|
1725
|
+
delete parents[vueId];
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
return has
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
Vue.prototype.$getScopedSlotsParams = function (vueId, name, key) {
|
|
1732
|
+
const data = center[vueId];
|
|
1733
|
+
if (data) {
|
|
1734
|
+
const object = data[name] || {};
|
|
1735
|
+
return key ? object[key] : object
|
|
1736
|
+
} else {
|
|
1737
|
+
parents[vueId] = this;
|
|
1738
|
+
this.$on('hook:destroyed', () => {
|
|
1739
|
+
delete parents[vueId];
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
|
|
1744
|
+
Vue.prototype.$setScopedSlotsParams = function (name, value) {
|
|
1745
|
+
const vueIds = this.$options.propsData.vueId;
|
|
1746
|
+
if (vueIds) {
|
|
1747
|
+
const vueId = vueIds.split(',')[0];
|
|
1748
|
+
const object = center[vueId] = center[vueId] || {};
|
|
1749
|
+
object[name] = value;
|
|
1750
|
+
if (parents[vueId]) {
|
|
1751
|
+
parents[vueId].$forceUpdate();
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
};
|
|
1755
|
+
|
|
1756
|
+
Vue.mixin({
|
|
1757
|
+
destroyed () {
|
|
1758
|
+
const propsData = this.$options.propsData;
|
|
1759
|
+
const vueId = propsData && propsData.vueId;
|
|
1760
|
+
if (vueId) {
|
|
1761
|
+
delete center[vueId];
|
|
1762
|
+
delete parents[vueId];
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
function parseBaseApp (vm, {
|
|
1769
|
+
mocks,
|
|
1770
|
+
initRefs
|
|
1771
|
+
}) {
|
|
1772
|
+
initEventChannel$1();
|
|
1773
|
+
{
|
|
1774
|
+
initScopedSlotsParams();
|
|
1775
|
+
}
|
|
1776
|
+
if (vm.$options.store) {
|
|
1777
|
+
Vue.prototype.$store = vm.$options.store;
|
|
1778
|
+
}
|
|
1779
|
+
uniIdMixin(Vue);
|
|
1780
|
+
|
|
1781
|
+
Vue.prototype.mpHost = "mp-qq";
|
|
1782
|
+
|
|
1783
|
+
Vue.mixin({
|
|
1784
|
+
beforeCreate () {
|
|
1785
|
+
if (!this.$options.mpType) {
|
|
1786
|
+
return
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
this.mpType = this.$options.mpType;
|
|
1790
|
+
|
|
1791
|
+
this.$mp = {
|
|
1792
|
+
data: {},
|
|
1793
|
+
[this.mpType]: this.$options.mpInstance
|
|
1794
|
+
};
|
|
1795
|
+
|
|
1796
|
+
this.$scope = this.$options.mpInstance;
|
|
1797
|
+
|
|
1798
|
+
delete this.$options.mpType;
|
|
1799
|
+
delete this.$options.mpInstance;
|
|
1800
|
+
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
|
|
1801
|
+
const app = getApp();
|
|
1802
|
+
if (app.$vm && app.$vm.$i18n) {
|
|
1803
|
+
this._i18n = app.$vm.$i18n;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
if (this.mpType !== 'app') {
|
|
1807
|
+
initRefs(this);
|
|
1808
|
+
initMocks(this, mocks);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
|
|
1813
|
+
const appOptions = {
|
|
1814
|
+
onLaunch (args) {
|
|
1815
|
+
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1816
|
+
return
|
|
1817
|
+
}
|
|
1818
|
+
{
|
|
1819
|
+
if (wx.canIUse && !wx.canIUse('nextTick')) { // 事实 上2.2.3 即可,简单使用 2.3.0 的 nextTick 判断
|
|
1820
|
+
console.error('当前微信基础库版本过低,请将 微信开发者工具-详情-项目设置-调试基础库版本 更换为`2.3.0`以上');
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
this.$vm = vm;
|
|
1825
|
+
|
|
1826
|
+
this.$vm.$mp = {
|
|
1827
|
+
app: this
|
|
1828
|
+
};
|
|
1829
|
+
|
|
1830
|
+
this.$vm.$scope = this;
|
|
1831
|
+
// vm 上也挂载 globalData
|
|
1832
|
+
this.$vm.globalData = this.globalData;
|
|
1833
|
+
|
|
1834
|
+
this.$vm._isMounted = true;
|
|
1835
|
+
this.$vm.__call_hook('mounted', args);
|
|
1836
|
+
|
|
1837
|
+
this.$vm.__call_hook('onLaunch', args);
|
|
1838
|
+
}
|
|
1839
|
+
};
|
|
1840
|
+
|
|
1841
|
+
// 兼容旧版本 globalData
|
|
1842
|
+
appOptions.globalData = vm.$options.globalData || {};
|
|
1843
|
+
// 将 methods 中的方法挂在 getApp() 中
|
|
1844
|
+
const methods = vm.$options.methods;
|
|
1845
|
+
if (methods) {
|
|
1846
|
+
Object.keys(methods).forEach(name => {
|
|
1847
|
+
appOptions[name] = methods[name];
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
initAppLocale(Vue, vm, wx.getSystemInfoSync().language || 'zh-Hans');
|
|
1852
|
+
|
|
1853
|
+
initHooks(appOptions, hooks);
|
|
1854
|
+
|
|
1855
|
+
return appOptions
|
|
1613
1856
|
}
|
|
1614
1857
|
|
|
1615
1858
|
const mocks = ['__route__', '__wxExparserNodeId__', '__wxWebviewId__'];
|
|
@@ -1919,6 +2162,7 @@ function createSubpackageApp (vm) {
|
|
|
1919
2162
|
const app = getApp({
|
|
1920
2163
|
allowDefault: true
|
|
1921
2164
|
});
|
|
2165
|
+
vm.$scope = app;
|
|
1922
2166
|
const globalData = app.globalData;
|
|
1923
2167
|
if (globalData) {
|
|
1924
2168
|
Object.keys(appOptions.globalData).forEach(name => {
|
|
@@ -1933,18 +2177,18 @@ function createSubpackageApp (vm) {
|
|
|
1933
2177
|
}
|
|
1934
2178
|
});
|
|
1935
2179
|
if (isFn(appOptions.onShow) && wx.onAppShow) {
|
|
1936
|
-
wx.onAppShow((...args) => {
|
|
1937
|
-
|
|
2180
|
+
wx.onAppShow((...args) => {
|
|
2181
|
+
vm.__call_hook('onShow', args);
|
|
1938
2182
|
});
|
|
1939
2183
|
}
|
|
1940
2184
|
if (isFn(appOptions.onHide) && wx.onAppHide) {
|
|
1941
|
-
wx.onAppHide((...args) => {
|
|
1942
|
-
|
|
2185
|
+
wx.onAppHide((...args) => {
|
|
2186
|
+
vm.__call_hook('onHide', args);
|
|
1943
2187
|
});
|
|
1944
2188
|
}
|
|
1945
2189
|
if (isFn(appOptions.onLaunch)) {
|
|
1946
2190
|
const args = wx.getLaunchOptionsSync && wx.getLaunchOptionsSync();
|
|
1947
|
-
|
|
2191
|
+
vm.__call_hook('onLaunch', args);
|
|
1948
2192
|
}
|
|
1949
2193
|
return vm
|
|
1950
2194
|
}
|