From bfff9c67052781de46be61a7ed378a4b65221e58 Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Mon, 13 Jun 2022 09:03:09 +0800
Subject: [PATCH] 工具集增加生成随机字符串的功能

---
 common/WxH5Pay.js |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/common/WxH5Pay.js b/common/WxH5Pay.js
index 07022b9..70256a4 100644
--- a/common/WxH5Pay.js
+++ b/common/WxH5Pay.js
@@ -9,27 +9,31 @@
 
 const askModal = {
     $modal: null,
+    _callback: null,
     show(type, callback) {
+        this._callback = callback;
         const that = this;
         Taro.showModal({
-            title: type === 'ask' ? '微信支付未响应?' : '微信支付仍未响应?',
+            content: type === 'ask' ? '微信支付未响应?' : '微信支付仍未响应?',
             confirmColor: '#4a8aff',
             confirmText: type === 'ask' ? '点击重试' : '重载页面',
             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;
             },
         });
         setTimeout(() => {
             this.$modal = $('.taro__modal');
+            this.$modal.find('>div>div').css('textAlign', 'center');
         }, 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 +49,8 @@
         };
     }
 
+    askModal = askModal;
+
     callWxPay(payParam, callback, type = 'webview') {
         // 默认 webview 支付
         if (type === 'webview') {
@@ -57,7 +63,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 +86,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 +96,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 +117,7 @@
                 timestamp: sign.timeStamp,
                 complete: complete => {
                     // 关闭询问弹窗
-                    askModal.cancel();
+                    this.askModal.cancel();
                     this._data.alreadyCall = true;
                     // 支付结果
                     if (complete.errMsg === 'chooseWXPay:ok') {
@@ -139,7 +145,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