//index.js //获取应用实例 const app = getApp() const host = app.globalData.host; Page({ data: { act:6, openid:'', show:0, data:[], news: ['国家安全生产监督管理总局30号令'], animationData:{} }, //事件处理函数 bindViewTap: function() { wx.navigateTo({ url: '../logs/logs' }) }, tabchange:function(e){ this.setData({ act: e.target.dataset.id }) }, onLoad: function () { wx.showLoading({ title: '', }) this.getData() this.setData({ openid: app.globalData.openid }) console.log(this.data.openid) this.getNotice() wx.getStorage({ key: 'userInfo', success: res=> { if(res.data){ this.setData({show:0}) } }, }) var animation = wx.createAnimation({ duration: 1000, timingFunction: 'ease', }) this.animation = animation animation.translateX(100).step() this.setData({ animationData: animation.export() }) }, // onGotUserInfo: function (e) { // wx.setStorage({ // key: 'userInfo', // data: e.detail.userInfo, // }) // console.log(app.globalData.openid) // wx.request({ // url: host+'/api/wx/auth', // method:'POST', // data:{ // nickname: e.detail.userInfo.nickName, // avatar: e.detail.userInfo.avatarUrl, // openid: app.globalData.openid, // }, // success:res=>{ // console.log(res) // this.setData({ // show:0 // }) // } // }) // }, getData:function(){ wx.request({ url: host +'/api/wx/index', method:'GET', success:res=>{ wx.hideLoading() let data=res.data.data; this.setData({ data:res.data.data }) for(let i=0;i{ wx.showToast({ title: '服务器开小差啦!', icon: 'none', duration: 2000 }) } }) }, getNotice:function(){ wx.showLoading({ title: '', }) wx.request({ url: host+'/api/wx/notice', header: { openid: this.data.openid }, success:res=>{ if (res.statusCode == 403) { this.save() } else { this.setData({ list:res.data.data.list }) if(res.data.data.new > 0){ wx.setTabBarBadge({ index: 2, text: String(res.data.data.new) }); } } } }) }, save: function () { var _this = this wx.showLoading({ title: '正在登录', }) wx.getStorage({ key: 'userInfo', success: function (res) { console.log(res) wx.request({ url: host + '/api/wx/auth', method: 'POST', data: { nickname: res.data.nickName, avatar: res.data.avatarUrl, openid: app.globalData.openid, }, success: res => { wx.hideLoading() _this.getData(); } }) }, }) } })