From 74ea5528e7cbaf2bc617c23a1dbfc700406b0293 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Tue, 04 Jan 2022 10:50:44 +0800 Subject: [PATCH] 微调小程序中文本输入框行为,降低多文本框输入切换时焦掉丢失的几率 --- common/WxH5Pay.js | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-) diff --git a/common/WxH5Pay.js b/common/WxH5Pay.js index 07022b9..be9fd8a 100644 --- a/common/WxH5Pay.js +++ b/common/WxH5Pay.js @@ -9,7 +9,9 @@ const askModal = { $modal: null, + _callback: null, show(type, callback) { + this._callback = callback; const that = this; Taro.showModal({ title: type === 'ask' ? '微信支付未响应?' : '微信支付仍未响应?', @@ -18,9 +20,9 @@ success: res => { // 点击重试,执行回调 if (res.confirm) { - callback(true); + that._callback && that._callback(true); } else if (res.cancel) { - callback(false); + that._callback && that._callback(false); } this.$modal = null; }, @@ -30,6 +32,7 @@ }, 10); }, cancel() { + this._callback = null; // 关闭回调,关闭弹窗不取消订单 if (this.$modal) { this.$modal.find('.taro-modal__foot > .taro-model__btn:eq(0)').trigger('click'); this.$modal = null; @@ -45,6 +48,8 @@ }; } + askModal = askModal; + callWxPay(payParam, callback, type = 'webview') { // 默认 webview 支付 if (type === 'webview') { @@ -57,7 +62,7 @@ // 2.2 秒后,如果 alreadyCall 未变为 true,跳出询问弹窗 setTimeout(() => { if (!this._data.alreadyCall) { - askModal.show('ask', next => { + this.askModal.show('ask', next => { if (next) { this.callWxPay(payParam, callback, 'webview2'); } else { @@ -80,7 +85,7 @@ // 2.2 秒后,如果 alreadyCall 未变为 true,跳出询问弹窗 setTimeout(() => { if (!this._data.alreadyCall) { - askModal.show('reload', next => { + this.askModal.show('reload', next => { if (next) { callback('fail', '页面重载中...'); window._hmt.push(['_trackEvent', 'wx', 'wx-wxPay', 'wx-wxPay-pageReload', 0]); @@ -90,7 +95,7 @@ window.location.href.split(/[#?]/)[0] + '?' + window.location.hash; } window.location.reload(); - }, 1000); + }, 1500); } else { callback('cancel', '支付已取消!(微信未响应)'); window._hmt.push(['_trackEvent', 'wx', 'wx-wxPay', 'wx-wxPay-noResponse', 0]); @@ -111,7 +116,7 @@ timestamp: sign.timeStamp, complete: complete => { // 关闭询问弹窗 - askModal.cancel(); + this.askModal.cancel(); this._data.alreadyCall = true; // 支付结果 if (complete.errMsg === 'chooseWXPay:ok') { @@ -139,7 +144,7 @@ const sign = JSON.parse(payParam); WeixinJSBridge.invoke('getBrandWCPayRequest', sign, res => { // 关闭询问弹窗 - askModal.cancel(); + this.askModal.cancel(); this._data.alreadyCall = true; // 支付结果 if (res.err_msg === 'get_brand_wcpay_request:ok') { -- Gitblit v1.9.1