btnAuth.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const util = require('../../../utils/util.js');
  2. const api = require('../../../config/api.js');
  3. const user = require('../../../services/user.js');
  4. //获取应用实例
  5. const app = getApp()
  6. Page({
  7. data: {
  8. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  9. navUrl: ''
  10. },
  11. onLoad: function (options) {
  12. let that = this;
  13. if (wx.getStorageSync("navUrl")) {
  14. that.setData(
  15. {
  16. navUrl: wx.getStorageSync("navUrl")
  17. }
  18. )
  19. }else{
  20. that.setData(
  21. {
  22. navUrl: '/pages/index/index'
  23. }
  24. )
  25. }
  26. },
  27. bindGetUserInfo: function (e) {
  28. let that = this;
  29. console.log(e.detail.userInfo)
  30. console.log(this.data.navUrl)
  31. user.loginByWeixin();
  32. if (that.data.navUrl && that.data.navUrl == '/pages/index/index') {
  33. wx.switchTab({
  34. url: that.data.navUrl,
  35. })
  36. } else if (that.data.navUrl) {
  37. wx.redirectTo({
  38. url: that.data.navUrl,
  39. })
  40. }
  41. },
  42. onReady: function () {
  43. // 页面渲染完成
  44. },
  45. onShow: function () {
  46. // 页面显示
  47. },
  48. onHide: function () {
  49. // 页面隐藏
  50. },
  51. onUnload: function () {
  52. // 页面关闭
  53. }
  54. })