提交 1746dcce 编写于 作者: Q qiang

chore: build app

上级 cc16bcd6
......@@ -294,8 +294,36 @@ var serviceContext = (function () {
window.addEventListener('test-passive', null, opts);
} catch (e) {}
let realAtob;
const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;
if (typeof atob !== 'function') {
realAtob = function (str) {
str = String(str).replace(/[\t\n\f\r ]+/g, '');
if (!b64re.test(str)) { throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.") }
// Adding the padding if missing, for semplicity
str += '=='.slice(2 - (str.length & 3));
var bitmap; var result = ''; var r1; var r2; var i = 0;
for (; i < str.length;) {
bitmap = b64.indexOf(str.charAt(i++)) << 18 | b64.indexOf(str.charAt(i++)) << 12 |
(r1 = b64.indexOf(str.charAt(i++))) << 6 | (r2 = b64.indexOf(str.charAt(i++)));
result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255)
: r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255)
: String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255);
}
return result
};
} else {
// 注意atob只能在全局对象上调用,例如:`const Base64 = {atob};Base64.atob('xxxx')`是错误的用法
realAtob = atob;
}
function b64DecodeUnicode (str) {
return decodeURIComponent(atob(str).split('').map(function (c) {
return decodeURIComponent(realAtob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
}).join(''))
}
......@@ -1284,10 +1312,10 @@ var serviceContext = (function () {
}
locale = locale.toLowerCase();
if (locale.indexOf('zh') === 0) {
if (locale.indexOf('-hans') !== -1) {
if (locale.indexOf('-hans') > -1) {
return LOCALE_ZH_HANS;
}
if (locale.indexOf('-hant') !== -1) {
if (locale.indexOf('-hant') > -1) {
return LOCALE_ZH_HANT;
}
if (include(locale, ['-tw', '-hk', '-mo', '-cht'])) {
......@@ -1379,11 +1407,29 @@ var serviceContext = (function () {
}
}
const ignoreVueI18n = true;
function watchAppLocale(appVm, i18n) {
appVm.$watch(() => appVm.$locale, (newLocale) => {
i18n.setLocale(newLocale);
});
// 需要保证 watch 的触发在组件渲染之前
if (appVm.$watchLocale) {
// vue2
appVm.$watchLocale((newLocale) => {
i18n.setLocale(newLocale);
});
}
else {
appVm.$watch(() => appVm.$locale, (newLocale) => {
i18n.setLocale(newLocale);
});
}
}
function getDefaultLocale() {
if (typeof uni !== 'undefined' && uni.getLocale) {
return uni.getLocale();
}
// 小程序平台,uni 和 uni-i18n 互相引用,导致访问不到 uni,故在 global 上挂了 getLocale
if (typeof global !== 'undefined' && global.getLocale) {
return global.getLocale();
}
return LOCALE_EN;
}
function initVueI18n(locale, messages = {}, fallbackLocale, watcher) {
// 兼容旧版本入参
......@@ -1394,9 +1440,8 @@ var serviceContext = (function () {
];
}
if (typeof locale !== 'string') {
locale =
(typeof uni !== 'undefined' && uni.getLocale && uni.getLocale()) ||
LOCALE_EN;
// 因为小程序平台,uni-i18n 和 uni 互相引用,导致此时访问 uni 时,为 undefined
locale = getDefaultLocale();
}
if (typeof fallbackLocale !== 'string') {
fallbackLocale =
......@@ -1418,33 +1463,32 @@ var serviceContext = (function () {
};
}
else {
const appVm = getApp().$vm;
watchAppLocale(appVm, i18n);
if (!appVm.$t || !appVm.$i18n || ignoreVueI18n) {
// if (!locale) {
// i18n.setLocale(getDefaultLocale())
// }
/* eslint-disable no-func-assign */
t = function (key, values) {
let isWatchedAppLocale = false;
t = function (key, values) {
const appVm = getApp().$vm;
// 可能$vm还不存在,比如在支付宝小程序中,组件定义较早,在props的default里使用了t()函数(如uni-goods-nav),此时app还未初始化
// options: {
// type: Array,
// default () {
// return [{
// icon: 'shop',
// text: t("uni-goods-nav.options.shop"),
// }, {
// icon: 'cart',
// text: t("uni-goods-nav.options.cart")
// }]
// }
// },
if (appVm) {
// 触发响应式
appVm.$locale;
return i18n.t(key, values);
};
}
else {
/* eslint-disable no-func-assign */
t = function (key, values) {
const $i18n = appVm.$i18n;
const silentTranslationWarn = $i18n.silentTranslationWarn;
$i18n.silentTranslationWarn = true;
const msg = appVm.$t(key, values);
$i18n.silentTranslationWarn = silentTranslationWarn;
if (msg !== key) {
return msg;
if (!isWatchedAppLocale) {
isWatchedAppLocale = true;
watchAppLocale(appVm, i18n);
}
return i18n.t(key, $i18n.locale, values);
};
}
}
return i18n.t(key, values);
};
}
return t(key, values);
};
......@@ -1504,7 +1548,9 @@ var serviceContext = (function () {
"uni.video.danmu": "Danmu",
"uni.video.volume": "Volume",
"uni.button.feedback.title": "feedback",
"uni.button.feedback.send": "send"
"uni.button.feedback.send": "send",
"uni.chooseLocation.search": "Find Place",
"uni.chooseLocation.cancel": "Cancel"
};
var es = {
......@@ -1537,7 +1583,9 @@ var serviceContext = (function () {
"uni.video.danmu": "Danmu",
"uni.video.volume": "Volumen",
"uni.button.feedback.title": "realimentación",
"uni.button.feedback.send": "enviar"
"uni.button.feedback.send": "enviar",
"uni.chooseLocation.search": "Encontrar",
"uni.chooseLocation.cancel": "Cancelar"
};
var fr = {
......@@ -1570,7 +1618,9 @@ var serviceContext = (function () {
"uni.video.danmu": "Danmu",
"uni.video.volume": "Le Volume",
"uni.button.feedback.title": "retour d'information",
"uni.button.feedback.send": "envoyer"
"uni.button.feedback.send": "envoyer",
"uni.chooseLocation.search": "Trouve",
"uni.chooseLocation.cancel": "Annuler"
};
var zhHans = {
......@@ -1603,7 +1653,9 @@ var serviceContext = (function () {
"uni.video.danmu": "弹幕",
"uni.video.volume": "音量",
"uni.button.feedback.title": "问题反馈",
"uni.button.feedback.send": "发送"
"uni.button.feedback.send": "发送",
"uni.chooseLocation.search": "搜索地点",
"uni.chooseLocation.cancel": "取消"
};
var zhHant = {
......@@ -1636,7 +1688,9 @@ var serviceContext = (function () {
"uni.video.danmu": "彈幕",
"uni.video.volume": "音量",
"uni.button.feedback.title": "問題反饋",
"uni.button.feedback.send": "發送"
"uni.button.feedback.send": "發送",
"uni.chooseLocation.search": "搜索地點",
"uni.chooseLocation.cancel": "取消"
};
const messages = {
......@@ -6084,7 +6138,7 @@ var serviceContext = (function () {
/**
* 动态设置 tabBar 某一项的内容
*/
function setTabBarItem$1 (index, text, iconPath, selectedIconPath) {
function setTabBarItem$1 (index, text, iconPath, selectedIconPath, visible) {
const item = {
index
};
......@@ -6097,7 +6151,17 @@ var serviceContext = (function () {
if (selectedIconPath) {
item.selectedIconPath = getRealPath$1(selectedIconPath);
}
tabBar && tabBar.setTabBarItem(item);
if (visible !== undefined) {
item.visible = config.list[index].visible = visible;
delete item.index;
const tabbarItems = config.list.map(item => ({ visible: item.visible }));
tabbarItems[index] = item;
tabBar && tabBar.setTabBarItems({ list: tabbarItems });
} else {
tabBar && tabBar.setTabBarItem(item);
}
}
/**
* 动态设置 tabBar 的整体样式
......@@ -10670,9 +10734,10 @@ var serviceContext = (function () {
text,
iconPath,
selectedIconPath,
pagePath
pagePath,
visible
}) {
tabBar$1.setTabBarItem(index, text, iconPath, selectedIconPath);
tabBar$1.setTabBarItem(index, text, iconPath, selectedIconPath, visible);
const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath);
if (route) {
const meta = route.meta;
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册