l***@163.com
l***@163.com
  • 发布:2025-01-15 08:55
  • 更新:2025-01-15 11:10
  • 阅读:26

【报Bug】uni统计2.0配置微信小程序平台导致内存耗尽崩溃

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: Alpha

HBuilderX版本号: 4.45

第三方开发者工具版本号: 1.06.2501092

基础库版本号: 3.7.2

项目创建方式: HBuilderX

示例代码:

async onLoad(options) {
let that = this
uni.hideTabBar(); //隐藏原生tabbar

        // uni.getNetworkType({  
        //  success: function(res) {  
        //      console.log("network:", res.networkType);  
        //  }  
        // });  

        // uni.onNetworkStatusChange(this.onNetworkStatusChange)  

        // #ifdef MP-WEIXIN  
        // wx.onBackgroundFetchData(() => {  

        // })  
        wx.getBackgroundFetchData({  
            fetchType: 'pre',  
            success(res) {  
                // console.log("fetchedData:",res) // 缓存数据  
                that.record = JSON.parse(res.fetchedData).data  
            },  
            fail(err){  
                console.log("err:",err)   
            }  
        })  
        // #endif  

    },  
    onReachBottom() { //滚动到底翻页  
        // this.$refs.udb.loadMore()  
    },  
    onReady() {  
        // #ifdef MP-WEIXIN  
        const windowInfo = wx.getWindowInfo()  
        this.windowWidth = windowInfo.screenWidth  
        // console.log("windowWidth:", windowInfo)  
        // #endif  
        // #ifndef MP-WEIXIN              
        uni.getSystemInfo({  
            success: (res) => {  
                let cha = res.screenWidth - 1320  
                // #ifdef H5  
                this.windowWidth = res.screenWidth - cha;  
                // #endif  
                // #ifndef H5  
                this.windowWidth = res.screenWidth  
                // #endif  

            },  
        });  
        // #endif  
    },  
    async onShow() {  
        let that = this  
        // this.tabBerLists = uni.getStorageSync('tabBarList') // 自定义的tabbar赋值  
        // console.log("hasmore", that.hasMore)  
        let token = uni.getStorageSync('uni_id_token')  
        // console.log("Token", token)  
        if (token) {  
            let resuser = await db.collection("uni-id-users").where({  
                    token: token  
                })  
                .field({  
                    username: true,  
                    userType: true,  
                    realName: true,  
                    wx_openid: true,  
                    identitycard: true  
                })  
                .get()  
            // console.log("resuser", resuser)  

            if (resuser.data.length == 1) {  
                let userdata = resuser.data[0]  
                getApp().globalData.userName = userdata.username  
                getApp().globalData.realName = userdata.realName  
                getApp().globalData.userType = userdata.userType  
                getApp().globalData.adminType = userdata.userType  
                getApp().globalData.openid = userdata.wx_openid ? userdata.wx_openid.mp : ''  
                //未读消息  
                // console.log("userName:", getApp().globalData.userName)  
                var count = await db.collection('Messages')  
                    .where({  
                        messageSend: getApp().globalData.userName,  
                        isRead: false  
                    }).count()  
                // console.log("count:", count)  
                getApp().globalData.unreadMessages = count.total  
                //通过manager更新  
                let resmanager = await db.collection("Managers").where({  
                        userName: userdata.username  
                    })  
                    .get()  
                if (resmanager.data.length > 0) {  
                    resmanager = resmanager.data[0]  
                    getApp().globalData.adminType = resmanager.adminType  
                    getApp().globalData.userDept = resmanager.department  
                    getApp().globalData.adminLevel = resmanager.adminType  
                    getApp().globalData.scopeCompany = resmanager.scopeCompany  
                    getApp().globalData.division = resmanager.division  
                    getApp().globalData.position = resmanager.position  
                }  

                if (resuser.data[0].userType == '供应商') {  
                    getApp().globalData.userDept = '供应商'  

                }  
                if (resuser.data[0].userType == '管理员') {  
                    that.$store.commit('setRoleId', 1)  
                    getApp().globalData.setRoleId = 1  
                    that.tabBerLists = uni.getStorageSync('tabBarList') // 自定义的tabbar赋值  
                    if (that.tabBerLists.length == 4) {  
                        that.currenttab = 3  
                        that.tabBerLists[2].mark = getApp().globalData.unreadMessages  

                    }  
                } else {  
                    that.$store.commit('setRoleId', 0)  
                    getApp().globalData.setRoleId = 0  
                    that.tabBerLists = uni.getStorageSync('tabBarList')  
                    if (that.tabBerLists.length == 4) {  
                        that.currenttab = 3  
                        that.tabBerLists[1].mark = getApp().globalData.unreadMessages  
                    }  
                }  
            } else if (resuser.data.length == 0) {  
                uni.navigateTo({  
                    url: "/pagessub/ucenter/pages/login/login-withpwd"  
                })  
            }  

        } else {  
            console.log("user has no token")  
            uni.showToast({  
                title: "未登录",  
                icon: 'none'  
            })  
            that.$store.commit('setRoleId', 0)  
            getApp().globalData.setRoleId = 0  
            that.tabBerLists = uni.getStorageSync('tabBarList')  
            if (that.tabBerLists.length == 4) {  
                that.currenttab = 3  
            }  
        }  

        // #ifndef MP-WEIXIN  
        let resp = await db.collection('Projects')  
            .where({  
                isShow: true  
            })  
            .orderBy('flag', 'desc')  
            .get()  

        if (resp.data) {  
            that.record = resp.data  
        } else {  
            uni.showToast({  
                title: "没有数据"  
            })  
        }  
        // #endif  

        // this.$refs.udb.loadData() //udb为unicloud-db组件的ref属性值  

    },

操作步骤:

打开uni统计2.0

预期结果:

正确处理报错,不陷入死循环

实际结果:

内存耗尽,首页无法打开

bug描述:

升级到最新版HBuilderX4.45 正式版与alpha版发现的问题,编译到微信开发者工具测试内存很快耗尽,经排查发现,是uni统计代码造成的。关闭微信平台后,一切正常。首页代码很正常,没有死循环。目前只能暂时关闭统计。

2025-01-15 08:55 负责人:无 分享
已邀请:
DCloud_UNI_HT

DCloud_UNI_HT

是 vue2 项目还是 vue3 项目 ?

  • DCloud_UNI_HT

    已经复现,在排查了,修复后我会告知

    2025-01-15 11:15

要回复问题请先登录注册