fileDetail.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. if (capture.split("/").length > 1) {
  61. return match.replace(/src=['"]([^'"]+)[^>]/gi, 'src="' + 'https://www.cqna.gov.cn' +
  62. capture +
  63. '"');
  64. }
  65. return match.replace(/src=['"]([^'"]+)[^>]/gi, 'src="' + url +
  66. capture +
  67. '"');
  68. });
  69. res.data.data.DOCHTMLCON = res.data.data.CONTENT.replace(/\<span/gi, '<span class="fontSize"');
  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. })