@dcloudio/uni-quickapp-webview 2.0.0-32620210831002 → 2.0.0-32920210926001
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 +185 -97
- package/dist/uni.api.esm.js +32 -1
- package/dist/uni.mp.esm.js +15 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Vue from 'vue';
|
|
2
|
+
import { initVueI18n } from '@dcloudio/uni-i18n';
|
|
2
3
|
|
|
3
4
|
function b64DecodeUnicode (str) {
|
|
4
5
|
return decodeURIComponent(atob(str).split('').map(function (c) {
|
|
@@ -398,6 +399,40 @@ function upx2px (number, newDeviceWidth) {
|
|
|
398
399
|
return number < 0 ? -result : result
|
|
399
400
|
}
|
|
400
401
|
|
|
402
|
+
function getLocale () {
|
|
403
|
+
// 优先使用 $locale
|
|
404
|
+
const app = getApp({
|
|
405
|
+
allowDefault: true
|
|
406
|
+
});
|
|
407
|
+
if (app && app.$vm) {
|
|
408
|
+
return app.$vm.$locale
|
|
409
|
+
}
|
|
410
|
+
return qa.getSystemInfoSync().language || 'zh-Hans'
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function setLocale (locale) {
|
|
414
|
+
const app = getApp();
|
|
415
|
+
if (!app) {
|
|
416
|
+
return false
|
|
417
|
+
}
|
|
418
|
+
const oldLocale = app.$vm.$locale;
|
|
419
|
+
if (oldLocale !== locale) {
|
|
420
|
+
app.$vm.$locale = locale;
|
|
421
|
+
onLocaleChangeCallbacks.forEach((fn) => fn({
|
|
422
|
+
locale
|
|
423
|
+
}));
|
|
424
|
+
return true
|
|
425
|
+
}
|
|
426
|
+
return false
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const onLocaleChangeCallbacks = [];
|
|
430
|
+
function onLocaleChange (fn) {
|
|
431
|
+
if (onLocaleChangeCallbacks.indexOf(fn) === -1) {
|
|
432
|
+
onLocaleChangeCallbacks.push(fn);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
401
436
|
const interceptors = {
|
|
402
437
|
promiseInterceptor
|
|
403
438
|
};
|
|
@@ -405,6 +440,9 @@ const interceptors = {
|
|
|
405
440
|
var baseApi = /*#__PURE__*/Object.freeze({
|
|
406
441
|
__proto__: null,
|
|
407
442
|
upx2px: upx2px,
|
|
443
|
+
getLocale: getLocale,
|
|
444
|
+
setLocale: setLocale,
|
|
445
|
+
onLocaleChange: onLocaleChange,
|
|
408
446
|
addInterceptor: addInterceptor,
|
|
409
447
|
removeInterceptor: removeInterceptor,
|
|
410
448
|
interceptors: interceptors
|
|
@@ -1375,110 +1413,160 @@ function handleEvent (event) {
|
|
|
1375
1413
|
}
|
|
1376
1414
|
}
|
|
1377
1415
|
|
|
1378
|
-
|
|
1379
|
-
'onShow',
|
|
1380
|
-
'onHide',
|
|
1381
|
-
'onError',
|
|
1382
|
-
'onPageNotFound',
|
|
1383
|
-
'onThemeChange',
|
|
1384
|
-
'onUnhandledRejection'
|
|
1385
|
-
];
|
|
1416
|
+
let locale;
|
|
1386
1417
|
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
if (!this.__eventChannel__) {
|
|
1390
|
-
this.__eventChannel__ = new EventChannel();
|
|
1391
|
-
}
|
|
1392
|
-
return this.__eventChannel__
|
|
1393
|
-
};
|
|
1394
|
-
const callHook = Vue.prototype.__call_hook;
|
|
1395
|
-
Vue.prototype.__call_hook = function (hook, args) {
|
|
1396
|
-
if (hook === 'onLoad' && args && args.__id__) {
|
|
1397
|
-
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1398
|
-
delete args.__id__;
|
|
1399
|
-
}
|
|
1400
|
-
return callHook.call(this, hook, args)
|
|
1401
|
-
};
|
|
1418
|
+
{
|
|
1419
|
+
locale = qa.getSystemInfoSync().language;
|
|
1402
1420
|
}
|
|
1403
1421
|
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1422
|
+
const i18n = initVueI18n(
|
|
1423
|
+
locale,
|
|
1424
|
+
{}
|
|
1425
|
+
);
|
|
1426
|
+
const t = i18n.t;
|
|
1427
|
+
const i18nMixin = (i18n.mixin = {
|
|
1428
|
+
beforeCreate () {
|
|
1429
|
+
const unwatch = i18n.i18n.watchLocale(() => {
|
|
1430
|
+
this.$forceUpdate();
|
|
1431
|
+
});
|
|
1432
|
+
this.$once('hook:beforeDestroy', function () {
|
|
1433
|
+
unwatch();
|
|
1434
|
+
});
|
|
1435
|
+
},
|
|
1436
|
+
methods: {
|
|
1437
|
+
$$t (key, values) {
|
|
1438
|
+
return t(key, values)
|
|
1439
|
+
}
|
|
1411
1440
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
Vue.mixin({
|
|
1417
|
-
beforeCreate () {
|
|
1418
|
-
if (!this.$options.mpType) {
|
|
1419
|
-
return
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
this.mpType = this.$options.mpType;
|
|
1423
|
-
|
|
1424
|
-
this.$mp = {
|
|
1425
|
-
data: {},
|
|
1426
|
-
[this.mpType]: this.$options.mpInstance
|
|
1427
|
-
};
|
|
1428
|
-
|
|
1429
|
-
this.$scope = this.$options.mpInstance;
|
|
1441
|
+
});
|
|
1442
|
+
const setLocale$1 = i18n.setLocale;
|
|
1443
|
+
const getLocale$1 = i18n.getLocale;
|
|
1430
1444
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
const app = getApp();
|
|
1435
|
-
if (app.$vm && app.$vm.$i18n) {
|
|
1436
|
-
this._i18n = app.$vm.$i18n;
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
if (this.mpType !== 'app') {
|
|
1440
|
-
initRefs(this);
|
|
1441
|
-
initMocks(this, mocks);
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1445
|
+
function initAppLocale (Vue, appVm, locale) {
|
|
1446
|
+
const state = Vue.observable({
|
|
1447
|
+
locale: locale || i18n.getLocale()
|
|
1444
1448
|
});
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1449
|
-
return
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
this.$vm = vm;
|
|
1453
|
-
|
|
1454
|
-
this.$vm.$mp = {
|
|
1455
|
-
app: this
|
|
1456
|
-
};
|
|
1457
|
-
|
|
1458
|
-
this.$vm.$scope = this;
|
|
1459
|
-
// vm 上也挂载 globalData
|
|
1460
|
-
this.$vm.globalData = this.globalData;
|
|
1461
|
-
|
|
1462
|
-
this.$vm._isMounted = true;
|
|
1463
|
-
this.$vm.__call_hook('mounted', args);
|
|
1464
|
-
|
|
1465
|
-
this.$vm.__call_hook('onLaunch', args);
|
|
1466
|
-
}
|
|
1449
|
+
const localeWatchers = [];
|
|
1450
|
+
appVm.$watchLocale = fn => {
|
|
1451
|
+
localeWatchers.push(fn);
|
|
1467
1452
|
};
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1453
|
+
Object.defineProperty(appVm, '$locale', {
|
|
1454
|
+
get () {
|
|
1455
|
+
return state.locale
|
|
1456
|
+
},
|
|
1457
|
+
set (v) {
|
|
1458
|
+
state.locale = v;
|
|
1459
|
+
localeWatchers.forEach(watch => watch(v));
|
|
1460
|
+
}
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
const hooks = [
|
|
1465
|
+
'onShow',
|
|
1466
|
+
'onHide',
|
|
1467
|
+
'onError',
|
|
1468
|
+
'onPageNotFound',
|
|
1469
|
+
'onThemeChange',
|
|
1470
|
+
'onUnhandledRejection'
|
|
1471
|
+
];
|
|
1472
|
+
|
|
1473
|
+
function initEventChannel$1 () {
|
|
1474
|
+
Vue.prototype.getOpenerEventChannel = function () {
|
|
1475
|
+
if (!this.__eventChannel__) {
|
|
1476
|
+
this.__eventChannel__ = new EventChannel();
|
|
1477
|
+
}
|
|
1478
|
+
return this.__eventChannel__
|
|
1479
|
+
};
|
|
1480
|
+
const callHook = Vue.prototype.__call_hook;
|
|
1481
|
+
Vue.prototype.__call_hook = function (hook, args) {
|
|
1482
|
+
if (hook === 'onLoad' && args && args.__id__) {
|
|
1483
|
+
this.__eventChannel__ = getEventChannel(args.__id__);
|
|
1484
|
+
delete args.__id__;
|
|
1485
|
+
}
|
|
1486
|
+
return callHook.call(this, hook, args)
|
|
1487
|
+
};
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
function parseBaseApp (vm, {
|
|
1491
|
+
mocks,
|
|
1492
|
+
initRefs
|
|
1493
|
+
}) {
|
|
1494
|
+
initEventChannel$1();
|
|
1495
|
+
if (vm.$options.store) {
|
|
1496
|
+
Vue.prototype.$store = vm.$options.store;
|
|
1497
|
+
}
|
|
1498
|
+
uniIdMixin(Vue);
|
|
1499
|
+
|
|
1500
|
+
Vue.prototype.mpHost = "quickapp-webview";
|
|
1501
|
+
|
|
1502
|
+
Vue.mixin({
|
|
1503
|
+
beforeCreate () {
|
|
1504
|
+
if (!this.$options.mpType) {
|
|
1505
|
+
return
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
this.mpType = this.$options.mpType;
|
|
1509
|
+
|
|
1510
|
+
this.$mp = {
|
|
1511
|
+
data: {},
|
|
1512
|
+
[this.mpType]: this.$options.mpInstance
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1515
|
+
this.$scope = this.$options.mpInstance;
|
|
1516
|
+
|
|
1517
|
+
delete this.$options.mpType;
|
|
1518
|
+
delete this.$options.mpInstance;
|
|
1519
|
+
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
|
|
1520
|
+
const app = getApp();
|
|
1521
|
+
if (app.$vm && app.$vm.$i18n) {
|
|
1522
|
+
this._i18n = app.$vm.$i18n;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
if (this.mpType !== 'app') {
|
|
1526
|
+
initRefs(this);
|
|
1527
|
+
initMocks(this, mocks);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
const appOptions = {
|
|
1533
|
+
onLaunch (args) {
|
|
1534
|
+
if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
|
|
1535
|
+
return
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
this.$vm = vm;
|
|
1539
|
+
|
|
1540
|
+
this.$vm.$mp = {
|
|
1541
|
+
app: this
|
|
1542
|
+
};
|
|
1543
|
+
|
|
1544
|
+
this.$vm.$scope = this;
|
|
1545
|
+
// vm 上也挂载 globalData
|
|
1546
|
+
this.$vm.globalData = this.globalData;
|
|
1547
|
+
|
|
1548
|
+
this.$vm._isMounted = true;
|
|
1549
|
+
this.$vm.__call_hook('mounted', args);
|
|
1550
|
+
|
|
1551
|
+
this.$vm.__call_hook('onLaunch', args);
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
// 兼容旧版本 globalData
|
|
1556
|
+
appOptions.globalData = vm.$options.globalData || {};
|
|
1557
|
+
// 将 methods 中的方法挂在 getApp() 中
|
|
1558
|
+
const methods = vm.$options.methods;
|
|
1559
|
+
if (methods) {
|
|
1560
|
+
Object.keys(methods).forEach(name => {
|
|
1561
|
+
appOptions[name] = methods[name];
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
initAppLocale(Vue, vm, qa.getSystemInfoSync().language || 'zh-Hans');
|
|
1566
|
+
|
|
1567
|
+
initHooks(appOptions, hooks);
|
|
1568
|
+
|
|
1569
|
+
return appOptions
|
|
1482
1570
|
}
|
|
1483
1571
|
|
|
1484
1572
|
const mocks = ['nodeId', 'componentName', '_componentId', 'uniquePrefix'];
|
package/dist/uni.api.esm.js
CHANGED
|
@@ -583,7 +583,7 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
|
|
|
583
583
|
emitter.emit(name, ...args);
|
|
584
584
|
}, EmitProtocol);
|
|
585
585
|
|
|
586
|
-
const SYNC_API_RE = /^\$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
|
|
586
|
+
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
|
|
587
587
|
const CONTEXT_API_RE = /^create|Manager$/;
|
|
588
588
|
// Context例外情况
|
|
589
589
|
const CONTEXT_API_RE_EXC = ['createBLEConnection'];
|
|
@@ -727,6 +727,34 @@ function initWrapper(protocols) {
|
|
|
727
727
|
};
|
|
728
728
|
}
|
|
729
729
|
|
|
730
|
+
const getLocale = () => {
|
|
731
|
+
// 优先使用 $locale
|
|
732
|
+
const app = getApp({ allowDefault: true });
|
|
733
|
+
if (app && app.$vm) {
|
|
734
|
+
return app.$vm.$locale;
|
|
735
|
+
}
|
|
736
|
+
return uni.getSystemInfoSync().language || 'zh-Hans';
|
|
737
|
+
};
|
|
738
|
+
const setLocale = (locale) => {
|
|
739
|
+
const app = getApp();
|
|
740
|
+
if (!app) {
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
const oldLocale = app.$vm.$locale;
|
|
744
|
+
if (oldLocale !== locale) {
|
|
745
|
+
app.$vm.$locale = locale;
|
|
746
|
+
onLocaleChangeCallbacks.forEach((fn) => fn({ locale }));
|
|
747
|
+
return true;
|
|
748
|
+
}
|
|
749
|
+
return false;
|
|
750
|
+
};
|
|
751
|
+
const onLocaleChangeCallbacks = [];
|
|
752
|
+
const onLocaleChange = (fn) => {
|
|
753
|
+
if (onLocaleChangeCallbacks.indexOf(fn) === -1) {
|
|
754
|
+
onLocaleChangeCallbacks.push(fn);
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
|
|
730
758
|
const baseApis = {
|
|
731
759
|
$on,
|
|
732
760
|
$off,
|
|
@@ -736,6 +764,9 @@ const baseApis = {
|
|
|
736
764
|
addInterceptor,
|
|
737
765
|
removeInterceptor,
|
|
738
766
|
onAppLaunch,
|
|
767
|
+
getLocale,
|
|
768
|
+
setLocale,
|
|
769
|
+
onLocaleChange,
|
|
739
770
|
};
|
|
740
771
|
function initUni(api, protocols) {
|
|
741
772
|
const wrapper = initWrapper(protocols);
|
package/dist/uni.mp.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared';
|
|
2
|
-
import { injectHook } from 'vue';
|
|
2
|
+
import { injectHook, ref } from 'vue';
|
|
3
3
|
|
|
4
4
|
const encode = encodeURIComponent;
|
|
5
5
|
function stringifyQuery(obj, encodeStr = encode) {
|
|
@@ -534,6 +534,7 @@ function parseApp(instance, parseAppOptions) {
|
|
|
534
534
|
instance.$callHook(ON_LAUNCH, extend({ app: this }, options));
|
|
535
535
|
},
|
|
536
536
|
};
|
|
537
|
+
initLocale(instance);
|
|
537
538
|
const vueOptions = instance.$.type;
|
|
538
539
|
initHooks(appOptions, HOOKS);
|
|
539
540
|
initUnknownHooks(appOptions, vueOptions);
|
|
@@ -550,6 +551,17 @@ function initCreateApp(parseAppOptions) {
|
|
|
550
551
|
return function createApp(vm) {
|
|
551
552
|
return App(parseApp(vm, parseAppOptions));
|
|
552
553
|
};
|
|
554
|
+
}
|
|
555
|
+
function initLocale(appVm) {
|
|
556
|
+
const locale = ref(uni.getSystemInfoSync().language || 'zh-Hans');
|
|
557
|
+
Object.defineProperty(appVm, '$locale', {
|
|
558
|
+
get() {
|
|
559
|
+
return locale.value;
|
|
560
|
+
},
|
|
561
|
+
set(v) {
|
|
562
|
+
locale.value = v;
|
|
563
|
+
},
|
|
564
|
+
});
|
|
553
565
|
}
|
|
554
566
|
|
|
555
567
|
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
|
|
@@ -1210,7 +1222,7 @@ function initLifetimes(lifetimesOptions) {
|
|
|
1210
1222
|
if (this.pageinstance) {
|
|
1211
1223
|
this.__webviewId__ = this.pageinstance.__pageId__;
|
|
1212
1224
|
}
|
|
1213
|
-
this.$vm.$
|
|
1225
|
+
this.$vm.$callCreatedHook();
|
|
1214
1226
|
this.$vm.$callHook('mounted');
|
|
1215
1227
|
this.$vm.$callHook(ON_READY);
|
|
1216
1228
|
}
|
|
@@ -1267,7 +1279,7 @@ function handleLink({ detail: { nodeId, webviewId }, }) {
|
|
|
1267
1279
|
initInjections(vm);
|
|
1268
1280
|
initProvide(vm);
|
|
1269
1281
|
}
|
|
1270
|
-
vm.$
|
|
1282
|
+
vm.$callCreatedHook();
|
|
1271
1283
|
};
|
|
1272
1284
|
const mountedVm = function () {
|
|
1273
1285
|
// 处理当前 vm 子
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-quickapp-webview",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-32920210926001",
|
|
4
4
|
"description": "uni-app quickapp-webview",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
"name": "quickapp-webview",
|
|
18
18
|
"title": "快应用(Webview)版"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "5e7404fe087c97dfc46bfa7b0ab9044a2fa90142"
|
|
21
21
|
}
|