u
This commit is contained in:
parent
767fa447a2
commit
bb485c5ad4
69
unitool.js
69
unitool.js
@ -56,7 +56,7 @@ module.exports = {
|
|||||||
: globalThis.getCurrentPages?.()?.pop?.() || {} // [20220401] 发现在 topWindow 里,或者在 App.vue 里, getCurrentPages() 是 undefined 和 空数组 [],因此在这里默认 {} 做保护。
|
: globalThis.getCurrentPages?.()?.pop?.() || {} // [20220401] 发现在 topWindow 里,或者在 App.vue 里, getCurrentPages() 是 undefined 和 空数组 [],因此在这里默认 {} 做保护。
|
||||||
},
|
},
|
||||||
|
|
||||||
localizeText (i18nText, langCode) {
|
localizeText (i18nText, { langCode, precise = false } = {}) {
|
||||||
i18nText =
|
i18nText =
|
||||||
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
|
||||||
@ -68,12 +68,7 @@ module.exports = {
|
|||||||
return (
|
return (
|
||||||
i18nText?.[langCode] ||
|
i18nText?.[langCode] ||
|
||||||
i18nText?.[my.langNow()] ||
|
i18nText?.[my.langNow()] ||
|
||||||
i18nText?.earTH ||
|
(precise ? '' : i18nText?.earTH || i18nText?.defLAN || i18nText?.gloBAL || i18nText?.enUS || Object.values(i18nText)[0] || '')
|
||||||
i18nText?.defLAN ||
|
|
||||||
i18nText?.gloBAL ||
|
|
||||||
i18nText?.enUS ||
|
|
||||||
Object.values(i18nText)[0] ||
|
|
||||||
''
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return ''
|
return ''
|
||||||
@ -209,6 +204,29 @@ module.exports = {
|
|||||||
// #endif
|
// #endif
|
||||||
}
|
}
|
||||||
apiWhat._passtoken = uni.getStorageSync('_passtoken')
|
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 = {}
|
let result = {}
|
||||||
if (baseType === 'UNICLOUD_OBJECT') {
|
if (baseType === 'UNICLOUD_OBJECT') {
|
||||||
const uniObj = uniCloud.importObject(apiWho)
|
const uniObj = uniCloud.importObject(apiWho)
|
||||||
@ -287,27 +305,6 @@ module.exports = {
|
|||||||
// 注意1,resultServer 和 resultCloud 推荐遵循同样的格式 { _state, error | data },这样方便前端做统一判断。
|
// 注意1,resultServer 和 resultCloud 推荐遵循同样的格式 { _state, error | data },这样方便前端做统一判断。
|
||||||
// 注意2,虽然预设了 resultServer 和 resultCloud = {},但如果后台返回了 null,那么 resultServer/resultCloud 也是 null。
|
// 注意2,虽然预设了 resultServer 和 resultCloud = {},但如果后台返回了 null,那么 resultServer/resultCloud 也是 null。
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
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(
|
console.log(
|
||||||
{
|
{
|
||||||
_at: new Date().toJSON(),
|
_at: new Date().toJSON(),
|
||||||
@ -705,7 +702,7 @@ module.exports = {
|
|||||||
callback // 发生在 toast 之后
|
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)
|
title = this.localizeText(title)
|
||||||
if (!title) {
|
if (!title) {
|
||||||
return
|
return
|
||||||
@ -720,12 +717,12 @@ module.exports = {
|
|||||||
globalThis.getCurrentPages?.()?.pop()?.$refs?.mytoast ||
|
globalThis.getCurrentPages?.()?.pop()?.$refs?.mytoast ||
|
||||||
globalThis.getApp().globalData?.mytoast ||
|
globalThis.getApp().globalData?.mytoast ||
|
||||||
wo?.mytoast
|
wo?.mytoast
|
||||||
if (mypopup) {
|
if (!sysToast && 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
|
||||||
mypopup.open()
|
mypopup.open()
|
||||||
} else if (mytoast) {
|
} else if (!sysToast && mytoast) {
|
||||||
// 来自 <ucToast> 或 <u-toast> 或 <u-top-tips> // rename to popToast?
|
// 来自 <ucToast> 或 <u-toast> 或 <u-top-tips> // rename to popToast?
|
||||||
mytoast?.show?.({ type, title, duration, ...rest })
|
mytoast?.show?.({ type, title, duration, ...rest })
|
||||||
} else {
|
} else {
|
||||||
@ -758,16 +755,16 @@ module.exports = {
|
|||||||
uni.showModal(option) // uni.showModal 的 showCancel 默认为 true
|
uni.showModal(option) // uni.showModal 的 showCancel 默认为 true
|
||||||
},
|
},
|
||||||
|
|
||||||
showLoading ({ title = { zhCN: '加载中...', enUS: 'Loading...' }, mask } = {}) {
|
showLoading ({ title = { zhCN: '加载中...', enUS: 'Loading...' }, mask = false } = {}) {
|
||||||
title = this.localizeText(title)
|
title = this.localizeText(title)
|
||||||
// #ifndef APP
|
// #ifndef APP
|
||||||
uni.showLoading({ title, mask })
|
uni.showLoading({ title, mask }) // 原函数的 mask 默认为 false
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef APP
|
// #ifdef APP
|
||||||
// 在安卓应用里,uni.showLoading() 重复调用,导致不断闪烁跳动。
|
// 在安卓应用里,uni.showLoading() 重复调用,导致不断闪烁跳动。
|
||||||
// plus.nativeUI.showWaiting() 调用多了则导致死机。
|
// plus.nativeUI.showWaiting() 调用多了则导致死机。
|
||||||
// 还好,showWaiting() 返回 waiting 对象,可以 waiting.setTitle()
|
// 还好,showWaiting() 返回 waiting 对象,可以 waiting.setTitle()
|
||||||
return plus.nativeUI.showWaiting(title, { modal: mask })
|
return plus.nativeUI.showWaiting(title, { modal: mask }) // 原函数的 mask 默认为 true
|
||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
hideLoading () {
|
hideLoading () {
|
||||||
@ -920,11 +917,9 @@ module.exports = {
|
|||||||
self.showToast?.({
|
self.showToast?.({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
title: `${this.localizeText?.({ zhCN: '已拷贝\n', enUS: 'Copied\n' }) || ''}${text}`,
|
title: `${this.localizeText?.({ zhCN: '已拷贝\n', enUS: 'Copied\n' }) || ''}${text}`,
|
||||||
|
sysToast,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (sysToast) {
|
|
||||||
uni.showToast({ title: this.localizeText?.({ zhCN: '已拷贝', enUS: 'Copied' }) })
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user