This commit is contained in:
陆柯 2023-12-07 19:16:02 +08:00
parent 53e3aff7b0
commit 2cc8f66651

View File

@ -37,7 +37,7 @@ export default {
thisPage () { thisPage () {
return this.__page__ return this.__page__
? this // constructor.name==='VueComponent' 只在 development 环境有用,在 production 环境会被简化成 'o'。 ? this // constructor.name==='VueComponent' 只在 development 环境有用,在 production 环境会被简化成 'o'。
: getCurrentPages().pop() || {} // [20220401] 发现在 topWindow 里,或者在 App.vue 里, getCurrentPages() 是 undefined 和 空数组 [],因此在这里默认 {} 做保护。 : getCurrentPages()?.pop?.() || {} // [20220401] 发现在 topWindow 里,或者在 App.vue 里, getCurrentPages() 是 undefined 和 空数组 [],因此在这里默认 {} 做保护。
}, },
localizeText (i18nText) { localizeText (i18nText) {
@ -167,7 +167,9 @@ export default {
const thisRoute = getCurrentPages()?.pop?.()?.route || 'VueApp' // 立刻保存 route因为在调用后台后可能已切换到了其他页面。 const thisRoute = getCurrentPages()?.pop?.()?.route || 'VueApp' // 立刻保存 route因为在调用后台后可能已切换到了其他页面。
const startTime = new Date().toJSON() const startTime = new Date().toJSON()
let url = undefined let url = undefined
apiWhat._clientInfo = globalThis.wo?.envar?.clientInfo // #ifdef H5
apiWhat._clientInfo = Object.assign(globalThis.wo?.envar?.clientInfo, { url: globalThis.location?.href, lang: globalThis.wo?.ss?.i18n?.mylang })
// #endif
apiWhat._passtoken = uni.getStorageSync('_passtoken') apiWhat._passtoken = uni.getStorageSync('_passtoken')
let result = {} let result = {}
if (baseType === 'UNICLOUD_OBJECT') { if (baseType === 'UNICLOUD_OBJECT') {
@ -420,16 +422,16 @@ export default {
return /msie/.test(userAgent) && !/opera/.test(userAgent) return /msie/.test(userAgent) && !/opera/.test(userAgent)
? 'msie' ? 'msie'
: /opera/.test(userAgent) : /opera/.test(userAgent)
? 'opera' ? 'opera'
: /version.*safari/.test(userAgent) : /version.*safari/.test(userAgent)
? 'safari' ? 'safari'
: /chrome/.test(userAgent) : /chrome/.test(userAgent)
? 'chrome' ? 'chrome'
: /gecko/.test(userAgent) && !/webkit/.test(userAgent) : /gecko/.test(userAgent) && !/webkit/.test(userAgent)
? 'firefox' ? 'firefox'
: /micromessenger/.test(userAgent) : /micromessenger/.test(userAgent)
? 'wechat' ? 'wechat'
: 'unknown' // 只要在 H5, 即使不认识也要返回一个名称。 : 'unknown' // 只要在 H5, 即使不认识也要返回一个名称。
// #endif // #endif
return '' // 如果不在 H5。 return '' // 如果不在 H5。
}, },
@ -451,29 +453,28 @@ export default {
}) })
*/ */
showToast ({ tool, type = 'success', image, title, duration = 2000, wo = globalThis.wo, ...rest } = {}) { showToast ({ tool, type = 'success', image, title, duration = 2000, wo = globalThis.wo, ...rest } = {}) {
// rename to popToast? title = this.localizeText(title)
if (tool !== 'uni') { if (tool === 'uni') {
// 来自 <ucToast> 或 <u-toast> 或 <u-top-tips> // #ifdef APP-PLUS
const toast = getCurrentPages()?.pop()?.$refs?.toast || getApp().globalData?.toast || wo?.toast uni.showToast({ icon: 'none', title, duration, ...rest })
const popup = getCurrentPages()?.pop()?.$refs?.popup || getApp().globalData?.popup || wo?.popup // plus.nativeUI.toast( title, { align: center/left/right, verticalAlign: bottom/center/top, duration:long/short, icon, iconWidth, iconHeight, style: block/inline, type:text/richtext })
if (toast) { // #endif
toast.show({ type, title, duration, ...rest }) // #ifndef APP-PLUS
return uni.showToast({ icon: 'none', image, title, duration, ...rest })
} else if (popup && wo?.ss) { // #endif
wo.ss.popMessage = title return
wo.ss.popType = type // success/error/warning/info }
wo.ss.popDuration = duration // 来自 <ucToast> 或 <u-toast> 或 <u-top-tips> // rename to popToast?
popup.open() const popup = getCurrentPages()?.pop()?.$refs?.popup || getApp().globalData?.popup || wo?.popup
return if (popup) {
} wo.ss.popMessage = title
wo.ss.popType = type // success/error/warning/info
wo.ss.popDuration = duration
popup.open()
} else {
const toast = getCurrentPages()?.pop()?.$refs?.toast || getApp().globalData?.toast || wo?.toast
toast?.show?.({ type, title, duration, ...rest })
} }
// #ifdef APP-PLUS
uni.showToast({ icon: 'none', title, duration, ...rest })
// plus.nativeUI.toast( title, { align: center/left/right, verticalAlign: bottom/center/top, duration:long/short, icon, iconWidth, iconHeight, style: block/inline, type:text/richtext })
// #endif
// #ifndef APP-PLUS
uni.showToast({ icon: 'none', image, title, duration, ...rest })
// #endif
}, },
showLoading ({ title = { zhCN: '加载中...', enUS: 'Loading...' }, mask } = {}) { showLoading ({ title = { zhCN: '加载中...', enUS: 'Loading...' }, mask } = {}) {
@ -574,7 +575,7 @@ export default {
(res) => { (res) => {
pc.setLocalDescription(res) pc.setLocalDescription(res)
}, },
() => {} () => { }
) )
//延迟,让一切都能完成 //延迟,让一切都能完成
setTimeout(() => { setTimeout(() => {
@ -605,11 +606,11 @@ export default {
next_focus (currentFocus, focusList) { next_focus (currentFocus, focusList) {
focusList = focusList || getCurrentPages()?.pop()?.focusList focusList = focusList || getCurrentPages()?.pop()?.focusList
if (focusList) { if (focusList) {
for (let n in focusList) { for (let n in focusList) { // 不论对数组或对象都有效n 是数组的index 或对象的key
focusList[n] = false focusList[n] = false
} }
setTimeout(() => { setTimeout(() => {
focusList[(parseInt(currentFocus) + 1) % Object.keys(focusList).length] = true focusList[(currentFocus + 1) % Object.keys(focusList).length] = true
}, 200) // 如果没有 setTimeout 至少 200ms, 焦点短暂跳到下一个后,又会消失 }, 200) // 如果没有 setTimeout 至少 200ms, 焦点短暂跳到下一个后,又会消失
} }
}, },