index.js 1.8 KB

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