diff --git a/index.js b/index.js index 8bd0a1e..f02fe86 100644 --- a/index.js +++ b/index.js @@ -24,11 +24,11 @@ module.exports = { // 快速输出详尽提示,可用来取代 console.log colog(...message) { - process.env.NODE_ENV === 'production' || console.log( - '【', - getCurrentPages().length > 0 ? getCurrentPages().pop().route : 'App', // 在首页时,getApp() 或 getCurrentPages() 有可能获取不到。 - '【', ...message, '】】' - ) + if (process.env.NODE_ENV === 'development') { + // 在首页时,getApp() 或 getCurrentPages() 有可能获取不到。 + const pageName = getCurrentPages().length > 0 ? getCurrentPages().pop().route : 'App' + console.log(`【 ${pageName} 【 `, ...message, ' 】】') + } }, thisPage() { @@ -52,21 +52,11 @@ module.exports = { }, localeText() { - const thisPage = this.$store ? this // 对于组件内定义的 i18nText,要使用 this 来获得组建内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。 + const thisPage = this.$store ? this // 对于组件内定义的 i18nText,要使用 this 来获得组件内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。 : getCurrentPages()[getCurrentPages().length - 1] - return thisPage.i18nText[thisPage.$store.state.i18n.mylang] + return thisPage.i18nText?.[thisPage.$store.state.i18n.mylang] || {} }, - // setBarTitles 迁移到 user.i18n.uniapp 库,通过 this.$store.commit('i18n/setBarTitles') 来调用 - // setBarTitles({ windowTitle, pageTitle } = {}) { - // let page = getCurrentPages()[getCurrentPages().length - 1] - // uni.setNavigationBarTitle({ title: pageTitle || page.i18nText[page.$store.state.i18n.mylang].tPageTitle }) - // // #ifdef H5 - // document.title = windowTitle || page.$store.getters['i18n/getAppName'] // 必须放在 setNavigationBarTitle 之后,否则会被其覆盖掉。 - // // #endif - // if (page.$store._mutations['i18n/setTabbar']) page.$store.commit('i18n/setTabbar') // 必须要在有 tab 的页面里重置才有效果 - // }, - makeServerUrl(route = '') { if (typeof route !== 'string') route = '' // 防止 route 为 null, undedefined 等由于后台数据库默认值而造成的异常。