index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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:0,
  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. console.log(app.globalData.openid)
  57. wx.request({
  58. url: host+'/api/wx/auth',
  59. method:'POST',
  60. data:{
  61. nickname: e.detail.userInfo.nickName,
  62. avatar: e.detail.userInfo.avatarUrl,
  63. openid: app.globalData.openid,
  64. },
  65. success:res=>{
  66. console.log(res)
  67. this.setData({
  68. show:0
  69. })
  70. }
  71. })
  72. },
  73. getData:function(){
  74. wx.request({
  75. url: host +'/api/wx/index',
  76. method:'GET',
  77. success:res=>{
  78. wx.hideLoading()
  79. let data=res.data.data;
  80. this.setData({
  81. data:res.data.data
  82. })
  83. for(let i=0;i<data.length;i++){
  84. if(data[i].type=='notice'){
  85. this.setData({
  86. news:data[i].list
  87. })
  88. break;
  89. }
  90. }
  91. },
  92. fail:res=>{
  93. wx.showToast({
  94. title: '服务器开小差啦!',
  95. icon: 'none',
  96. duration: 2000
  97. })
  98. }
  99. })
  100. }
  101. })