This commit is contained in:
Luk 2025-01-17 16:14:09 +08:00
parent 767fa447a2
commit bb485c5ad4

View File

@ -56,7 +56,7 @@ module.exports = {
: globalThis.getCurrentPages?.()?.pop?.() || {} // [20220401] 发现在 topWindow 里,或者在 App.vue 里, getCurrentPages() 是 undefined 和 空数组 [],因此在这里默认 {} 做保护。
},
localizeText (i18nText, langCode) {
localizeText (i18nText, { langCode, precise = false } = {}) {
i18nText =
i18nText || // 如果传入i18n参数 ({zhCN:'...', enUS:'...'})
this.i18nText || // 1) 如果挂载到具体页面的 computed { lote: wo?.localizeText } 那么 this 就是当前页面,直接取用 this.i18nText 即可。2) 对于组件内定义的 i18nText要使用 this 来获得组件内的 i18nText
@ -68,12 +68,7 @@ module.exports = {
return (
i18nText?.[langCode] ||
i18nText?.[my.langNow()] ||
i18nText?.earTH ||
i18nText?.defLAN ||
i18nText?.gloBAL ||
i18nText?.enUS ||
Object.values(i18nText)[0] ||
''
(precise ? '' : i18nText?.earTH || i18nText?.defLAN || i18nText?.gloBAL || i18nText?.enUS || Object.values(i18nText)[0] || '')
)
} else {
return ''
@ -209,6 +204,29 @@ module.exports = {
// #endif
}
apiWhat._passtoken = uni.getStorageSync('_passtoken')
if (process.env.NODE_ENV !== 'production') {
console.log(
{
_at: startTime,
_io: 'CREQ',
_path: `${thisRoute} => ${apiWho}/${apiTodo}`,
apiurl,
baseType,
apiWhat,
timeout,
}
// `%c ${startTime} (IN) ${thisRoute} :: ${apiTodo}`,
// 'background: #87cefa; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
// {
// baseType,
// apiWho,
// apiTodo,
// apiWhat,
// timeout,
// apiurl,
// }
)
}
let result = {}
if (baseType === 'UNICLOUD_OBJECT') {
const uniObj = uniCloud.importObject(apiWho)
@ -287,27 +305,6 @@ module.exports = {
// 注意1resultServer 和 resultCloud 推荐遵循同样的格式 { _state, error | data },这样方便前端做统一判断。
// 注意2虽然预设了 resultServer 和 resultCloud = {},但如果后台返回了 null那么 resultServer/resultCloud 也是 null。
if (process.env.NODE_ENV !== 'production') {
console.log(
{
_at: startTime,
_io: 'CREQ',
_path: `${thisRoute} => ${apiWho}/${apiTodo}`,
apiurl,
baseType,
apiWhat,
timeout,
}
// `%c ${startTime} (IN) ${thisRoute} :: ${apiTodo}`,
// 'background: #87cefa; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
// {
// baseType,
// apiWho,
// apiTodo,
// apiWhat,
// timeout,
// apiurl,
// }
)
console.log(
{
_at: new Date().toJSON(),
@ -705,7 +702,7 @@ module.exports = {
callback // 发生在 toast 之后
})
*/
showToast ({ type = 'success', image, title, duration = 2000, wo = globalThis.wo, ...rest } = {}) {
showToast ({ type = 'success', image, title, duration = 2000, wo = globalThis.wo, sysToast = false, ...rest } = {}) {
title = this.localizeText(title)
if (!title) {
return
@ -720,12 +717,12 @@ module.exports = {
globalThis.getCurrentPages?.()?.pop()?.$refs?.mytoast ||
globalThis.getApp().globalData?.mytoast ||
wo?.mytoast
if (mypopup) {
if (!sysToast && mypopup) {
wo.ss.popMessage = title
wo.ss.popType = type // success/error/warning/info
wo.ss.popDuration = duration
mypopup.open()
} else if (mytoast) {
} else if (!sysToast && mytoast) {
// 来自 <ucToast> 或 <u-toast> 或 <u-top-tips> // rename to popToast?
mytoast?.show?.({ type, title, duration, ...rest })
} else {
@ -758,16 +755,16 @@ module.exports = {
uni.showModal(option) // uni.showModal 的 showCancel 默认为 true
},
showLoading ({ title = { zhCN: '加载中...', enUS: 'Loading...' }, mask } = {}) {
showLoading ({ title = { zhCN: '加载中...', enUS: 'Loading...' }, mask = false } = {}) {
title = this.localizeText(title)
// #ifndef APP
uni.showLoading({ title, mask })
uni.showLoading({ title, mask }) // 原函数的 mask 默认为 false
// #endif
// #ifdef APP
// 在安卓应用里uni.showLoading() 重复调用,导致不断闪烁跳动。
// plus.nativeUI.showWaiting() 调用多了则导致死机。
// 还好showWaiting() 返回 waiting 对象,可以 waiting.setTitle()
return plus.nativeUI.showWaiting(title, { modal: mask })
return plus.nativeUI.showWaiting(title, { modal: mask }) // 原函数的 mask 默认为 true
// #endif
},
hideLoading () {
@ -920,11 +917,9 @@ module.exports = {
self.showToast?.({
type: 'success',
title: `${this.localizeText?.({ zhCN: '已拷贝\n', enUS: 'Copied\n' }) || ''}${text}`,
sysToast,
})
}
if (sysToast) {
uni.showToast({ title: this.localizeText?.({ zhCN: '已拷贝', enUS: 'Copied' }) })
}
},
})
},