Commit 467cf56d by 1377875331@qq.com

面函xml格式显示

parent 9ffa5e63
......@@ -345,8 +345,8 @@ export default {
// let url = rtnmsg.data.trnmod_trndoc_smh_docpth;
this.title = "面函"
let viewurl = "/#/docpan/show";
viewurl += "?model="+rtnmsg.data.litbenl1blk;
console.log(viewurl)
var newXml = Utils.showXml(rtnmsg.data.litbenl1blk)
window.sessionStorage.docXML = newXml;
window.open(viewurl, 'newwindow', 'height=1200,width=800,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
}
this.dialogOpen=true
......
......@@ -60,4 +60,85 @@ export default class Utils {
}
return target;
}
static showXml(str){
var text = str
//去掉多余的空格
text = '\n' + text.replace(/(<\w+)(\s.*?>)/g,function($0, name, props)
{
return name + ' ' + props.replace(/\s+(\w+=)/g," $1");
}).replace(/>\s*?</g,">\n<");
//把注释编码
text = text.replace(/\n/g,'\r').replace(/<!--(.+?)-->/g,function($0, text)
{
var ret = '<!--' + escape(text) + '-->';
return ret;
}).replace(/\r/g,'\n');
//调整格式
var rgx = /\n(<(([^\?]).+?)(?:\s|\s*?>|\s*?(\/)>)(?:.*?(?:(?:(\/)>)|(?:<(\/)\2>)))?)/mg;
var nodeStack = [];
var output = text.replace(rgx,function($0,all,name,isBegin,isCloseFull1,isCloseFull2 ,isFull1,isFull2){
var isClosed = (isCloseFull1 == '/') || (isCloseFull2 == '/' ) || (isFull1 == '/') || (isFull2 == '/');
var prefix = '';
if(isBegin == '!')
{
prefix = Utils.getPrefix(nodeStack.length);
}
else
{
if(isBegin != '/')
{
prefix = Utils.getPrefix(nodeStack.length);
if(!isClosed)
{
nodeStack.push(name);
}
}
else
{
nodeStack.pop();
prefix = Utils.getPrefix(nodeStack.length);
}
}
var ret = '\n' + prefix + all;
return ret;
});
var prefixSpace = -1;
var outputText = output.substring(1);
//把注释还原并解码,调格式
outputText = outputText.replace(/\n/g,'\r').replace(/(\s*)<!--(.+?)-->/g,function($0, prefix, text)
{
if(prefix.charAt(0) == '\r')
prefix = prefix.substring(1);
text = unescape(text).replace(/\r/g,'\n');
var ret = '\n' + prefix + '<!--' + text.replace(/^\s*/mg, prefix ) + '-->';
return ret;
});
//alert(outputText);
outputText= outputText.replace(/\s+$/g,'').replace(/\r/g,'\r\n');
return outputText
}
static getPrefix(prefixIndex)
{
var span = ' ';
var output = [];
for(var i = 0 ; i < prefixIndex; ++i)
{
output.push(span);
}
return output.join('');
}
}
\ No newline at end of file
<template>
<div>
<div class="title">面函列表</div>
<div>
<c-input
type="textarea"
:autosize="{ minRows: 16}"
placeholder="请输入原因"
v-model="model">
</c-input>
<div style="height:1000px;width:900px;overflow:auto">
<pre>
{{model.docXML}}
</pre>
</div>
</div>
</template>
......@@ -19,12 +16,12 @@ import Utils from "~/utils"
export default {
data(){
return {
model: this.$route.query.model,
model: {docXML:""},
}
},
mounted() {
console.log(this.$router);
}
this.model.docXML = window.sessionStorage.docXML
}
}
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment