@dcloudio/uni-quickapp-webview 2.0.1-alpha-34920220527003 → 2.0.1-alpha-34920220531002
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 +163 -118
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Vue from 'vue';
|
|
2
1
|
import { initVueI18n } from '@dcloudio/uni-i18n';
|
|
2
|
+
import Vue from 'vue';
|
|
3
3
|
|
|
4
4
|
let realAtob;
|
|
5
5
|
|
|
@@ -98,7 +98,7 @@ function hasOwn (obj, key) {
|
|
|
98
98
|
return hasOwnProperty.call(obj, key)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
function noop () {}
|
|
101
|
+
function noop () { }
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Create a cached version of a pure function.
|
|
@@ -427,7 +427,134 @@ function upx2px (number, newDeviceWidth) {
|
|
|
427
427
|
return number < 0 ? -result : result
|
|
428
428
|
}
|
|
429
429
|
|
|
430
|
-
|
|
430
|
+
const LOCALE_ZH_HANS = 'zh-Hans';
|
|
431
|
+
const LOCALE_ZH_HANT = 'zh-Hant';
|
|
432
|
+
const LOCALE_EN = 'en';
|
|
433
|
+
const LOCALE_FR = 'fr';
|
|
434
|
+
const LOCALE_ES = 'es';
|
|
435
|
+
|
|
436
|
+
const messages = {};
|
|
437
|
+
|
|
438
|
+
let locale;
|
|
439
|
+
|
|
440
|
+
{
|
|
441
|
+
locale = normalizeLocale(qa.getSystemInfoSync().language) || LOCALE_EN;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function initI18nMessages () {
|
|
445
|
+
if (!isEnableLocale()) {
|
|
446
|
+
return
|
|
447
|
+
}
|
|
448
|
+
const localeKeys = Object.keys(__uniConfig.locales);
|
|
449
|
+
if (localeKeys.length) {
|
|
450
|
+
localeKeys.forEach((locale) => {
|
|
451
|
+
const curMessages = messages[locale];
|
|
452
|
+
const userMessages = __uniConfig.locales[locale];
|
|
453
|
+
if (curMessages) {
|
|
454
|
+
Object.assign(curMessages, userMessages);
|
|
455
|
+
} else {
|
|
456
|
+
messages[locale] = userMessages;
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
initI18nMessages();
|
|
463
|
+
|
|
464
|
+
const i18n = initVueI18n(
|
|
465
|
+
locale,
|
|
466
|
+
{}
|
|
467
|
+
);
|
|
468
|
+
const t = i18n.t;
|
|
469
|
+
const i18nMixin = (i18n.mixin = {
|
|
470
|
+
beforeCreate () {
|
|
471
|
+
const unwatch = i18n.i18n.watchLocale(() => {
|
|
472
|
+
this.$forceUpdate();
|
|
473
|
+
});
|
|
474
|
+
this.$once('hook:beforeDestroy', function () {
|
|
475
|
+
unwatch();
|
|
476
|
+
});
|
|
477
|
+
},
|
|
478
|
+
methods: {
|
|
479
|
+
$$t (key, values) {
|
|
480
|
+
return t(key, values)
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
const setLocale = i18n.setLocale;
|
|
485
|
+
const getLocale = i18n.getLocale;
|
|
486
|
+
|
|
487
|
+
function initAppLocale (Vue, appVm, locale) {
|
|
488
|
+
const state = Vue.observable({
|
|
489
|
+
locale: locale || i18n.getLocale()
|
|
490
|
+
});
|
|
491
|
+
const localeWatchers = [];
|
|
492
|
+
appVm.$watchLocale = fn => {
|
|
493
|
+
localeWatchers.push(fn);
|
|
494
|
+
};
|
|
495
|
+
Object.defineProperty(appVm, '$locale', {
|
|
496
|
+
get () {
|
|
497
|
+
return normalizeLocale(state.locale)
|
|
498
|
+
},
|
|
499
|
+
set (v) {
|
|
500
|
+
state.locale = v;
|
|
501
|
+
localeWatchers.forEach(watch => watch(v));
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function isEnableLocale () {
|
|
507
|
+
return typeof __uniConfig !== 'undefined' && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function include (str, parts) {
|
|
511
|
+
return !!parts.find((part) => str.indexOf(part) !== -1)
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function startsWith (str, parts) {
|
|
515
|
+
return parts.find((part) => str.indexOf(part) === 0)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function normalizeLocale (locale, messages) {
|
|
519
|
+
if (!locale) {
|
|
520
|
+
return
|
|
521
|
+
}
|
|
522
|
+
locale = locale.trim().replace(/_/g, '-');
|
|
523
|
+
if (messages && messages[locale]) {
|
|
524
|
+
return locale
|
|
525
|
+
}
|
|
526
|
+
locale = locale.toLowerCase();
|
|
527
|
+
if (locale === 'chinese') {
|
|
528
|
+
// 支付宝
|
|
529
|
+
return LOCALE_ZH_HANS
|
|
530
|
+
}
|
|
531
|
+
if (locale.indexOf('zh') === 0) {
|
|
532
|
+
if (locale.indexOf('-hans') > -1) {
|
|
533
|
+
return LOCALE_ZH_HANS
|
|
534
|
+
}
|
|
535
|
+
if (locale.indexOf('-hant') > -1) {
|
|
536
|
+
return LOCALE_ZH_HANT
|
|
537
|
+
}
|
|
538
|
+
if (include(locale, ['-tw', '-hk', '-mo', '-cht'])) {
|
|
539
|
+
return LOCALE_ZH_HANT
|
|
540
|
+
}
|
|
541
|
+
return LOCALE_ZH_HANS
|
|
542
|
+
}
|
|
543
|
+
const lang = startsWith(locale, [LOCALE_EN, LOCALE_FR, LOCALE_ES]);
|
|
544
|
+
if (lang) {
|
|
545
|
+
return lang
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
// export function initI18n() {
|
|
549
|
+
// const localeKeys = Object.keys(__uniConfig.locales || {})
|
|
550
|
+
// if (localeKeys.length) {
|
|
551
|
+
// localeKeys.forEach((locale) =>
|
|
552
|
+
// i18n.add(locale, __uniConfig.locales[locale])
|
|
553
|
+
// )
|
|
554
|
+
// }
|
|
555
|
+
// }
|
|
556
|
+
|
|
557
|
+
function getLocale$1 () {
|
|
431
558
|
// 优先使用 $locale
|
|
432
559
|
const app = getApp({
|
|
433
560
|
allowDefault: true
|
|
@@ -435,10 +562,10 @@ function getLocale () {
|
|
|
435
562
|
if (app && app.$vm) {
|
|
436
563
|
return app.$vm.$locale
|
|
437
564
|
}
|
|
438
|
-
return qa.getSystemInfoSync().language ||
|
|
565
|
+
return normalizeLocale(qa.getSystemInfoSync().language) || LOCALE_EN
|
|
439
566
|
}
|
|
440
567
|
|
|
441
|
-
function setLocale (locale) {
|
|
568
|
+
function setLocale$1 (locale) {
|
|
442
569
|
const app = getApp();
|
|
443
570
|
if (!app) {
|
|
444
571
|
return false
|
|
@@ -462,7 +589,7 @@ function onLocaleChange (fn) {
|
|
|
462
589
|
}
|
|
463
590
|
|
|
464
591
|
if (typeof global !== 'undefined') {
|
|
465
|
-
global.getLocale = getLocale;
|
|
592
|
+
global.getLocale = getLocale$1;
|
|
466
593
|
}
|
|
467
594
|
|
|
468
595
|
const interceptors = {
|
|
@@ -472,8 +599,8 @@ const interceptors = {
|
|
|
472
599
|
var baseApi = /*#__PURE__*/Object.freeze({
|
|
473
600
|
__proto__: null,
|
|
474
601
|
upx2px: upx2px,
|
|
475
|
-
getLocale: getLocale,
|
|
476
|
-
setLocale: setLocale,
|
|
602
|
+
getLocale: getLocale$1,
|
|
603
|
+
setLocale: setLocale$1,
|
|
477
604
|
onLocaleChange: onLocaleChange,
|
|
478
605
|
addInterceptor: addInterceptor,
|
|
479
606
|
removeInterceptor: removeInterceptor,
|
|
@@ -651,12 +778,6 @@ var previewImage = {
|
|
|
651
778
|
}
|
|
652
779
|
};
|
|
653
780
|
|
|
654
|
-
function _getDeviceBrand (model) {
|
|
655
|
-
if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { return 'apple' }
|
|
656
|
-
if (/windows/gi.test(model)) { return 'microsoft' }
|
|
657
|
-
return ''
|
|
658
|
-
}
|
|
659
|
-
|
|
660
781
|
const UUID_KEY = '__DC_STAT_UUID';
|
|
661
782
|
let deviceId;
|
|
662
783
|
function useDeviceId (result) {
|
|
@@ -687,11 +808,10 @@ function populateParameters (result) {
|
|
|
687
808
|
const {
|
|
688
809
|
brand = '', model = '', system = '',
|
|
689
810
|
language = '', theme, version,
|
|
690
|
-
|
|
691
|
-
SDKVersion, pixelRatio, deviceOrientation
|
|
692
|
-
environment
|
|
811
|
+
platform, fontSizeSetting,
|
|
812
|
+
SDKVersion, pixelRatio, deviceOrientation
|
|
693
813
|
} = result;
|
|
694
|
-
const isQuickApp = "quickapp-webview".indexOf('quickapp-webview') !== -1
|
|
814
|
+
// const isQuickApp = "quickapp-webview".indexOf('quickapp-webview') !== -1
|
|
695
815
|
|
|
696
816
|
// osName osVersion
|
|
697
817
|
let osName = '';
|
|
@@ -706,10 +826,10 @@ function populateParameters (result) {
|
|
|
706
826
|
const deviceType = getGetDeviceType(result, model);
|
|
707
827
|
|
|
708
828
|
// deviceModel
|
|
709
|
-
const deviceBrand = getDeviceBrand(brand
|
|
829
|
+
const deviceBrand = getDeviceBrand(brand);
|
|
710
830
|
|
|
711
831
|
// hostName
|
|
712
|
-
|
|
832
|
+
const _hostName = getHostName(result);
|
|
713
833
|
|
|
714
834
|
// deviceOrientation
|
|
715
835
|
let _deviceOrientation = deviceOrientation; // 仅 微信 百度 支持
|
|
@@ -720,6 +840,9 @@ function populateParameters (result) {
|
|
|
720
840
|
// SDKVersion
|
|
721
841
|
let _SDKVersion = SDKVersion;
|
|
722
842
|
|
|
843
|
+
// hostLanguage
|
|
844
|
+
const hostLanguage = language.replace(/_/g, '-');
|
|
845
|
+
|
|
723
846
|
// wx.getAccountInfoSync
|
|
724
847
|
|
|
725
848
|
const parameters = {
|
|
@@ -727,6 +850,7 @@ function populateParameters (result) {
|
|
|
727
850
|
appName: process.env.UNI_APP_NAME,
|
|
728
851
|
appVersion: process.env.UNI_APP_VERSION_NAME,
|
|
729
852
|
appVersionCode: process.env.UNI_APP_VERSION_CODE,
|
|
853
|
+
appLanguage: getAppLanguage(hostLanguage),
|
|
730
854
|
uniCompileVersion: process.env.UNI_COMPILER_VERSION,
|
|
731
855
|
uniRuntimeVersion: process.env.UNI_COMPILER_VERSION,
|
|
732
856
|
uniPlatform: process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM,
|
|
@@ -739,7 +863,7 @@ function populateParameters (result) {
|
|
|
739
863
|
osVersion,
|
|
740
864
|
hostTheme: theme,
|
|
741
865
|
hostVersion,
|
|
742
|
-
hostLanguage
|
|
866
|
+
hostLanguage,
|
|
743
867
|
hostName: _hostName,
|
|
744
868
|
hostSDKVersion: _SDKVersion,
|
|
745
869
|
hostFontSizeSetting: fontSizeSetting,
|
|
@@ -751,7 +875,7 @@ function populateParameters (result) {
|
|
|
751
875
|
ua: undefined,
|
|
752
876
|
hostPackageName: undefined,
|
|
753
877
|
browserName: undefined,
|
|
754
|
-
|
|
878
|
+
browserVersion: undefined
|
|
755
879
|
};
|
|
756
880
|
|
|
757
881
|
Object.assign(result, parameters);
|
|
@@ -778,23 +902,27 @@ function getGetDeviceType (result, model) {
|
|
|
778
902
|
return deviceType
|
|
779
903
|
}
|
|
780
904
|
|
|
781
|
-
function getDeviceBrand (
|
|
782
|
-
brand
|
|
783
|
-
|
|
784
|
-
isQuickApp = false
|
|
785
|
-
) {
|
|
786
|
-
let deviceBrand = model.split(' ')[0].toLocaleLowerCase();
|
|
787
|
-
if (
|
|
788
|
-
|
|
789
|
-
isQuickApp
|
|
790
|
-
) {
|
|
905
|
+
function getDeviceBrand (brand) {
|
|
906
|
+
let deviceBrand = brand;
|
|
907
|
+
if (deviceBrand) {
|
|
791
908
|
deviceBrand = brand.toLocaleLowerCase();
|
|
792
|
-
} else {
|
|
793
|
-
deviceBrand = _getDeviceBrand(deviceBrand);
|
|
794
909
|
}
|
|
795
910
|
return deviceBrand
|
|
796
911
|
}
|
|
797
912
|
|
|
913
|
+
function getAppLanguage (defaultLanguage) {
|
|
914
|
+
return getLocale$1
|
|
915
|
+
? getLocale$1()
|
|
916
|
+
: defaultLanguage
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function getHostName (result) {
|
|
920
|
+
const _platform = "quickapp-webview".split('-')[1];
|
|
921
|
+
let _hostName = result.hostName || _platform; // mp-jd
|
|
922
|
+
|
|
923
|
+
return _hostName
|
|
924
|
+
}
|
|
925
|
+
|
|
798
926
|
var getSystemInfo = {
|
|
799
927
|
returnValue: function (result) {
|
|
800
928
|
useDeviceId(result);
|
|
@@ -1733,89 +1861,6 @@ function handleEvent (event) {
|
|
|
1733
1861
|
}
|
|
1734
1862
|
}
|
|
1735
1863
|
|
|
1736
|
-
const messages = {};
|
|
1737
|
-
|
|
1738
|
-
let locale;
|
|
1739
|
-
|
|
1740
|
-
{
|
|
1741
|
-
locale = qa.getSystemInfoSync().language;
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
function initI18nMessages () {
|
|
1745
|
-
if (!isEnableLocale()) {
|
|
1746
|
-
return
|
|
1747
|
-
}
|
|
1748
|
-
const localeKeys = Object.keys(__uniConfig.locales);
|
|
1749
|
-
if (localeKeys.length) {
|
|
1750
|
-
localeKeys.forEach((locale) => {
|
|
1751
|
-
const curMessages = messages[locale];
|
|
1752
|
-
const userMessages = __uniConfig.locales[locale];
|
|
1753
|
-
if (curMessages) {
|
|
1754
|
-
Object.assign(curMessages, userMessages);
|
|
1755
|
-
} else {
|
|
1756
|
-
messages[locale] = userMessages;
|
|
1757
|
-
}
|
|
1758
|
-
});
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
initI18nMessages();
|
|
1763
|
-
|
|
1764
|
-
const i18n = initVueI18n(
|
|
1765
|
-
locale,
|
|
1766
|
-
{}
|
|
1767
|
-
);
|
|
1768
|
-
const t = i18n.t;
|
|
1769
|
-
const i18nMixin = (i18n.mixin = {
|
|
1770
|
-
beforeCreate () {
|
|
1771
|
-
const unwatch = i18n.i18n.watchLocale(() => {
|
|
1772
|
-
this.$forceUpdate();
|
|
1773
|
-
});
|
|
1774
|
-
this.$once('hook:beforeDestroy', function () {
|
|
1775
|
-
unwatch();
|
|
1776
|
-
});
|
|
1777
|
-
},
|
|
1778
|
-
methods: {
|
|
1779
|
-
$$t (key, values) {
|
|
1780
|
-
return t(key, values)
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
});
|
|
1784
|
-
const setLocale$1 = i18n.setLocale;
|
|
1785
|
-
const getLocale$1 = i18n.getLocale;
|
|
1786
|
-
|
|
1787
|
-
function initAppLocale (Vue, appVm, locale) {
|
|
1788
|
-
const state = Vue.observable({
|
|
1789
|
-
locale: locale || i18n.getLocale()
|
|
1790
|
-
});
|
|
1791
|
-
const localeWatchers = [];
|
|
1792
|
-
appVm.$watchLocale = fn => {
|
|
1793
|
-
localeWatchers.push(fn);
|
|
1794
|
-
};
|
|
1795
|
-
Object.defineProperty(appVm, '$locale', {
|
|
1796
|
-
get () {
|
|
1797
|
-
return state.locale
|
|
1798
|
-
},
|
|
1799
|
-
set (v) {
|
|
1800
|
-
state.locale = v;
|
|
1801
|
-
localeWatchers.forEach(watch => watch(v));
|
|
1802
|
-
}
|
|
1803
|
-
});
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
|
-
function isEnableLocale () {
|
|
1807
|
-
return typeof __uniConfig !== 'undefined' && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
// export function initI18n() {
|
|
1811
|
-
// const localeKeys = Object.keys(__uniConfig.locales || {})
|
|
1812
|
-
// if (localeKeys.length) {
|
|
1813
|
-
// localeKeys.forEach((locale) =>
|
|
1814
|
-
// i18n.add(locale, __uniConfig.locales[locale])
|
|
1815
|
-
// )
|
|
1816
|
-
// }
|
|
1817
|
-
// }
|
|
1818
|
-
|
|
1819
1864
|
const hooks = [
|
|
1820
1865
|
'onShow',
|
|
1821
1866
|
'onHide',
|
|
@@ -1917,7 +1962,7 @@ function parseBaseApp (vm, {
|
|
|
1917
1962
|
});
|
|
1918
1963
|
}
|
|
1919
1964
|
|
|
1920
|
-
initAppLocale(Vue, vm, qa.getSystemInfoSync().language ||
|
|
1965
|
+
initAppLocale(Vue, vm, normalizeLocale(qa.getSystemInfoSync().language) || LOCALE_EN);
|
|
1921
1966
|
|
|
1922
1967
|
initHooks(appOptions, hooks);
|
|
1923
1968
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-quickapp-webview",
|
|
3
|
-
"version": "2.0.1-alpha-
|
|
3
|
+
"version": "2.0.1-alpha-34920220531002",
|
|
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": "2b52f91070c0f58ca58f654ec7e6e8a70a2ff374"
|
|
21
21
|
}
|