mine.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // loifn//index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. text: "This is page data.",
  7. windowHeight: app.globalData.windowHeight
  8. },
  9. onLoad: function (options) {
  10. var that = this;
  11. wx.login({
  12. success: function (res) {
  13. console.log(res.code)
  14. if (res.code) {
  15. //将保存在本地的用户名取出
  16. wx.getStorage({
  17. key: 'login',
  18. success(res) {
  19. //发起网络请求
  20. // 页面创建时执行
  21. wx.request({
  22. url: 'https://wx.yfzhwlw.com/wechat_user_info',
  23. header: {
  24. "Content-Type": "application/x-www-form-urlencoded"
  25. },
  26. method: "post",
  27. data: {
  28. req: "info",
  29. username: res.data
  30. },
  31. success: function (res) {
  32. if (res.statusCode != 200) {
  33. wx.showToast({ //这里提示失败原因
  34. title: res.data.message,
  35. icon: 'loading',
  36. duration: 1500
  37. })
  38. } else {
  39. wx.showToast({
  40. title: '登陆成功', //这里成功
  41. icon: 'success',
  42. duration: 1000
  43. });
  44. that.setData({
  45. isLogin: true,
  46. redata: res.data
  47. })
  48. }
  49. },
  50. fail: function (res) {
  51. console.log(res)
  52. wx.showToast({
  53. title: '请求失败',
  54. icon: 'none',
  55. duration: 1500
  56. })
  57. }
  58. });
  59. }
  60. })
  61. } else {
  62. console.log('登录失败!' + res.errMag)
  63. }
  64. }
  65. })
  66. },
  67. onShow: function () {
  68. // 页面出现在前台时执行
  69. },
  70. onReady: function () {
  71. // 页面首次渲染完毕时执行
  72. },
  73. onHide: function () {
  74. // 页面从前台变为后台时执行
  75. },
  76. onUnload: function () {
  77. // 页面销毁时执行
  78. },
  79. onPullDownRefresh: function () {
  80. // 触发下拉刷新时执行
  81. },
  82. onReachBottom: function () {
  83. // 页面触底时执行
  84. },
  85. onShareAppMessage: function () {
  86. // 页面被用户分享时执行
  87. },
  88. onPageScroll: function () {
  89. // 页面滚动时执行
  90. },
  91. onResize: function () {
  92. // 页面尺寸变化时执行
  93. },
  94. onTabItemTap(item) {
  95. // tab 点击时执行
  96. // console.log(item.index)
  97. // console.log(item.pagePath)
  98. // console.log(item.text)
  99. },
  100. // 事件响应函数
  101. viewTap: function () {
  102. this.setData({
  103. text: 'Set some data for updating view.'
  104. }, function () {
  105. // this is setData callback
  106. })
  107. },
  108. // 自由数据
  109. customData: {
  110. hi: 'MINA'
  111. },
  112. //点击退出登录
  113. outBtn: function () {
  114. wx.showModal({
  115. title: '提示',
  116. content: '是否退出当前账号',
  117. success(res) {
  118. if (res.confirm) {
  119. wx.removeStorage({
  120. key: 'login',
  121. success(res) {}
  122. })
  123. wx.reLaunch({
  124. url: '../login/login'
  125. })
  126. } else if (res.cancel) {
  127. console.log('用户点击取消')
  128. }
  129. }
  130. })
  131. }
  132. })