zhongmianzixundetail.vue 3.2 KB
<template>
	<view class="container">
		<view class="top">{{zixundetail.name}}</view>
		<view class='flexone datebox'>
			<view class="botleft">{{zixundetail.author}}</view>
			<view class="botright">{{zixundetail.publishtime}}</view>
		</view>
		<view class="contentbox">
			<rich-text :nodes="content"></rich-text>
		</view>
		
	</view>
</template>

<script>
	import app from "../../App.vue";
	    export default {
	        data() {
	            return {
	                zixunid: "",
					zixundetail:'',
					content:''
	            }
	        },
	        onLoad(options) {
				console.log(options)
				this.zixunid=options.zixunid
				console.log(this.zixunid)
				this.getzixundetail(this.zixunid)
	        },
	        methods: {
				
				 text(details) {
				
				    var texts = '';//待拼接的内容
				
				    while (details.indexOf('<img') != -1) {//寻找img 循环
				
				      texts += details.substring('0', details.indexOf('<img') + 4);//截取到<img前面的内容
				
				      details = details.substring(details.indexOf('<img') + 4);//<img 后面的内容
				
				      if (details.indexOf('style=') != -1 && details.indexOf('style=') < details.indexOf('>')) {
				
				        texts += details.substring(0, details.indexOf('style="') + 7) + "max-width:100%;height:auto;margin:0 auto;";//从 <img 后面的内容 截取到style= 加上自己要加的内容
				
				        details = details.substring(details.indexOf('style="') + 7); //style后面的内容拼接
				
				      } else {
				
				        texts += ' style="max-width:100%;height:auto;margin:0 auto;" ';
				
				      }
				    }
				  
				   while (details.indexOf('<td') != -1) {//寻找img 循环
				
				     texts += details.substring('0', details.indexOf('<td') + 4);//截取到<img前面的内容
				
				     details = details.substring(details.indexOf('<td') + 4);//<img 后面的内容
				
				     if (details.indexOf('style=') != -1 && details.indexOf('style=') < details.indexOf('>')) {
				
				       texts += details.substring(0, details.indexOf('style="') + 7) + "max-width:74!important;height:auto;margin:0 auto;";//从 <img 后面的内容 截取到style= 加上自己要加的内容
				
				       details = details.substring(details.indexOf('style="') + 7); //style后面的内容拼接
				
				     } else {
				
				       texts += ' style="max-width:100%;height:auto;margin:0 auto;" ';
				
				     }
				   }
				    texts += details;//最后拼接的内容
				    return texts
				  },
	           getzixundetail(id){
				  let that = this;
				  var url = 'article/get_detail';
				  var params = {
				  	new_id:id,
				  	
				  }
				  
				  app.post(url, params, "post").then((res) => {
				  	console.log(res);
					that.zixundetail=res.data.data;
					this.content=this.text(res.data.data.content)
				  
				  }).catch((err) => {
				  	console.log(err)
				  
				  }) 
			   }
	      
	        }
	
	    }
</script>

<style>
	.datebox{
		margin-top:20rpx
	}
	.container{
		padding: 32rpx;
		box-sizing: border-box;
	}
	.top {
	font-size: 32rpx;
	font-weight: bold;
	
	
	}
	.botleft {
			color: #C29445;
			font-size: 24rpx;
	
	}
	.botright {
		color: #8c9198;
		font-size: 24rpx;
		margin-left: 24rpx;
	}
	.contentbox{
		margin-top:20rpx
	}
</style>