index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // miniprogram/pages/interList/interList.js
  2. const app = getApp();
  3. Page({
  4. oriList: [],
  5. pageSize: 20,
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. articleList: [],
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. const that = this;
  17. wx.setNavigationBarTitle({
  18. title: decodeURIComponent(options.title) || "列表"
  19. })
  20. wx.showLoading()
  21. const fs = wx.getFileSystemManager();
  22. wx.downloadFile({
  23. url: options.url,
  24. success: r => {
  25. fs.readFile({
  26. filePath: r.tempFilePath,
  27. encoding: 'utf8',
  28. position: 0,
  29. success(res) {
  30. that.oriList = res.data ? JSON.parse(res.data || '[]') : {};
  31. that.setData({
  32. articleList: that.oriList.splice(0, that.pageSize)
  33. })
  34. wx.hideLoading()
  35. },
  36. fail(res) {
  37. wx.hideLoading()
  38. }
  39. })
  40. },
  41. fail() {
  42. wx.hideLoading()
  43. }
  44. })
  45. },
  46. atBottom() {
  47. if (!this.oriList || !this.oriList.length) return;
  48. const list = this.data.articleList || [];
  49. list.push(...this.oriList.splice(0, this.pageSize))
  50. this.setData({
  51. articleList: list
  52. })
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面显示
  61. */
  62. onShow: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload: function () {
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh: function () {
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom: function () {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {
  88. }
  89. })