interList.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // miniprogram/pages/interList/interList.js
  2. const app = getApp();
  3. Page({
  4. active: 0,
  5. oriList: {},
  6. pageSize: 20,
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. newsListAll: {},
  12. tabList: [],
  13. mainHeight: 0,
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. const sys = wx.getSystemInfoSync();
  20. let list = app.globalData.origin.ArticlesOverview || [];
  21. this.getJSON(list[0].id);
  22. this.active = list[0].id;
  23. this.setData({
  24. tabList: app.globalData.origin.ArticlesOverview || [],
  25. mainHeight: sys.windowHeight - 60
  26. })
  27. },
  28. onChange(e) {
  29. let { id } = this.data.tabList[e.detail.index];
  30. this.active = id;
  31. !this.oriList[id] && this.getJSON(id);
  32. },
  33. atBottom() {
  34. this.oriList[this.active]
  35. let newsList = this.data.newsListAll || {};
  36. if (newsList[this.active]) {
  37. newsList[this.active].push(...this.oriList[this.active].splice(0, this.pageSize))
  38. } else
  39. newsList[this.active] = this.oriList[this.active].splice(0, this.pageSize);
  40. this.setData({
  41. newsListAll: newsList
  42. })
  43. },
  44. getJSON(id) {
  45. wx.showLoading();
  46. const that = this;
  47. const fs = wx.getFileSystemManager();
  48. wx.downloadFile({
  49. url: app.base.url + '/qf-platform/' + id + '.json',
  50. success(r) {
  51. fs.readFile({
  52. filePath: r.tempFilePath,
  53. encoding: 'utf8',
  54. position: 0,
  55. success(res) {
  56. let data = res.data ? JSON.parse(res.data) : {};
  57. that.oriList[id] = data || [];
  58. let newsList = that.data.newsListAll || {};
  59. newsList[id] = that.oriList[id].splice(0, that.pageSize);
  60. that.setData({
  61. newsListAll: newsList
  62. })
  63. },
  64. complete() {
  65. wx.hideLoading()
  66. }
  67. })
  68. },
  69. complete() {
  70. wx.hideLoading()
  71. }
  72. })
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面隐藏
  86. */
  87. onHide: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面卸载
  91. */
  92. onUnload: function () {
  93. },
  94. /**
  95. * 页面相关事件处理函数--监听用户下拉动作
  96. */
  97. onPullDownRefresh: function () {
  98. },
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom: function () {
  103. },
  104. /**
  105. * 用户点击右上角分享
  106. */
  107. onShareAppMessage: function () {
  108. },
  109. toDetail: function (e) {
  110. let title = e.currentTarget.dataset.title, newsUrl = e.currentTarget.dataset.newsurl;
  111. wx.navigateTo({
  112. url: '/pages/webView/index?title=' + title + "&newsUrl=" + newsUrl,
  113. })
  114. }
  115. })