From 08b6c3e31ac0161fa7b6d3d942729d4cd1ff712c Mon Sep 17 00:00:00 2001 From: Luk Date: Tue, 1 Oct 2024 20:23:54 +0800 Subject: [PATCH] localizeText return enUS if the target language is undefined --- unitool.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/unitool.js b/unitool.js index b2e720f..c864631 100644 --- a/unitool.js +++ b/unitool.js @@ -57,7 +57,13 @@ module.exports = { i18nText || // 如果传入i18n参数 ({zhCN:'...', enUS:'...'}) this.i18nText || // 1) 如果挂载到具体页面的 computed { lote: wo?.localizeText } 那么 this 就是当前页面,直接取用 this.i18nText 即可。2) 对于组件内定义的 i18nText,要使用 this 来获得组件内的 i18nText getCurrentPages()?.pop()?.i18nText // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就不存在了。因此通过 pageNow.i18nText 访问。 - return i18nText?.[my.langNow()] || i18nText?.earth || i18nText?.default || (['string', 'number', 'boolean'].includes(typeof i18nText) ? i18nText : '') // 必须检测是否标量值,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错 + return ( + i18nText?.[my.langNow()] || + i18nText?.earth || + i18nText?.default || + i18nText?.enUS || + (['string', 'number', 'boolean'].includes(typeof i18nText) ? i18nText : '') + ) // 必须检测是否标量值,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错 }, localeText () { @@ -226,12 +232,16 @@ module.exports = { } } apiurl = this.make_server_url(`${apiVersion}/${apiWho}/${apiTodo}`) - let [error, { statusCode, header, errMsg, data: resultServer = {} } = {}] = await uni.request({ - method: httpMethod, - url: apiurl, - data: apiWhat, - timeout, - }) + let [error, { statusCode, header, errMsg, data: resultServer = {} } = {}] = await uni + .request({ + method: httpMethod, + url: apiurl, + data: apiWhat, + timeout, + }) + .catch((expt) => { + return [undefined, { data: { _state: 'CLIENT_WOBASE_EXCEPTION' } }] + }) if (error) { if (error.errMsg === 'request:fail') { // 后台服务器无法连接 @@ -683,13 +693,18 @@ module.exports = { option.content = (uni.getSystemInfoSync().uniPlatform === 'app' ? '\n' : '') + this.localizeText(option.content)?.substring?.(0, option.contentLength || 300) if (option.content) option.content += '\n\n' - option.cancelText = this.localizeText(option.cancelText || { zhCN: '取消', enUS: 'Cancel' }) - option.confirmText = this.localizeText(option.confirmText || { zhCN: '好的', enUS: 'OK' }) + option.cancelText = this.localizeText(option.cancelText || { zhCN: '取消', enUS: 'Cancel', jaJP: 'キャンセル' }) + option.confirmText = this.localizeText( + option.confirmText || + (option.showCanel === true || option.showCancel === undefined + ? { zhCN: '确认', enUS: 'Confirm', jaJP: '確認' } + : { zhCN: '好的', enUS: 'OK', jaJP: 'OK' }) + ) // #ifdef APP if (option.content) option.content = '\n' + option.content else option.content = ' ' // 20240229 从前在手机app里,content必须存在。现在似乎没关<-系了,但不确定。 // #endif - uni.showModal(option) + uni.showModal(option) // uni.showModal 的 showCancel 默认为 true }, showLoading ({ title = { zhCN: '加载中...', enUS: 'Loading...' }, mask } = {}) {