From 002efd6b94b62de336d2b0580429606b7e0d70fa Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 18 Jun 2020 18:29:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20App=20=E7=AB=AF=20u?= =?UTF-8?q?ni.hideLoading=20=E4=BC=9A=E6=8A=8A=20uni.showToast=20=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E6=8E=89=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/api/route/navigate-back.js | 6 +- .../app-plus/service/api/ui/popup.js | 91 ++++++++----------- 2 files changed, 41 insertions(+), 56 deletions(-) diff --git a/src/platforms/app-plus/service/api/route/navigate-back.js b/src/platforms/app-plus/service/api/route/navigate-back.js index a2696e7a1..da6769711 100644 --- a/src/platforms/app-plus/service/api/route/navigate-back.js +++ b/src/platforms/app-plus/service/api/route/navigate-back.js @@ -103,7 +103,9 @@ export function navigateBack ({ return } - uni.hideToast() // 后退时,关闭 toast,loading + // 后退时,关闭 toast,loading + uni.hideToast() + uni.hideLoading() if (currentPage.$page.meta.isQuit) { quit() @@ -120,4 +122,4 @@ export function navigateBack ({ return { errMsg: 'navigateBack:ok' } -} +} diff --git a/src/platforms/app-plus/service/api/ui/popup.js b/src/platforms/app-plus/service/api/ui/popup.js index e70eada70..9f7cd1f3a 100644 --- a/src/platforms/app-plus/service/api/ui/popup.js +++ b/src/platforms/app-plus/service/api/ui/popup.js @@ -6,17 +6,16 @@ import { invoke } from '../../bridge' -let waiting -let waitingTimeout -let toast = false -let toastTimeout +let toast +let toastType +let timeout export function showLoading (args) { - return callApiSync(showToast, args, 'showToast', 'showLoading') + return callApiSync(showToast, Object.assign({}, args, { type: 'loading' }), 'showToast', 'showLoading') } export function hideLoading () { - return callApiSync(hideToast, Object.create(null), 'hideToast', 'hideLoading') + return callApiSync(hide, 'loading', 'hide', 'hideLoading') } export function showToast ({ @@ -25,41 +24,18 @@ export function showToast ({ image = '', duration = 1500, mask = false, - position = '' + position = '', + type = 'toast' } = {}) { - if (position) { - if (toast) { - toastTimeout && clearTimeout(toastTimeout) - plus.nativeUI.closeToast() - } - if (waiting) { - waitingTimeout && clearTimeout(waitingTimeout) - waiting.close() - } - if (~['top', 'center', 'bottom'].indexOf(position)) { - plus.nativeUI.toast(title, { - verticalAlign: position - }) - toast = true - toastTimeout = setTimeout(() => { - hideToast() - }, 2000) - return { - errMsg: 'showToast:ok' - } - } - console.warn('uni.showToast 传入的 "position" 值 "' + position + '" 无效') - } - - if (duration) { - if (waiting) { - waitingTimeout && clearTimeout(waitingTimeout) - waiting.close() - } - if (toast) { - toastTimeout && clearTimeout(toastTimeout) - plus.nativeUI.closeToast() - } + hide(null) + toastType = type + if (['top', 'center', 'bottom'].includes(position)) { + // 仅可以关闭 richtext 类型,但 iOS 部分情况换行显示有问题 + plus.nativeUI.toast(title, { + verticalAlign: position + }) + toast = true + } else { if (icon && !~['success', 'loading', 'none'].indexOf(icon)) { icon = 'success' } @@ -93,33 +69,40 @@ export function showToast ({ height: '55px', icon: '__uniappsuccess.png', interval: duration - } } } - waiting = plus.nativeUI.showWaiting(title, waitingOptions) - waitingTimeout = setTimeout(() => { - hideToast() - }, duration) + toast = plus.nativeUI.showWaiting(title, waitingOptions) } + + timeout = setTimeout(() => { + hide(null) + }, duration) return { errMsg: 'showToast:ok' } } export function hideToast () { - if (toast) { - toastTimeout && clearTimeout(toastTimeout) - plus.nativeUI.closeToast() - toast = false + return callApiSync(hide, 'toast', 'hide', 'hideToast') +} + +export function hide (type = 'toast') { + if (type && type !== toastType) { + return } - if (waiting) { - waitingTimeout && clearTimeout(waitingTimeout) - waiting.close() - waiting = null - waitingTimeout = null + if (timeout) { + clearTimeout(timeout) + timeout = null + } + if (toast === true) { + plus.nativeUI.closeToast() + } else if (toast && toast.close) { + toast.close() } + toast = null + toastType = null return { errMsg: 'hideToast:ok' } -- GitLab