1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<template>
<div class="eContainer">
<div style="float:right;position:relative;z-index:99;display:inline-block;">
<el-button @click="print" style="margin-right:1em;" type="primary">打印</el-button>
</div>
<el-tabs type="card" v-model="tabName">
<el-tab-pane :label="`格式化文本`" :name="`format`" style="overflow:auto">
<div class="printEm" :ref="`formatDiv`" style="line-height:1.2em">
<table class="elc_view_table">
<colgroup>
<col style="width:43%"/>
<col style="width:2%"/>
<col style="width:55%"/>
</colgroup>
<tr :key="index" v-for="(tagDesp,index) in renderList">
<td>
<span v-html="tagDesp.tag"></span>
</td>
<td>:</td>
<td v-html="formatContent(tagDesp.value)">
</td>
</tr>
</table>
</div>
</el-tab-pane>
<el-tab-pane :label="`原报`" :name="`source`" style="overflow:auto">
<div :ref="`sourceDiv`" style="line-height:1.2em">
<pre >{{textContent}}</pre>
</div>
</el-tab-pane>
</el-tabs>
</div>
</template>
<script>
import * as ElcLabels from './ElcLabel'
import {MsgCodes} from "./MsgCodes"
import Api from "~/service/Api";
//8个不予展示的字段
const displayArr = ["OrigSender", "OrigReceiver", "OrigSendDate", "OrigSendTime", "MesgType", "MesgRefID", "MesgID", "MesgDirection", "OrigSenderSID", "OrigReceiverSID", "FilePath"]
export default {
props:["formatData", "textContent"],
data(){
return {
tabName: "format",
tagDespList:[]
}
},
methods:{
base64ToBlob(code) {
code = code.replace(/[\n\r]/g, "");
const raw = window.atob(code);
const rawLength = raw.length;
const uInt8Array = new Uint8Array(rawLength);
for (let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], { type: "application/pdf" });
},
async print() {
let res = null;
if (this.tabName === "format") {
res = await Api.post(`/public/quesel/getPdf`, {
format: "elc",
formatData: this.tagDespList
});
} else if (this.tabName === "source") {
res = await Api.post(`/public/quesel/getPdf`, {
format: "source",
data: this.textContent
});
}
if (res != null && res.respCode === SUCCESS) {
let blob = this.base64ToBlob(res.data.data);
const fileURL = URL.createObjectURL(blob);
let iframe = document.createElement("iframe");
iframe.id = this.tabName;
iframe.src = fileURL;
iframe.type = "application/pdf";
iframe.style.display = "inline-block";
iframe.style.width = "1px";
iframe.style.height = "1px";
iframe.style.position = "absolute";
iframe.style.top = "-100px";
iframe.onload = function() {
iframe.contentWindow.print();
};
document.body.appendChild(iframe);
} else {
this.$notify.warning({
title: "提示",
message: "打印调起失败!"
});
}
},
getLabels(mty) {
return ElcLabels[mty]
},
output(msg, ellist, mty_labels){
Object.keys(msg).forEach(key=>{
if(displayArr.includes(key)){
return
}
let value = msg[key]
let label = mty_labels[key] || value.label || key
let srcValue = value.value
//转换码表
if(value.typeCode && value.kind === 0){
if(MsgCodes[value.typeCode]){
let codes = MsgCodes[value.typeCode]
let code = codes.find(item=>item.id == value.value);
if(code &&code.text != value.value){
srcValue = value.value + " :"+code.text
}else{
srcValue = value.value
}
}
}
ellist.push({tag:label,value:srcValue})
})
// if(msg.OrigSender && msg.OrigSender.value){
// ellist.push({tag:"报文发起人",value:msg.OrigSender.value});
// }
// if(msg.OrigReceiver && msg.OrigReceiver.value){
// ellist.push({tag:"报文接收人",value:msg.OrigReceiver.value});
// }
// if(msg.OrigSendDate && msg.OrigSendDate.value){
// ellist.push({tag:"报文发起日期",value:msg.OrigSendDate.value});
// }
// if(msg.OrigSendTime && msg.OrigSendTime.value){
// ellist.push({tag:"报文发起时间",value:msg.OrigSendTime.value});
// }
if(msg.MesgType && msg.MesgType.value){
let elcmty = msg.MesgType.value
let elcitem = MsgCodes.regmsgtype.find(item=>item.id == elcmty)
if(elcitem){
elcmty = elcitem.text
}
ellist.splice(9,0,{tag:"报文类型",value:msg.MesgType.value + " " +elcmty});
}
// if(msg.MesgID && msg.MesgID.value){
// ellist.push({tag:"通信级标识号",value:msg.MesgID.value});
// }
// if(msg.MesgRefID && msg.MesgRefID.value){
// ellist.push({tag:"通信级参考号",value:msg.MesgRefID.value});
// }
// if(msg.MesgDirection && msg.MesgDirection.value){
// ellist.push({tag:"报文传输方向",value:msg.MesgDirection.value});
// }
},
formatContent(content){
return '<p>'+(content || ' ').replace(/\r?\n/g,'</p><p>')+'</p>'
},
},
computed:{
noPrint(){
return this.$store.state.Status.mode === "display" && this.$route.query.noPrint == 'Y'
},
renderList(){
let msg = this.formatData
let mty = msg.MesgType.value
let ellist = []
this.tagDespList=[]
if (mty) {
mty = mty.charAt(0).toUpperCase() + mty.substring(1).replace(/\./g, '_')
}
if (!msg)
return []
const mty_labels = this.getLabels(mty)
this.output(msg, ellist, mty_labels)
this.tagDespList=ellist
return ellist
}
}
}
</script>
<style lang="less">
.elc_view_table{
width: 80%;
table-layout: fixed;
margin-left: 10%;
margin-top: 1em;
font-size: 16px;
line-height: 1.2em;
font-family: '宋体';
color: black;
tr{
vertical-align: top;
}
td{
word-break: break-all;
padding: 0.1rem 1rem;
}
}
</style>