1***@163.com
1***@163.com
  • 发布:2021-04-26 14:37
  • 更新:2021-04-26 14:37
  • 阅读:702

微信H5静默授权获取code以及H5页面历史回退死循环问题

分类:uni-app
<template>  
    <view>  

        <view class="box-input">  
            <text>提现金额:</text> <input type="number" v-model="price" placeholder="请输入提现金额" />  
            <!-- <view @click="cashPrice">全部提现</view> -->  
        </view>  
        <view class="submit-btn">  
            <button @click="submitApply">提交申请</button>  
        </view>  
        <view class="list">  
            <view>  
                1.单次提现额度不得低于1元  
            </view>  
            <view>  
                2.当前余额是{{canPrice/100.0}}元  
            </view>  
            <view>  
                3.每个用户每天提现次数无限制  
            </view>  
        </view>  
    </view>  
</template>  

<script>  
    import {  
        submitWithdraw,  
        getUserPromotionInfo  
    } from '../../utils/http.js'  
    export default {  
        data() {  
            return {  
                code: '',  
                price: '',  
                canPrice: 0  
            }  
        },  
        methods: {  
            retunTopath() {  
                 uni.redirectTo({  
                    url:'../cash/cash'  
                 })  
            },  
            //微信支付获取code传给后台  
            getCode() {  
                //测试号  
                let appID = "xxxxxxxxxxx";  
                console.log(this.code)  
                this.code = this.getUrlCode().code  
                let redirectUri = encodeURIComponent(location.href);  
                console.log(redirectUri)  
                if (this.code == null || this.code === '' || this.code == undefined) {  
                    let url =  
                        `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appID}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=123&#wechat_redirect`;  

                    window.location.replace(url)  
                } else {  
                    this.code = this.getUrlCode().code  
                }  
            },  
            getUrlCode() {  
                // 截取url中的code方法  
                var url = location.href; //获取打开的公众号的路径  
                let winUrl = url;  
                var theRequest = new Object();  
                if (url.indexOf('?') != -1) {  
                    var str = url.substr(url.indexOf('?') + 1);  
                    var strs = str.split('&');  
                    for (var i = 0; i < strs.length; i++) {  
                        var items = strs[i].split('=');  
                        console.log(items)  
                        theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1];  
                        console.log(theRequest[strs[i].split('=')[0]])  
                    }  
                }  
                return theRequest;  
            },  
            submitApply() {  
                if (Number(this.price) < 1) {  
                    uni.showToast({  
                        icon: 'none',  
                        title: '提现金额过小'  
                    })  
                    return  
                }  
                let params = {  
                    payMode: 2,  
                    price: this.price * 100,  
                    code: this.code  
                }  
                submitWithdraw(params).then(res => {  
                    console.log(res)  
                    if (res.success) {  
                        uni.showToast({  
                            title: '提交成功',  
                            icon: 'none'  
                        })  
                        uni.navigateTo({  
                            url: '../cash/cash'  
                        })  
                    } else {  
                        uni.showToast({  
                            icon: 'none',  
                            title: res.msg  
                        })  
                    }  
                })  
            },  
            requestGetUserPromotionInfo() {  
                getUserPromotionInfo().then(response => {  
                    console.log(response)  
                    if (response.success) {  
                        this.canPrice = response.data.price  
                    }  
                })  
            },  
        },  
        onLoad() {  
            if (!this.code) {  
                // this.getCode()  
            }  

        },  
        onUnload() {  

        },  
        onShow() {  
            this.requestGetUserPromotionInfo()  
        }  
    }  
</script>  

<style>  
    .box-input {  
        display: flex;  
        padding: 46rpx 30rpx;  
        border-bottom: 2rpx solid #EEEEEE;  

    }  

    .box-input text {  
        margin-right: 20rpx;  
        font-size: 30rpx;  
        font-family: PingFang SC;  
        font-weight: 500;  
        color: #333333;  
    }  

    .box-input view {  
        text-align: right;  
        flex: 1;  
        font-size: 28rpx;  
        font-family: PingFang SC;  
        font-weight: 500;  
        color: #3BCEA3;  
    }  

    .submit-btn {  

        bottom: 40rpx;  
        width: 690rpx;  
        height: 88rpx;  
        margin: 62rpx auto 32rpx auto;  
        background: linear-gradient(-90deg, #65DB8C 0%, #3ACEA3 100%);  
        border-radius: 10rpx;  

    }  

    button::after {  
        border: 0;  
    }  

    .submit-btn button {  
        background: linear-gradient(-90deg, #65DB8C 0%, #3ACEA3 100%);  
        color: #FFFFFF;  
    }  

    .list {  
        padding: 0 30rpx;  
    }  

    .list view {  
        height: 60rpx;  
        line-height: 60rpx;  
        color: #999999;  
        font-size: 26rpx;  
    }  
</style>  

出现了一只回退回退不到上一个页面,一值在重复的调用

2021-04-26 14:37 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复