index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // pages/problemPage/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. Page: 1,
  8. Size: 5,
  9. isMore: true,
  10. data: {
  11. question: [],
  12. showEnd: false
  13. },
  14. tonext(e) {
  15. app.globalData.selectQuestion = this.data.question[e.currentTarget.dataset.i] || { list: [] };
  16. if(app.globalData.selectQuestion.type != 'questionBank'){
  17. wx.navigateTo({
  18. url: '/pages/detail/index',
  19. })
  20. return
  21. }
  22. if (!app.globalData.userInfo || !app.globalData.userInfo.phone) wx.navigateTo({
  23. url: '/pages/index/index',
  24. })
  25. else {
  26. wx.navigateTo({
  27. url: '/pages/answerInfo/index',
  28. })
  29. }
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. this.getData();
  36. },
  37. getData() {
  38. const that = this;
  39. wx.cloud.callFunction({
  40. name: "quickstartFunctions",
  41. data: {
  42. type: "questionBankList",
  43. data: {
  44. Page: that.Page,
  45. Size: that.Size
  46. }
  47. }
  48. }).then(res => {
  49. wx.hideLoading();
  50. if (res.result.code !== 0) return;
  51. let li = that.data.question || [];
  52. let newli = res.result.data.list || [];
  53. if(!newli.length) that.isMore = false;
  54. li = [...li, ...newli]
  55. that.setData({
  56. question: li,
  57. showEnd: res.result.data.total <= that.Page * that.Size
  58. })
  59. }).catch(err => {
  60. wx.hideLoading({
  61. success: (res) => {
  62. wx.showToast({
  63. title: '服务走丢了~',
  64. icon: "none"
  65. })
  66. },
  67. })
  68. })
  69. },
  70. /**
  71. * 生命周期函数--监听页面初次渲染完成
  72. */
  73. onReady: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面显示
  77. */
  78. onShow: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function () {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function () {
  99. // 添加数据
  100. if(!this.isMore) return
  101. this.Page++;
  102. this.getData()
  103. },
  104. /**
  105. * 用户点击右上角分享
  106. */
  107. onShareAppMessage: function () {
  108. }
  109. })