123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //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
- })
- 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<data.length;i++){
- if(data[i].type=='notice'){
- this.setData({
- news:data[i].list
- })
- break;
- }
- }
- },
- fail:res=>{
- wx.showToast({
- title: '服务器开小差啦!',
- icon: 'none',
- duration: 2000
- })
- }
- })
- }
- })
|