u
This commit is contained in:
parent
80fc62e602
commit
fdbdbe1693
50
unitool.js
50
unitool.js
@ -48,7 +48,7 @@ export default {
|
||||
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 || (typeof i18nText === 'string' ? i18nText : '') // 必须检测是否string,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
|
||||
return i18nText?.[my.langNow()] || i18nText?.earth || i18nText?.default || (['string', 'number', 'boolean'].includes(typeof i18nText) ? i18nText : '') // 必须检测是否标量值,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
|
||||
},
|
||||
|
||||
localeText () {
|
||||
@ -119,8 +119,7 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
make_server_url (route, wo = globalThis.wo) {
|
||||
const envar = wo?.envar || {}
|
||||
make_server_url (route, envar = globalThis.wo?.envar || {}) {
|
||||
if (typeof route === 'string') route = route.replace('\\', '/')
|
||||
else if (route?.apiWho && route?.apiTodo) {
|
||||
const { apiVersion = 'api', apiWho, apiTodo } = route
|
||||
@ -146,12 +145,13 @@ export default {
|
||||
// 已有现成后端服务域名
|
||||
if (envar.servUrl) {
|
||||
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) {
|
||||
@ -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 }) {
|
||||
url = this.localizeText?.(url) || url
|
||||
// #ifdef APP
|
||||
@ -450,8 +467,9 @@ export default {
|
||||
// #endif
|
||||
},
|
||||
open_url_in_webview ({ url, title }) {
|
||||
url = this.localizeText?.(url) || url
|
||||
if (wo.envar.inPc) {
|
||||
window.open(wo.ll(url), '_blank')
|
||||
window.open(url, '_blank')
|
||||
} else {
|
||||
wo.ss.webviewUrl = url
|
||||
wo.ss.webviewTitle = title
|
||||
@ -508,25 +526,27 @@ export default {
|
||||
return
|
||||
}
|
||||
// 来自 <ucToast> 或 <u-toast> 或 <u-top-tips> // rename to popToast?
|
||||
const popup = getCurrentPages()?.pop()?.$refs?.popup || getApp().globalData?.popup || wo?.popup
|
||||
if (popup) {
|
||||
const mypopup = getCurrentPages()?.pop()?.mypopup || getCurrentPages()?.pop()?.$refs?.mypopup || getApp().globalData?.mypopup || wo?.mypopup
|
||||
if (mypopup) {
|
||||
wo.ss.popMessage = title
|
||||
wo.ss.popType = type // success/error/warning/info
|
||||
wo.ss.popDuration = duration
|
||||
popup.open()
|
||||
mypopup.open()
|
||||
} else {
|
||||
const toast = getCurrentPages()?.pop()?.$refs?.toast || getApp().globalData?.toast || wo?.toast
|
||||
toast?.show?.({ type, title, duration, ...rest })
|
||||
const mytoast = getCurrentPages()?.pop()?.mytoast || getCurrentPages()?.pop()?.$refs?.mytoast || getApp().globalData?.mytoast || wo?.mytoast
|
||||
mytoast?.show?.({ type, title, duration, ...rest })
|
||||
}
|
||||
},
|
||||
|
||||
showModal (option = {}) {
|
||||
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.confirmText = this.localizeText(option.confirmText || { zhCN: '好的', enUS: 'OK' })
|
||||
// #ifdef APP
|
||||
if (option.content) option.content = '\n' + option.content
|
||||
else option.content = ' ' // 20240229 从前在手机app里,content必须存在。现在似乎没关<-系了,但不确定。
|
||||
// #endif
|
||||
uni.showModal(option)
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user