update this.thisPage() to this.thisPage?.()
This commit is contained in:
parent
274dc1bd29
commit
61424e89b6
23
unitool.js
23
unitool.js
@ -37,10 +37,9 @@ export default {
|
|||||||
localizeText (i18nText) {
|
localizeText (i18nText) {
|
||||||
i18nText =
|
i18nText =
|
||||||
i18nText || // 如果传入i18n参数 ({zhCN:'...', enUS:'...'})
|
i18nText || // 如果传入i18n参数 ({zhCN:'...', enUS:'...'})
|
||||||
(this?.__page__
|
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
|
this.thisPage?.()?.i18nText // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就报错了。因此通过 thisPage?.().i18nText 访问。
|
||||||
: this.thisPage()?.i18nText) // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就报错了。因此通过 thisPage().i18nText 访问。
|
const mylang = wo?.ss?.i18n?.mylang // this.thisPage?.() 有可能为空(例如在 topWindow 里,或者在 App.vue 里),所以用 getApp().$store 更安全. 20230513: 发现在微信小程序模拟器里,getApp().$store.state 未定义
|
||||||
const mylang = wo?.ss?.i18n?.mylang // this.thisPage() 有可能为空(例如在 topWindow 里,或者在 App.vue 里),所以用 getApp().$store 更安全. 20230513: 发现在微信小程序模拟器里,getApp().$store.state 未定义
|
|
||||||
return i18nText?.[mylang] || (typeof i18nText === 'string' ? i18nText : '') // 必须检测是否string,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
|
return i18nText?.[mylang] || (typeof i18nText === 'string' ? i18nText : '') // 必须检测是否string,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -51,7 +50,7 @@ export default {
|
|||||||
|
|
||||||
setBarTitles ({ windowTitle, pageTitle, pagesJson = this.pagesJson || wo?.pagesJson, envar = this.envar || wo?.envar } = {}) {
|
setBarTitles ({ windowTitle, pageTitle, pagesJson = this.pagesJson || wo?.pagesJson, envar = this.envar || wo?.envar } = {}) {
|
||||||
const mylang = getApp()?.$store?.state?.i18n?.mylang // 不要用 pageNow.$store,防止在 App.vue 里无法获取当前页面。
|
const mylang = getApp()?.$store?.state?.i18n?.mylang // 不要用 pageNow.$store,防止在 App.vue 里无法获取当前页面。
|
||||||
const pageNow = this.thisPage() // 需要兼顾在 App.vue 时无法获取当前页面的情况,因为如果在 topWindow 里调用本函数,getApp() 和 getCurrentPages()[getCurrentPages().length-1] 就是 undefined。
|
const pageNow = this.thisPage?.() // 需要兼顾在 App.vue 时无法获取当前页面的情况,因为如果在 topWindow 里调用本函数,getApp() 和 getCurrentPages()[getCurrentPages().length-1] 就是 undefined。
|
||||||
|
|
||||||
const navibarTitle =
|
const navibarTitle =
|
||||||
pageTitle ||
|
pageTitle ||
|
||||||
@ -145,7 +144,7 @@ export default {
|
|||||||
apiWhat = {},
|
apiWhat = {},
|
||||||
timeout,
|
timeout,
|
||||||
}) {
|
}) {
|
||||||
const thisRoute = this.thisPage()?.route || 'VueApp' // 立刻保存 this.thisPage().route,因为在调用后台后,可能已切换到了其他页面。
|
const thisRoute = this.thisPage?.()?.route || 'VueApp' // 立刻保存 this.thisPage?.().route,因为在调用后台后,可能已切换到了其他页面。
|
||||||
const startTime = new Date().toJSON()
|
const startTime = new Date().toJSON()
|
||||||
let url = undefined
|
let url = undefined
|
||||||
let result = {}
|
let result = {}
|
||||||
@ -426,19 +425,19 @@ export default {
|
|||||||
callback // 发生在 toast 之后
|
callback // 发生在 toast 之后
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
showToast ({ tool, type, image, title, duration = 2000, ...rest }) {
|
showToast ({ tool, type = 'success', image, title, duration = 2000, ...rest }) {
|
||||||
// rename to popToast?
|
// rename to popToast?
|
||||||
if (tool !== 'uni') {
|
if (tool !== 'uni') {
|
||||||
// 来自 <ucToast> 或 <u-toast> 或 <u-top-tips>
|
// 来自 <ucToast> 或 <u-toast> 或 <u-top-tips>
|
||||||
const toast = this.thisPage()?.$refs?.toast || getApp().globalData.toast || wo.toast
|
const toast = this.thisPage?.()?.$refs?.toast || getApp().globalData.toast || wo.toast
|
||||||
const popup = this.thisPage()?.$refs?.popup || getApp().globalData.popup || wo.popup
|
const popup = this.thisPage?.()?.$refs?.popup || getApp().globalData.popup || wo.popup
|
||||||
if (toast) {
|
if (toast) {
|
||||||
toast.show({ type, title, duration, ...rest })
|
toast.show({ type, title, duration, ...rest })
|
||||||
return
|
return
|
||||||
} else if (popup) {
|
} else if (popup) {
|
||||||
wo.ss.popMessage = title
|
wo.ss.popMessage = title
|
||||||
wo.ss.popType = type || 'success' // success/error/warning/info
|
wo.ss.popType = type // success/error/warning/info
|
||||||
wo.ss.popDuration = duration || 2000
|
wo.ss.popDuration = duration
|
||||||
popup.open()
|
popup.open()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -566,7 +565,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
next_focus (currentFocus, focusList = this.thisPage().focusList) {
|
next_focus (currentFocus, focusList = this.thisPage?.()?.focusList) {
|
||||||
if (focusList) {
|
if (focusList) {
|
||||||
for (let n in focusList) {
|
for (let n in focusList) {
|
||||||
focusList[n] = false
|
focusList[n] = false
|
||||||
|
Loading…
Reference in New Issue
Block a user