From 55a3015c837c1e581ca214dae9f1db8085922582 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 18 Jul 2019 12:12:08 +0800 Subject: [PATCH] fix(h5): hideLoading (http://ask.dcloud.net.cn/question/74975) --- src/core/helpers/protocol/popup.js | 4 --- src/core/service/api/popup.js | 2 +- .../h5/components/app/popup/mixins/toast.js | 27 ++++++++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/core/helpers/protocol/popup.js b/src/core/helpers/protocol/popup.js index a2838be96..c2b5ae689 100644 --- a/src/core/helpers/protocol/popup.js +++ b/src/core/helpers/protocol/popup.js @@ -90,10 +90,6 @@ export const showLoading = { visible: { type: Boolean, default: true - }, - isShowLoading: { - type: Boolean, - default: true } } diff --git a/src/core/service/api/popup.js b/src/core/service/api/popup.js index f07488fcc..320c68fe5 100644 --- a/src/core/service/api/popup.js +++ b/src/core/service/api/popup.js @@ -22,7 +22,7 @@ export function hideToast () { } export function showLoading (args) { - emit('onShowToast', args) + emit('onShowLoading', args) return {} } diff --git a/src/platforms/h5/components/app/popup/mixins/toast.js b/src/platforms/h5/components/app/popup/mixins/toast.js index b27f9e4d2..3dd0be026 100644 --- a/src/platforms/h5/components/app/popup/mixins/toast.js +++ b/src/platforms/h5/components/app/popup/mixins/toast.js @@ -7,28 +7,37 @@ export default { } }, created () { - UniServiceJSBridge.on('onShowToast', args => { - setTimeout(() => { // 延迟一下 show 可解决窗口打开前调用 showToast 在 onHidePopup 之后触发 - this.showToast = args - }, 10) - }) + let showType = '' + + const createOnShow = (type) => { + return (args) => { + showType = type + setTimeout(() => { // 延迟一下 show 可解决窗口打开前调用 showToast 在 onHidePopup 之后触发 + this.showToast = args + }, 10) + } + } + + UniServiceJSBridge.on('onShowToast', createOnShow('onShowToast')) + UniServiceJSBridge.on('onShowLoading', createOnShow('onShowLoading')) const createOnHide = (type) => { return () => { let warnMsg = '' - if (type === 'onHideToast' && this.showToast.isShowLoading) { + if (type === 'onHideToast' && showType !== 'onShowToast') { warnMsg = '请注意 showToast 与 hideToast 必须配对使用' - } else if (type === 'onHideLoading' && !this.showToast.isShowLoading) { + } else if (type === 'onHideLoading' && showType !== 'onShowLoading') { warnMsg = '请注意 showLoading 与 hideLoading 必须配对使用' } if (warnMsg) { return console.warn(warnMsg) - } + } + showType = '' setTimeout(() => { // 与 show 对应延迟10ms,避免快速调用 show,hide 导致无法关闭 this.showToast.visible = false }, 10) } - } + } UniServiceJSBridge.on('onHidePopup', createOnHide('onHidePopup')) UniServiceJSBridge.on('onHideToast', createOnHide('onHideToast')) -- GitLab