index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. wx.showLoading({
  27. title: '',
  28. })
  29. this.getData()
  30. this.setData({
  31. openid: app.globalData.openid
  32. })
  33. wx.getStorage({
  34. key: 'userInfo',
  35. success: res=> {
  36. if(res.data){
  37. this.setData({show:0})
  38. }
  39. },
  40. })
  41. var animation = wx.createAnimation({
  42. duration: 1000,
  43. timingFunction: 'ease',
  44. })
  45. this.animation = animation
  46. animation.translateX(100).step()
  47. this.setData({
  48. animationData: animation.export()
  49. })
  50. },
  51. onGotUserInfo: function (e) {
  52. wx.setStorage({
  53. key: 'userInfo',
  54. data: e.detail.userInfo,
  55. })
  56. wx.request({
  57. url: host+'/api/wx/authinfo',
  58. method:'POST',
  59. data:{
  60. nickname: e.detail.userInfo.nickName,
  61. avatar: e.detail.userInfo.avatarUrl,
  62. openid: this.data.openid,
  63. },
  64. success:res=>{
  65. console.log(res)
  66. this.setData({
  67. show:0
  68. })
  69. }
  70. })
  71. },
  72. getData:function(){
  73. wx.request({
  74. url: host +'/api/wx/index',
  75. method:'GET',
  76. success:res=>{
  77. wx.hideLoading()
  78. this.setData({
  79. data:res.data.data
  80. })
  81. }
  82. })
  83. }
  84. })