fileDetail.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/publics/fileDetail/fileDetail.js
  2. import {
  3. imgUrl
  4. } from "../../api/request"
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. // 图片前缀
  11. imgUrl: imgUrl,
  12. articles: '',
  13. fontSize: '中',
  14. isPlay: false
  15. },
  16. chooseFontSize(e) {
  17. let temp = this.data.articles;
  18. switch (this.data.fontSize) {
  19. case '大':
  20. temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span class="fontSizeMax"/gi, '<span"');
  21. break;
  22. case '中':
  23. temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span class="fontSize"/gi, '<span');
  24. break;
  25. case '小':
  26. temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span class="fontSizeSmall"/gi, '<span');
  27. break;
  28. }
  29. switch (e.currentTarget.dataset.size) {
  30. case '大':
  31. temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span/gi, '<span class="fontSizeMax"');
  32. break;
  33. case '中':
  34. temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span/gi, '<span class="fontSize"');
  35. break;
  36. case '小':
  37. temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span/gi, '<span class="fontSizeSmall"');
  38. break;
  39. }
  40. this.setData({
  41. fontSize: e.currentTarget.dataset.size,
  42. articles: temp
  43. })
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad(options) {
  49. var chennelId = options.channelId
  50. var docId = options.docId
  51. var url = options.url
  52. wx.request({
  53. url: `https://data.cqna.gov.cn/mini/hlw/info?channelId=${chennelId}&docId=${docId}`,
  54. method: 'GET',
  55. success: res => {
  56. res.data.data.DOCPUBTIME = res.data.data.DOCPUBTIME.split(" ")[0];
  57. res.data.data.DOCHTMLCON = res.data.data.CONTENT.replace(/<img [^>]*src="([^'"]+)[^>]*>/gi,
  58. function (match, capture) {
  59. // 替换小图片地址
  60. // console.log(capture);
  61. if (capture.split("/").length > 1) {
  62. return match.replace(/src=['"]([^'"]+)[^>]/gi, 'src="' + 'https://www.cqna.gov.cn' +
  63. capture +
  64. '"');
  65. }
  66. return match.replace(/src=['"]([^'"]+)[^>]/gi, 'src="' + url +
  67. capture +
  68. '"');
  69. });
  70. // console.log(res.data.data.DOCHTMLCON);
  71. res.data.data.DOCHTMLCON = res.data.data.DOCHTMLCON.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ')
  72. .replace(/&lt;/g, '<')
  73. .replace(/&gt;/g, '>')
  74. .replace(/&amp;nbsp;/g, ' ')
  75. .replace(/&quot;/g, '\"');
  76. res.data.data.DOCHTMLCON = res.data.data.DOCHTMLCON.replace(/\<span/gi, '<span class="fontSize"');
  77. // console.log(res.data.data.DOCHTMLCON)
  78. this.setData({
  79. articles: res.data.data
  80. })
  81. }
  82. })
  83. },
  84. audioPlay() {
  85. if (!this.data.isPlay) {
  86. let that = this;
  87. that.innerAudioContext = wx.createInnerAudioContext({
  88. useWebAudioImplement: false
  89. })
  90. that.innerAudioContext.src = 'https://www.cqna.gov.cn/voice_assistant/2022-11-28/a05-60ff109e2a32_10281519.mp3';
  91. that.innerAudioContext.play()
  92. } else {
  93. this.innerAudioContext.pause();
  94. }
  95. this.setData({
  96. isPlay: !this.data.isPlay
  97. })
  98. },
  99. end() {
  100. if (this.innerAudioContext) {
  101. this.innerAudioContext.pause();
  102. }
  103. },
  104. onReady() {
  105. },
  106. onShow() {
  107. },
  108. onHide() {
  109. this.end(); //暂停音频
  110. },
  111. onUnload() {
  112. this.end(); //暂停音频
  113. },
  114. onPullDownRefresh() {
  115. },
  116. onReachBottom() {},
  117. onShareAppMessage() {
  118. return {
  119. title: this.data.articles.TITLE
  120. };
  121. }
  122. })