publicContent.js 2.8 KB

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