index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // index.js
  2. var app = getApp();
  3. Page({
  4. data:{
  5. loading: true,
  6. src: "",
  7. msg: ""
  8. },
  9. onLoad:function(options){
  10. console.log(1111111111,encodeURIComponent("org_3"));
  11. app.getScene(options);
  12. var userId = wx.getStorageSync("userId");
  13. var token = wx.getStorageSync("token");
  14. if (!userId || token) { //未登录
  15. this.autologin();
  16. }else{
  17. this.setData({
  18. src: app.globalData.h5Url + "/#/pages/index/index?"+app.getCommonParam()
  19. })
  20. console.log(this.data.src);
  21. }
  22. },
  23. onShow: function () {
  24. var that = this;
  25. app.ajaxReadyCallback = res => { //各个接口统一回调方法
  26. var apiname = res.data.apiname;
  27. if(apiname == 'icon'){
  28. }
  29. }
  30. },
  31. autologin(){
  32. let that = this;
  33. wx.login({
  34. success: function (ret) {
  35. wx.showLoading({
  36. title: '加载中',
  37. mask: true
  38. });
  39. wx.request({
  40. url: app.globalData.serverUrl + 'Oauth/checkCode',
  41. data: {
  42. type: 2,
  43. code: ret.code,
  44. },
  45. method: 'POST',
  46. header: {
  47. 'content-type': 'application/x-www-form-urlencoded'
  48. },
  49. success: function (res) {
  50. wx.hideLoading();
  51. if (res.data.code == 0) {
  52. try {
  53. app.logout();
  54. wx.setStorageSync("userId", res.data.data.userId);
  55. wx.setStorageSync("token", res.data.data.token);
  56. } catch (e) { };
  57. var userinfo = {
  58. userId: res.data.data.userId,
  59. token: res.data.data.token,
  60. };
  61. app.globalData.userinfo = userinfo;
  62. that.setData({
  63. src: app.globalData.h5Url + "/#/pages/index/index?"+app.getCommonParam()
  64. })
  65. console.log(that.data.src);
  66. }else{
  67. wx.showModal({
  68. title: '提示',
  69. content: res.data.message,
  70. showCancel: false
  71. })
  72. }
  73. },
  74. fail:function(e){
  75. wx.hideLoading();
  76. wx.showModal({
  77. title: '提示',
  78. content: '登录失败,请重试',
  79. showCancel: false
  80. })
  81. }
  82. })
  83. },
  84. fail:function(e){
  85. wx.hideLoading();
  86. wx.showModal({
  87. title: '提示',
  88. content: '登录失败,请重试',
  89. showCancel: false
  90. })
  91. }
  92. });
  93. }
  94. })