yjzjDetail.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // pages/yjzjDetail/yjzjDetail.js
  2. import {
  3. yjzjList
  4. } from "../api/index-api"
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. html: '',
  11. title: ''
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad(options) {
  17. let title = options.title
  18. let list = wx.getStorageSync('yjzjDataList')
  19. if(list==null){
  20. yjzjList().then(res => {
  21. var list = []
  22. if (res.statusCode == 200 && res.datas.pageInfo.totalResults > 0) {
  23. list = res.datas.data
  24. for (var i = 0; i < list.length; i++) {
  25. list[i].beginTime = this.formatDateNumber(new Date(list[i].beginTime * 1))
  26. list[i].endTime = this.formatDateNumber(new Date(list[i].endTime * 1))
  27. }
  28. wx.setStorageSync('yjzjDataList', list)
  29. }
  30. })
  31. list = wx.getStorageSync('yjzjDataList')
  32. }
  33. let html
  34. list.forEach(item => {
  35. if (item.id == title) {
  36. html = item.htmlContent
  37. title = item.theme
  38. }
  39. })
  40. wx.setNavigationBarTitle({
  41. title: title
  42. })
  43. // console.log(options);
  44. // var html = decodeURIComponent(options.html)
  45. // console.log(html);
  46. let str_replace = function (search, replace, subject) {
  47. return subject.split(search).join(replace);
  48. }
  49. html = str_replace('/IGI/upload/file', 'https://www.cqna.gov.cn/IGI/upload/file', html);
  50. html = str_replace("<img", "<img style='max-width:100%;height:auto;'", html);
  51. this.setData({
  52. 'html': html,
  53. title: title
  54. })
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady() {
  60. },
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow() {
  65. },
  66. /**
  67. * 生命周期函数--监听页面隐藏
  68. */
  69. onHide() {
  70. },
  71. /**
  72. * 生命周期函数--监听页面卸载
  73. */
  74. onUnload() {
  75. },
  76. /**
  77. * 页面相关事件处理函数--监听用户下拉动作
  78. */
  79. onPullDownRefresh() {
  80. },
  81. /**
  82. * 页面上拉触底事件的处理函数
  83. */
  84. onReachBottom() {
  85. },
  86. /**
  87. * 用户点击右上角分享
  88. */
  89. onShareAppMessage() {
  90. return {
  91. title: this.data.title
  92. };
  93. },
  94. onShareTimeline(){
  95. return {
  96. title: this.data.title
  97. }
  98. }
  99. })