弃续
弃续
  • 发布:2023-03-28 11:32
  • 更新:2023-03-28 11:32
  • 阅读:203

uin-id-pages登录后使用uni统计数据不准确问题

分类:uniCloud

1.发生问题的原因微信小程序端使用uni-id-pages登录后会跳转到首页,为了优化体验,我把跳转部分强行改成了返回上一页(路径uni-id-pages/common/store.js里的loginBack方法)

loginBack (e = {}) {  
        const {uniIdRedirectUrl = ''} = e  
        let delta = 0; //判断需要返回几层  
        let pages = getCurrentPages();  
        // console.log(pages);  
        pages.forEach((page, index) => {  
            if (pages[pages.length - index - 1].route.split('/')[3] == 'login') {  
                delta++  
            }  
        })  
        // console.log('判断需要返回几层:', delta);  
        if (uniIdRedirectUrl) {  
            return uni.redirectTo({  
                url: uniIdRedirectUrl,  
                fail: (err1) => {  
                    uni.switchTab({  
                        url:uniIdRedirectUrl,  
                        fail: (err2) => {  
                            console.log(err1,err2)  
                        }  
                    })  
                }  
            })  
        }  
        // #ifdef H5  
        if (e.loginType == 'weixin') {  
            // console.log('window.history', window.history);  
            return window.history.go(-3)  
        }  
        // #endif  

        //如果是微信小程序就返回上一页  
        // #ifdef MP-WEIXIN  
        uni.navigateBack({  
            delta:1  
        });  

        // #endif  
        // #ifndef MP-WEIXIN  
        if (delta) {  
            const page = pagesJson.pages[0]  
            return uni.reLaunch({  
                url: `/${page.path}`  
            })  
        }  
        uni.navigateBack({  
            delta  
        })  
        // #endif  
    },

2.发生的问题,使用uni-id-pages登录后发生页面跳转会带用户id进行一个login事件统计,但按1所描述的把跳转改为返回上一页进行的login事件统计就没有用户id
3.在uni-id-pages的uni-id-pages-fab-login组件的login方法登录成功后是可以打印出uni_id_token的,但执行uni.report进行login事件统计却没有携带token进行请求

login(params, type) { //联网验证登录
// console.log('执行登录开始----');
console.log({params,type});
//toLowerCase
let action = 'loginBy' + type.trim().replace(type[0], type[0].toUpperCase())
const uniIdCo = uniCloud.importObject("uni-id-co",{
customUI:true
})
uniIdCoaction.then(result => {
uni.showToast({
title: '登录成功',
icon: 'none',
duration: 2000
});

                if(uni.getStorageSync('uni_id_token')){  
                    // 登录统计  
                    uni.report('login',{})  
                    console.log(uni.getStorageSync('uni_id_token'),"AAAAAAAAAAAAAAAAAAAuni_id_token")  
                }  
                // #ifdef H5  
                result.loginType = type  
                // #endif  
                mutations.loginSuccess(result)  
            })  
            .catch(e=>{  
                uni.showModal({  
                    content: e.message,  
                    confirmText:"知道了",  
                    showCancel: false  
                });  
            })  
            .finally(e => {  
                if (type == 'univerify') {  
                    uni.closeAuthView()  
                }  
                uni.hideLoading()  
            })  
        }
2023-03-28 11:32 负责人:无 分享
已邀请:

要回复问题请先登录注册