
<style lang="scss">
    @import "uview-ui/index.scss";
</style>

<script>
	export default {

        globalData: {
            isWxBrowser:false
        },

		onLaunch: function() {
            // #ifdef H5
            let ua = window.navigator.userAgent.toLowerCase();
            console.log('+++++++浏览器++++++',ua)
            // if(ua.match(/windowswechat/i)=="windowswechat") {
            //     console.log('这windos的微信浏览器');
            // } else {
            //     console.log('这不是微信浏览器');
            // }
            if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                console.log('这是微信浏览器');
                getApp().globalData.isWxBrowser = true
            }else {
                getApp().globalData.isWxBrowser = false
                // uni.showModal({
                //     title:'温馨提示',
                //     content:'请在手机微信客户端打开连接',
                // })
            }
            // #endif

            let sysInfo = uni.getSystemInfoSync()
            let versionName = sysInfo.appVersion
            let versionNumber = sysInfo.appVersionCode

            setTimeout(() => {
            let isRegister = uni.getStorageSync('isRegister')
            console.log('是否是扫码进的注册页面===>',isRegister)
            if (!isRegister){
                let form ={
                    username:'',
                    password:'',
                    versionNumber:versionNumber
                }
                form.username = uni.getStorageSync('username')
                form.password = uni.getStorageSync('password')

                if (form.username && form.password){

                    let startDate = new Date().getTime()
                    console.log("+++++++++++++++++自动登录开始时间+++++++++++++++++++++",startDate )
                    this.$api.login.expandLogin(form).then(res => {
                        uni.setStorageSync('accessToken', res.data.data.access_token)
                        this.$api.user.getUserInfo().then(res=>{
                            console.log('获取到的用户信息：',res.data.data,'获取到的用户头像',res.data.data.img)
                            this.userInfo = res.data.data
                            uni.setStorageSync('spreadUserInfo', this.userInfo)
                        })
                        let endDate = new Date().getTime()
                        console.log("+++++++++++++++++自动登录结束时间+++++++++++++++++++++",endDate)
                        console.log("+++++++++++++++++自动登录耗时+++++++++++++++++++++",endDate-startDate,'毫秒')

                        uni.switchTab({
                            url: "/pages/index/index"
                        })
                    }).catch(err=>{
                        uni.navigateTo({
                            url: "/pages/login/login"
                        })
                    })
                }else {
                    uni.navigateTo({
                        url: "/pages/login/login"
                    })
                }

            }else {
                uni.removeStorageSync('isRegister');
            }
            },1000)
			console.log('App Launch')

		},
		onShow: function() {
            console.log('App Show')

		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>


