startClass.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const app = require('../../utils/util.js');
  2. Page({
  3. data: {
  4. dataArr: []
  5. },
  6. getjj(sessionKey) {
  7. var _this = this;
  8. wx.request({
  9. url: app.globalData.publicUrl2 + '/education/student/wx/selClas',
  10. method: "post",
  11. data: {
  12. sessionKey: sessionKey,
  13. isActive: "0"
  14. },
  15. success: function (res) {
  16. console.log(res.data.data.length, "我是即将开班的列表")
  17. _this.setData({
  18. dataArr: res.data.data
  19. })
  20. }
  21. })
  22. },
  23. onLoad: function () {
  24. var _this = this;
  25. wx.checkSession({
  26. success: () => {
  27. console.log("我有缓存")
  28. var sessionKey = wx.getStorageSync('sessionKey');
  29. if (sessionKey == "") {
  30. wx.login({
  31. success(res) {
  32. console.log(res);
  33. var code = res.code
  34. wx.request({
  35. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  36. method: "get",
  37. data: {
  38. code
  39. },
  40. success: function (res) {
  41. sessionKey = res.data.sessionKey;
  42. wx.setStorageSync('sessionKey', res.data.sessionKey);
  43. _this.getjj(sessionKey);
  44. }
  45. })
  46. }
  47. })
  48. } else {
  49. _this.getjj(sessionKey);
  50. }
  51. },
  52. fail() {
  53. console.log("我没有缓存并去登录请求")
  54. wx.login({
  55. success(res) {
  56. console.log(res);
  57. var code = res.code
  58. wx.request({
  59. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  60. method: "get",
  61. data: {
  62. code
  63. },
  64. success: function (res) {
  65. wx.setStorageSync('sessionKey', res.data.sessionKey);
  66. var sessionKey = res.data.sessionKey
  67. this.getjj(sessionKey);
  68. }
  69. })
  70. }
  71. })
  72. }
  73. })
  74. }
  75. })