loading.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // pages/load/load.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. logo: '',
  9. name: '',
  10. url: app.globalData.url,
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. var that = this;
  17. app.setBarColor();
  18. if (options.scene) app.globalData.spid = options.scene;
  19. that.setSetting();
  20. },
  21. setSetting: function () {
  22. var that = this;
  23. wx.getSetting({
  24. success(res) {
  25. if (!res.authSetting['scope.userInfo']){
  26. wx.navigateTo({
  27. url: '/pages/load/load',
  28. })
  29. }else{
  30. that.getUserInfo();
  31. }
  32. }
  33. })
  34. },
  35. getUserInfo: function () {
  36. var that = this;
  37. wx.getUserInfo({
  38. lang: 'zh_CN',
  39. success: function (res) {
  40. var userInfo = res.userInfo
  41. wx.login({
  42. success: function (res) {
  43. if (res.code) {
  44. userInfo.code = res.code;
  45. userInfo.spid = app.globalData.spid;
  46. wx.request({
  47. url: app.globalData.url + '/routine/login/index',
  48. method: 'post',
  49. dataType  : 'json',
  50. data: {
  51. info: userInfo
  52. },
  53. success: function (res) {
  54. app.globalData.uid = res.data.data.uid;
  55. if (app.globalData.openPages != '' && app.globalData.openPages != undefined) {//跳转到指定页面
  56. wx.navigateTo({
  57. url: app.globalData.openPages
  58. })
  59. } else {//跳转到首页
  60. wx.reLaunch({
  61. url: '/pages/index/index'
  62. })
  63. }
  64. },
  65. })
  66. } else {
  67. console.log('登录失败!' + res.errMsg)
  68. }
  69. },
  70. fail: function () {
  71. },
  72. })
  73. },
  74. fail: function () {
  75. },
  76. })
  77. },
  78. /**
  79. * 生命周期函数--监听页面显示
  80. */
  81. onShow: function () {
  82. },
  83. })