index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. },
  12. //事件处理函数
  13. bindViewTap: function() {
  14. wx.navigateTo({
  15. url: '../logs/logs'
  16. })
  17. },
  18. tabchange:function(e){
  19. this.setData({
  20. act: e.target.dataset.id
  21. })
  22. },
  23. onLoad: function () {
  24. this.getData()
  25. this.setData({
  26. openid: app.globalData.openid
  27. })
  28. wx.getStorage({
  29. key: 'userInfo',
  30. success: res=> {
  31. if(res.data){
  32. this.setData({show:0})
  33. }
  34. },
  35. })
  36. },
  37. onGotUserInfo: function (e) {
  38. wx.setStorage({
  39. key: 'userInfo',
  40. data: e.detail.userInfo,
  41. })
  42. wx.request({
  43. url: host+'/api/wx/authinfo',
  44. method:'POST',
  45. data:{
  46. nickname: e.detail.userInfo.nickName,
  47. avatar: e.detail.userInfo.avatarUrl,
  48. openid: this.data.openid,
  49. },
  50. success:res=>{
  51. console.log(res)
  52. this.setData({
  53. show:0
  54. })
  55. }
  56. })
  57. },
  58. getData:function(){
  59. wx.request({
  60. url: host +'/api/wx/index',
  61. method:'GET',
  62. success:res=>{
  63. console.log(res.data)
  64. this.setData({
  65. data:res.data.data
  66. })
  67. }
  68. })
  69. }
  70. })