index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. const host = app.globalData.host;
  5. Page({
  6. data: {
  7. act:6,
  8. openid:'',
  9. show:1,
  10. data:[],
  11. news: ['国家安全生产监督管理总局30号令'],
  12. animationData:{}
  13. },
  14. //事件处理函数
  15. bindViewTap: function() {
  16. wx.navigateTo({
  17. url: '../logs/logs'
  18. })
  19. },
  20. tabchange:function(e){
  21. this.setData({
  22. act: e.target.dataset.id
  23. })
  24. },
  25. onLoad: function () {
  26. this.getData()
  27. this.setData({
  28. openid: app.globalData.openid
  29. })
  30. wx.getStorage({
  31. key: 'userInfo',
  32. success: res=> {
  33. if(res.data){
  34. this.setData({show:0})
  35. }
  36. },
  37. })
  38. var animation = wx.createAnimation({
  39. duration: 1000,
  40. timingFunction: 'ease',
  41. })
  42. this.animation = animation
  43. animation.translateX(100).step()
  44. this.setData({
  45. animationData: animation.export()
  46. })
  47. },
  48. onGotUserInfo: function (e) {
  49. wx.setStorage({
  50. key: 'userInfo',
  51. data: e.detail.userInfo,
  52. })
  53. wx.request({
  54. url: host+'/api/wx/authinfo',
  55. method:'POST',
  56. data:{
  57. nickname: e.detail.userInfo.nickName,
  58. avatar: e.detail.userInfo.avatarUrl,
  59. openid: this.data.openid,
  60. },
  61. success:res=>{
  62. console.log(res)
  63. this.setData({
  64. show:0
  65. })
  66. }
  67. })
  68. },
  69. getData:function(){
  70. wx.request({
  71. url: host +'/api/wx/index',
  72. method:'GET',
  73. success:res=>{
  74. console.log(res.data)
  75. this.setData({
  76. data:res.data.data
  77. })
  78. }
  79. })
  80. }
  81. })