import { Router } from "./utils/common"; import { requst_post_login } from './pages/api/index.js' App({ globalData: { employId:"", token: null, userInfo: null, flag: false, navHeight: null, navTop: null, windowHeight: null, navHeight: 0, navTop: 0, jnheight: 0, jnwidth: 0, screenHeight: 0, isInitialized: false }, onLaunch: function () { var that = this; // 登录1 获取code wx.login({ success: res => { // console.log(res.code+'我是登录中的') const code = res.code; if (code) { //将code发送到开发者服务器 wx.getUserInfo({ success: res => { // console.log(res,'getUserInfo') let encryptedData = res.encryptedData; let iv = res.iv; requst_post_login({ encryptedData: encryptedData, iv: iv, code: code }).then(res => { that.globalData.token = res.data.data.token; this.globalData.isInitialized = true; // console.log( that.globalData.token ,' that.globalData.token ') if (res.data.data) { // 回调 // this.globalData.employId= res.data.data; // let employId=res.data.data; //由于这里是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 wx.setStorage({ key: 'access-token', data: res.data.data.token, }) wx.setStorage({ key: 'wx_name', data: res.data.data.nickName, }) wx.setStorage({ key: 'wx_img', data: res.data.data.avatarUrl, }) setTimeout(function () { wx.switchTab({ url: '/pages/scan/scan' }) }, 400) if (this.employIdCallback){ this.employIdCallback(employId); } } else {} }).catch(err => { console.log('ajax_err', err) }) } }) } } }) //获取菜单按钮的布局位置信息 let menuButtonObject = wx.getMenuButtonBoundingClientRect(); //获取系统信息 wx.getSystemInfo({ success: res => { console.log('xxxx', res.screenWidth) //状态栏的高度 let statusBarHeight = res.statusBarHeight, //胶囊按钮与顶部的距离 navTop = menuButtonObject.top, navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2; let globalData = this.globalData; globalData.navHeight = navHeight;//导航栏高度 globalData.navTop = navTop;//胶囊按钮与顶部的距离 globalData.jnheight = menuButtonObject.height;//胶囊的高度 globalData.jnwidth = menuButtonObject.width;//胶囊的宽度 globalData.screenHeight = res.screenHeight;//屏幕高度 globalData.screenWidth = res.screenWidth; }, fail(err) { console.log(err); } }); }, //渐入,渐出实现 show : function(that,param,opacity){ var animation = wx.createAnimation({ //持续时间800ms duration: 800, timingFunction: 'ease', }); //var animation = this.animation animation.opacity(opacity).step() //将param转换为key var json = '{"' + param + '":""}' json = JSON.parse(json); json[param] = animation.export() //设置动画 that.setData(json) }, //滑动渐入渐出 slideupshow:function(that,param,px,opacity){ var animation = wx.createAnimation({ duration: 800, timingFunction: 'ease', }); animation.translateY(px).opacity(opacity).step() //将param转换为key var json = '{"' + param + '":""}' json = JSON.parse(json); json[param] = animation.export() //设置动画 that.setData(json) }, //向右滑动渐入渐出 sliderightshow: function (that, param, px, opacity) { var animation = wx.createAnimation({ duration: 800, timingFunction: 'ease', }); animation.translateX(px).opacity(opacity).step() //将param转换为key var json = '{"' + param + '":""}' json = JSON.parse(json); json[param] = animation.export() //设置动画 that.setData(json) } })