question.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // pages/question/question.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../utils/util.js'
  3. import { GetQuestion } from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. isLoaded: 0,
  13. title: '',
  14. pageSize: 10,
  15. pageNo: 1,
  16. stat: 2,
  17. type: 1,
  18. list: []
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. let stat = 0
  25. if (options.type == 1) {
  26. stat = 2
  27. } else if (options.type == 2) {
  28. stat = 6
  29. }
  30. this.setData({ options, stat })
  31. this.getList(res => {
  32. this.setData({ isLoaded: 1 })
  33. })
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  40. for (const i in obj) {
  41. this[i] = obj[i]
  42. }
  43. },
  44. /**
  45. * 生命周期函数--监听页面显示
  46. */
  47. onShow: function () {
  48. },
  49. /**
  50. * 生命周期函数--监听页面隐藏
  51. */
  52. onHide: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面卸载
  56. */
  57. onUnload: function () {
  58. },
  59. /**
  60. * 页面相关事件处理函数--监听用户下拉动作
  61. */
  62. onPullDownRefresh: function () {
  63. },
  64. /**
  65. * 页面上拉触底事件的处理函数
  66. */
  67. onReachBottom: function () {
  68. },
  69. /**
  70. * 用户点击右上角分享
  71. */
  72. onShareAppMessage: function () {
  73. if (isFn(sharePage)) return sharePage()
  74. },
  75. /**
  76. * 获取列表
  77. */
  78. getList: function (cb) {
  79. const continuousFn = { fn: this.getList, param: { ...arguments } }
  80. const { title, pageSize, pageNo, stat, type } = this.data
  81. GetQuestion({ data: { title, pageSize, pageNo, stat, type }, continuousFn }).then(res => {
  82. const { list } = res.data
  83. this.setData({ list })
  84. cb && cb(res)
  85. }).catch(res => {
  86. cb && cb(res)
  87. })
  88. }
  89. })