index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // miniprogram/pages/home/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. newList: []
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function (options) {
  14. let url = app.base.url + '/t.json?time=' + (new Date());
  15. // if(wx.getSystemInfoSync().platform === "devtools") url = app.base.url + '/t_dev.json?time=' + (new Date())
  16. wx.showLoading()
  17. const fs = wx.getFileSystemManager();
  18. wx.downloadFile({
  19. url,
  20. success: r => {
  21. fs.readFile({
  22. filePath: r.tempFilePath,
  23. encoding: 'utf8',
  24. position: 0,
  25. success(res) {
  26. let D = res.data;
  27. if(/xml/g.test(D)) {
  28. D = '{}'
  29. }
  30. let data = res.data ? JSON.parse(D) : {};
  31. app.globalData.origin = data;
  32. wx.hideLoading()
  33. },
  34. fail(res) {
  35. wx.hideLoading()
  36. }
  37. })
  38. },
  39. fail() {
  40. wx.hideLoading()
  41. }
  42. })
  43. },
  44. /**
  45. * 生命周期函数--监听页面初次渲染完成
  46. */
  47. onReady: function () {
  48. },
  49. /**
  50. * 生命周期函数--监听页面显示
  51. */
  52. onShow: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面隐藏
  56. */
  57. onHide: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面卸载
  61. */
  62. onUnload: function () {
  63. },
  64. /**
  65. * 页面相关事件处理函数--监听用户下拉动作
  66. */
  67. onPullDownRefresh: function () {
  68. },
  69. /**
  70. * 页面上拉触底事件的处理函数
  71. */
  72. onReachBottom: function () {
  73. },
  74. /**
  75. * 用户点击右上角分享
  76. */
  77. onShareAppMessage: function () {
  78. },
  79. toDetail: function (e) {
  80. let data = e.currentTarget.dataset || {};
  81. wx.navigateTo({
  82. url: '/pages/detail/detail?title=' + data.title + "&key=" + data.key + "&type=" + data.type,
  83. })
  84. },
  85. toMarvellous: function (e) {
  86. wx.navigateTo({
  87. url: '/pages/marvellous/index?title=' + e.currentTarget.dataset.title + "&type=" + e.currentTarget.dataset.type,
  88. })
  89. }
  90. })