index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import wxParse from '../../wxParse/wxParse.js';
  2. import {
  3. getArticleDetails
  4. } from '../../api/api.js';
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. parameter: {
  12. 'navbar': '1',
  13. 'return': '1',
  14. 'title': '新闻详情',
  15. 'color': false
  16. },
  17. id: 0,
  18. articleInfo: [],
  19. store_info: {},
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. if (options.hasOwnProperty('id')) {
  26. this.setData({
  27. id: options.id
  28. });
  29. } else {
  30. wx.navigateBack({
  31. delta: 1
  32. });
  33. }
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. },
  40. /**
  41. * 生命周期函数--监听页面显示
  42. */
  43. onShow: function () {
  44. this.getArticleOne();
  45. },
  46. getArticleOne: function () {
  47. var that = this;
  48. getArticleDetails(that.data.id).then(res => {
  49. that.setData({
  50. 'parameter.title': res.data.title,
  51. articleInfo: res.data,
  52. store_info: res.data.store_info ? res.data.store_info : {}
  53. });
  54. //html转wxml
  55. wxParse.wxParse('content', 'html', res.data.content, that, 0);
  56. });
  57. },
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面卸载
  65. */
  66. onUnload: function () {
  67. },
  68. /**
  69. * 页面相关事件处理函数--监听用户下拉动作
  70. */
  71. onPullDownRefresh: function () {
  72. },
  73. /**
  74. * 页面上拉触底事件的处理函数
  75. */
  76. onReachBottom: function () {
  77. },
  78. /**
  79. * 用户点击右上角分享
  80. */
  81. onShareAppMessage: function () {
  82. return {
  83. title: this.data.parameter.title,
  84. path: '/pages/news_details/index?id=' + this.data.id,
  85. imageUrl: this.data.articleInfo.image_input.length ? this.data.articleInfo.image_input[0] : '',
  86. }
  87. }
  88. })