This commit is contained in:
Luk 2024-03-28 14:23:18 +08:00
parent 80fc62e602
commit fdbdbe1693

View File

@ -48,7 +48,7 @@ export default {
i18nText || // 如果传入i18n参数 ({zhCN:'...', enUS:'...'}) i18nText || // 如果传入i18n参数 ({zhCN:'...', enUS:'...'})
this.i18nText || // 1) 如果挂载到具体页面的 computed { lote: wo?.localizeText } 那么 this 就是当前页面,直接取用 this.i18nText 即可。2) 对于组件内定义的 i18nText要使用 this 来获得组件内的 i18nText this.i18nText || // 1) 如果挂载到具体页面的 computed { lote: wo?.localizeText } 那么 this 就是当前页面,直接取用 this.i18nText 即可。2) 对于组件内定义的 i18nText要使用 this 来获得组件内的 i18nText
getCurrentPages()?.pop()?.i18nText // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就不存在了。因此通过 pageNow.i18nText 访问。 getCurrentPages()?.pop()?.i18nText // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就不存在了。因此通过 pageNow.i18nText 访问。
return i18nText?.[my.langNow()] || i18nText?.earth || i18nText?.default || (typeof i18nText === 'string' ? i18nText : '') // 必须检测是否string,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错 return i18nText?.[my.langNow()] || i18nText?.earth || i18nText?.default || (['string', 'number', 'boolean'].includes(typeof i18nText) ? i18nText : '') // 必须检测是否标量值,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
}, },
localeText () { localeText () {
@ -119,8 +119,7 @@ export default {
} }
}, },
make_server_url (route, wo = globalThis.wo) { make_server_url (route, envar = globalThis.wo?.envar || {}) {
const envar = wo?.envar || {}
if (typeof route === 'string') route = route.replace('\\', '/') if (typeof route === 'string') route = route.replace('\\', '/')
else if (route?.apiWho && route?.apiTodo) { else if (route?.apiWho && route?.apiTodo) {
const { apiVersion = 'api', apiWho, apiTodo } = route const { apiVersion = 'api', apiWho, apiTodo } = route
@ -146,12 +145,13 @@ export default {
// 已有现成后端服务域名 // 已有现成后端服务域名
if (envar.servUrl) { if (envar.servUrl) {
return `${envar.servUrl.replace(/\/$/, '')}/${route}` return `${envar.servUrl.replace(/\/$/, '')}/${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}`
} }
// 需要组装后端服务域名
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}`
}, },
make_bgurl (image) { make_bgurl (image) {
@ -440,6 +440,23 @@ export default {
} }
}, },
open_url ({ url, title, inWebview } = {}) {
url = this.localizeText?.(url) || url
if (wo.envar.inPc) {
window.open(url, '_blank')
} else if (inWebview) {
wo.ss.webviewUrl = url
wo.ss.webviewTitle = title
uni.navigateTo({ url: 'tool-webview' })
} else {
// #ifdef APP
plus.runtime.openURL(url)
// #endif
// #ifdef WEB
window.open(url, '_blank')
// #endif
}
},
open_url_in_browser ({ url }) { open_url_in_browser ({ url }) {
url = this.localizeText?.(url) || url url = this.localizeText?.(url) || url
// #ifdef APP // #ifdef APP
@ -450,8 +467,9 @@ export default {
// #endif // #endif
}, },
open_url_in_webview ({ url, title }) { open_url_in_webview ({ url, title }) {
url = this.localizeText?.(url) || url
if (wo.envar.inPc) { if (wo.envar.inPc) {
window.open(wo.ll(url), '_blank') window.open(url, '_blank')
} else { } else {
wo.ss.webviewUrl = url wo.ss.webviewUrl = url
wo.ss.webviewTitle = title wo.ss.webviewTitle = title
@ -508,25 +526,27 @@ export default {
return return
} }
// 来自 <ucToast> 或 <u-toast> 或 <u-top-tips> // rename to popToast? // 来自 <ucToast> 或 <u-toast> 或 <u-top-tips> // rename to popToast?
const popup = getCurrentPages()?.pop()?.$refs?.popup || getApp().globalData?.popup || wo?.popup const mypopup = getCurrentPages()?.pop()?.mypopup || getCurrentPages()?.pop()?.$refs?.mypopup || getApp().globalData?.mypopup || wo?.mypopup
if (popup) { if (mypopup) {
wo.ss.popMessage = title wo.ss.popMessage = title
wo.ss.popType = type // success/error/warning/info wo.ss.popType = type // success/error/warning/info
wo.ss.popDuration = duration wo.ss.popDuration = duration
popup.open() mypopup.open()
} else { } else {
const toast = getCurrentPages()?.pop()?.$refs?.toast || getApp().globalData?.toast || wo?.toast const mytoast = getCurrentPages()?.pop()?.mytoast || getCurrentPages()?.pop()?.$refs?.mytoast || getApp().globalData?.mytoast || wo?.mytoast
toast?.show?.({ type, title, duration, ...rest }) mytoast?.show?.({ type, title, duration, ...rest })
} }
}, },
showModal (option = {}) { showModal (option = {}) {
option.title = this.localizeText(option.title) option.title = this.localizeText(option.title)
option.content = this.localizeText(option.content) option.content = this.localizeText(option.content)?.substring?.(0, 100)
if (option.content) option.content += '\n\n'
option.cancelText = this.localizeText(option.cancelText || { zhCN: '取消', enUS: 'Cancel' }) option.cancelText = this.localizeText(option.cancelText || { zhCN: '取消', enUS: 'Cancel' })
option.confirmText = this.localizeText(option.confirmText || { zhCN: '好的', enUS: 'OK' }) option.confirmText = this.localizeText(option.confirmText || { zhCN: '好的', enUS: 'OK' })
// #ifdef APP // #ifdef APP
if (option.content) option.content = '\n' + option.content if (option.content) option.content = '\n' + option.content
else option.content = ' ' // 20240229 从前在手机app里content必须存在。现在似乎没关<-系了,但不确定。
// #endif // #endif
uni.showModal(option) uni.showModal(option)
}, },