123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- // pages/detail/detail.js
- // 29014
- const $api = require('../../utils/api.js').API;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- name:'',
- articleid:'',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if(options.type == '百科'){
- $api.getBaikeDetail({category_id:options.id}).then(res=>{
- let data = res.data.data
- data.content = data.content.replaceAll('<img', '<img class="rich-img"')
- data.content = data.content.replace(/style="[^"]+"/gi, "")
- .replace(/style='[^']+'/gi, "") //小程序展示要自己统一的样式,替换了行内样式
- .replace(/(<!--(.|[\r\n])*?-->)/gi, "") //替换了注释的内容这能替掉大部分
- .replace(/<xml[^>]*>(.|\n)*<\/xml>/gi, "") //替换了xml标签<xml></xml>word粘贴带出一堆标签包含在xml里
- .replace(/undefined/gi, "") //里面莫名有个undefined
- this.setData({
- info:data,
- name:res.data.data.name,
- articleid:options.id,
- })
- this.data.info.content = this.data.info.content.replace('<img', '<img class="rich-img"')
- wx.setNavigationBarTitle({
- title: res.data.data.name,
- })
- })
- return
- }
- $api.getArticle({id:options.id}).then(res=>{
- let data = res.data.data
- data.content = data.content.replaceAll('<img', '<img class="rich-img"')
- this.setData({
- info:data,
- name:res.data.data.name,
- articleid:options.id,
- })
- console.log(data)
- this.data.info.content = this.data.info.content.replace('<img', '<img class="rich-img"')
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- // const promise = new Promise(resolve => {
- // setTimeout(() => {
- // resolve({
- // title: this.data.name
- // })
- // }, 2000)
- // }),
- return{
- title:this.data.name,
- path:'/pages/detail/detail?id=' + this.data.articleid
- }
- },
- // onShareTimeline: function() {
- // return {
- // title: this.data.name,
- // query: {'id':this.data.articleid}
- // }
- // }
- })
|