WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2021-11-22 c97815a8be3982ea32f6eff79542a9dcedba7fbb
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') {