123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- // pages/publics/fileDetail/fileDetail.js
- import {
- imgUrl
- } from "../../api/request"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- // 图片前缀
- imgUrl: imgUrl,
- articles: '',
- fontSize: '中',
- isPlay: false
- },
- chooseFontSize(e) {
- let temp = this.data.articles;
- switch (this.data.fontSize) {
- case '大':
- temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span class="fontSizeMax"/gi, '<span"');
- break;
- case '中':
- temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span class="fontSize"/gi, '<span');
- break;
- case '小':
- temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span class="fontSizeSmall"/gi, '<span');
- break;
- }
- switch (e.currentTarget.dataset.size) {
- case '大':
- temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span/gi, '<span class="fontSizeMax"');
- break;
- case '中':
- temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span/gi, '<span class="fontSize"');
- break;
- case '小':
- temp.DOCHTMLCON = temp.DOCHTMLCON.replace(/\<span/gi, '<span class="fontSizeSmall"');
- break;
- }
- this.setData({
- fontSize: e.currentTarget.dataset.size,
- articles: temp
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- var chennelId = options.channelId
- var docId = options.docId
- var url = options.url
- wx.request({
- url: `https://data.cqna.gov.cn/mini/hlw/info?channelId=${chennelId}&docId=${docId}`,
- method: 'GET',
- success: res => {
-
- res.data.data.DOCPUBTIME = res.data.data.DOCPUBTIME.split(" ")[0];
- res.data.data.DOCHTMLCON = res.data.data.CONTENT.replace(/<img [^>]*src="([^'"]+)[^>]*>/gi,
- function (match, capture) {
- // 替换小图片地址
- // console.log(capture);
- if (capture.split("/").length > 1) {
- return match.replace(/src=['"]([^'"]+)[^>]/gi, 'src="' + 'https://www.cqna.gov.cn' +
- capture +
- '"');
- }
- return match.replace(/src=['"]([^'"]+)[^>]/gi, 'src="' + url +
- capture +
- '"');
- });
- // console.log(res.data.data.DOCHTMLCON);
- res.data.data.DOCHTMLCON = res.data.data.DOCHTMLCON.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/&nbsp;/g, ' ')
- .replace(/"/g, '\"');
- res.data.data.DOCHTMLCON = res.data.data.DOCHTMLCON.replace(/\<span/gi, '<span class="fontSize"');
- // console.log(res.data.data.DOCHTMLCON)
- this.setData({
- articles: res.data.data
- })
- }
- })
- },
- audioPlay() {
- if (!this.data.isPlay) {
- let that = this;
- that.innerAudioContext = wx.createInnerAudioContext({
- useWebAudioImplement: false
- })
- that.innerAudioContext.src = 'https://www.cqna.gov.cn/voice_assistant/2022-11-28/a05-60ff109e2a32_10281519.mp3';
- that.innerAudioContext.play()
- } else {
- this.innerAudioContext.pause();
- }
- this.setData({
- isPlay: !this.data.isPlay
- })
- },
- end() {
- if (this.innerAudioContext) {
- this.innerAudioContext.pause();
- }
- },
- onReady() {
- },
- onShow() {
- },
- onHide() {
- this.end(); //暂停音频
- },
- onUnload() {
- this.end(); //暂停音频
- },
- onPullDownRefresh() {
- },
- onReachBottom() {},
- onShareAppMessage() {
- return {
- title: this.data.articles.TITLE
- };
- }
- })
|