diff --git a/unitool.js b/unitool.js index d0c7558..8dc7f36 100644 --- a/unitool.js +++ b/unitool.js @@ -61,19 +61,26 @@ export default { pagesJson?.pages?.find((page) => page.path === pageNow?.route)?.i18nPageTitle?.[mylang] || // pages.json 的页面配置里 '' + windowTitle = windowTitle || wo?.envar?.callname?.[mylang] || pagesJson?.appInfo?.i18nText?.[mylang] || pagesJson?.globalStyle?.navigationBarTitleText || '' + if (uni.getSystemInfoSync().deviceType === 'pc') { - windowTitle = - windowTitle || wo?.envar?.callname?.[mylang] || pagesJson?.appInfo?.i18nText?.[mylang] || pagesJson?.globalStyle?.navigationBarTitleText || '' uni.setNavigationBarTitle({ title: windowTitle + (navibarTitle ? ` - ${navibarTitle}` : '') }) } else { uni.setNavigationBarTitle({ title: navibarTitle }) } - // #ifdef H5 - // navibarTitle 也会被用于浏览器的标签标题,可用 document.title 去覆盖。 - // 必须放在 setNavigationBarTitle 之后。但这个方案,在电脑上,还是会显示 navibarTitle 在浏览器窗口顶栏,不知为何。 - // document.title = ??? - // #endif + //#ifdef H5 + //// 设置窗口标题栏 document.title + //// navibarTitle 也会被用于浏览器的标签标题,可用 document.title 去覆盖。必须放在 setNavigationBarTitle 之后。 + //// 但这个方案,在电脑上,还是会显示 navibarTitle 在浏览器窗口顶栏,不知为何。 + if (uni.getSystemInfoSync().deviceType === 'phone' && /MicroMessenger/i.test(globalThis.window?.navigator?.userAgent)) { + //// 微信浏览器里,本身就显示了标题栏,和自有的导航栏形成功能重叠和混淆。 + //// 设置标题栏为空或覆盖 + document.title = windowTitle + //// 或者设置导航栏隐藏。但这样导致,用户容易误点微信浏览器标题栏的 X 关掉页面,所以还是显示导航栏吧。 + // document.getElementsByTagName('uni-page-head')?.[0]?.remove() // 或者 [0]?.style?.display = 'none' + } + //#endif if (uni.getSystemInfoSync().deviceType === 'pc') { uni.hideTabBar() @@ -94,32 +101,26 @@ export default { } }) } - - //#ifdef H5 - //// 微信浏览器里,本身就显示了标题栏,和自有的导航栏形成功能重叠和混淆。 - if (uni.getSystemInfoSync().deviceType === 'phone' && /MicroMessenger/i.test(globalThis.window?.navigator?.userAgent)) { - //// 设置标题栏为空 - document.title = '' - //// 或者设置导航栏隐藏。但这样导致,用户容易误点微信浏览器标题栏的 X 关掉页面,所以还是显示导航栏吧。 - // document.getElementsByTagName('uni-page-head')?.[0]?.remove() // 或者 [0]?.style?.display = 'none' - } - //#endif }, makeServerUrl (route = '') { - const envar = this.envar || wo?.envar || {} - - if (typeof route !== 'string') route = '' // 防止 route 为 null, undefined 等由于后台数据库默认值而造成的异常。 - route = route.replace('\\', '/') if (/^https?:\/\//.test(route)) { return route } - const hostname = envar.servHostname /*|| globalThis.window?.location?.hostname*/ || 'localhost' - const port = envar.servPort /*|| globalThis.window?.location?.port*/ || '' - const protocol = hostname === 'localhost' ? 'http' : envar.servProtocol || (process.env.NODE_ENV === 'production' ? 'https' : 'http') + if (typeof route !== 'string') route = '' // 防止 route 为 null, undefined 等由于后台数据库默认值而造成的异常。 + route = route.replace('\\', '/').replace(/^\//, '') - return `${protocol}://${hostname}${port ? ':' : ''}${port}/${route.replace(/^\//, '')}` + const envar = this.envar || wo?.envar || {} + + if (envar.servUrl) { + return `${envar.servUrl}/${route}` + } else { + const hostname = envar.servHostname /*|| globalThis.window?.location?.hostname*/ || 'localhost' + const port = envar.servPort /*|| globalThis.window?.location?.port*/ || '' + const protocol = hostname === 'localhost' ? 'http' : envar.servProtocol || (process.env.NODE_ENV === 'production' ? 'https' : 'http') + return `${protocol}://${hostname}${port ? ':' : ''}${port}/${route}` + } }, makeBgUrl (path) {