From 2cc8f66651941fac2c6240db783e998e55f8efe0 Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Thu, 7 Dec 2023 19:16:02 +0800 Subject: [PATCH] u --- unitool.js | 75 +++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/unitool.js b/unitool.js index bed5fe4..310c2da 100644 --- a/unitool.js +++ b/unitool.js @@ -37,7 +37,7 @@ export default { thisPage () { return this.__page__ ? 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) { @@ -167,7 +167,9 @@ export default { const thisRoute = getCurrentPages()?.pop?.()?.route || 'VueApp' // 立刻保存 route,因为在调用后台后,可能已切换到了其他页面。 const startTime = new Date().toJSON() 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') let result = {} if (baseType === 'UNICLOUD_OBJECT') { @@ -420,16 +422,16 @@ export default { return /msie/.test(userAgent) && !/opera/.test(userAgent) ? 'msie' : /opera/.test(userAgent) - ? 'opera' - : /version.*safari/.test(userAgent) - ? 'safari' - : /chrome/.test(userAgent) - ? 'chrome' - : /gecko/.test(userAgent) && !/webkit/.test(userAgent) - ? 'firefox' - : /micromessenger/.test(userAgent) - ? 'wechat' - : 'unknown' // 只要在 H5, 即使不认识也要返回一个名称。 + ? 'opera' + : /version.*safari/.test(userAgent) + ? 'safari' + : /chrome/.test(userAgent) + ? 'chrome' + : /gecko/.test(userAgent) && !/webkit/.test(userAgent) + ? 'firefox' + : /micromessenger/.test(userAgent) + ? 'wechat' + : 'unknown' // 只要在 H5, 即使不认识也要返回一个名称。 // #endif return '' // 如果不在 H5。 }, @@ -451,29 +453,28 @@ export default { }) */ showToast ({ tool, type = 'success', image, title, duration = 2000, wo = globalThis.wo, ...rest } = {}) { - // rename to popToast? - if (tool !== 'uni') { - // 来自 - const toast = getCurrentPages()?.pop()?.$refs?.toast || getApp().globalData?.toast || wo?.toast - const popup = getCurrentPages()?.pop()?.$refs?.popup || getApp().globalData?.popup || wo?.popup - if (toast) { - toast.show({ type, title, duration, ...rest }) - return - } else if (popup && wo?.ss) { - wo.ss.popMessage = title - wo.ss.popType = type // success/error/warning/info - wo.ss.popDuration = duration - popup.open() - return - } + title = this.localizeText(title) + if (tool === 'uni') { + // #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 + return + } + // 来自 // rename to popToast? + const popup = getCurrentPages()?.pop()?.$refs?.popup || getApp().globalData?.popup || wo?.popup + 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 } = {}) { @@ -574,7 +575,7 @@ export default { (res) => { pc.setLocalDescription(res) }, - () => {} + () => { } ) //延迟,让一切都能完成 setTimeout(() => { @@ -605,11 +606,11 @@ export default { next_focus (currentFocus, focusList) { focusList = focusList || getCurrentPages()?.pop()?.focusList if (focusList) { - for (let n in focusList) { + for (let n in focusList) { // 不论对数组或对象都有效,n 是数组的index 或对象的key focusList[n] = false } setTimeout(() => { - focusList[(parseInt(currentFocus) + 1) % Object.keys(focusList).length] = true + focusList[(currentFocus + 1) % Object.keys(focusList).length] = true }, 200) // 如果没有 setTimeout 至少 200ms, 焦点短暂跳到下一个后,又会消失 } },