tousudetail.vue 3.0 KB
<template>
	<view class="container">
		<view class="top">{{tousudetail.name}}</view>
		
		<view class="contentbox">
			<rich-text :nodes="content"></rich-text>
		</view>
		
	</view>
</template>

<script>
	import app from "../../App.vue";
	    export default {
	        data() {
	            return {
	                tousuid: "",
					tousudetail:'',
					content:''
	            }
	        },
	        onLoad(options) {
				console.log(options)
				this.tousuid=options.tousuid
				
				this.gettousudetail(this.tousuid)
	        },
	        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
				  },
	           gettousudetail(id){
				  let that = this;
				  var url = 'protect/get_detail';
				  var params = {
				  	protect_id:id,
				  	
				  }
				  
				  app.post(url, params, "post").then((res) => {
				  	console.log(res);
					that.tousudetail=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>