22 <el-dialog
33 :title =" isOutputXml ? '数据导出':'数据导入'"
44 :visible.sync =" centerDialogVisible"
5- width =" 70%"
5+ width =" 70%; "
66 center
77 @close =" close"
88 >
3030 </div >
3131 </el-upload >
3232 <!-- codemirror插件-->
33- <codemirror
34- :value =" currentNodeData"
35- v-model =" currentNodeData"
36- :options =" options"
37- class =" codemirror"
38- ></codemirror >
33+ <div style =" display :flex " >
34+ <codemirror
35+ :value =" currentNodeData"
36+ v-model =" currentNodeData"
37+ :options =" options"
38+ :style =" {'width': isOutputXml ? '50%':'100%'}"
39+ class =" codemirror"
40+ ></codemirror >
41+ <!-- xml转json -->
42+ <json-viewer
43+ v-if =" isOutputXml"
44+ class =" xmlToJson"
45+ :value =" xml2json"
46+ :expand-depth =" 5"
47+ copyable
48+ sort
49+ ></json-viewer >
50+ </div >
3951 <span slot =" footer" class =" dialog-footer" >
4052 <el-button @click =" cancelUpload" >取 消</el-button >
4153 <el-button type =" primary" @click =" confirmUpload" v-if =" !isOutputXml" >导入</el-button >
@@ -69,11 +81,13 @@ import 'codemirror/addon/fold/foldcode'
6981import ' codemirror/addon/fold/foldgutter'
7082import ' codemirror/addon/fold/brace-fold'
7183import ' codemirror/addon/fold/comment-fold'
84+ import X2JS from ' ../x2js'
7285
7386export default {
7487 props: [' graphXml' , ' isOutputXml' ],
7588 data () {
7689 return {
90+ xml2json: ' ' ,
7791 uploadFiles: [],
7892 centerDialogVisible: false ,
7993 currentNodeData: " " ,
@@ -99,7 +113,11 @@ export default {
99113 watch: {
100114 currentNodeData: {
101115 handler (newvalue ) {
102- this .currentNodeData = newvalue
116+ // let xmljson = x2js.xml2js(newvalue) //xml2js方法,传入xml格式的数据,返回json对象
117+ // 创建一个x2js对象进行转换
118+ var x2js = new X2JS ();
119+ this .xml2json = x2js .xml_str2json (newvalue);
120+ // this.currentNodeData = newvalue
103121 },
104122 immediate: true ,
105123 deep: true
@@ -110,6 +128,7 @@ export default {
110128 this .currentNodeData = this .graphXml
111129 },
112130 methods: {
131+
113132 close () {
114133 this .centerDialogVisible = false
115134 this .$parent .uploadDataVisible = false ;
@@ -189,4 +208,15 @@ export default {
189208 left : 10px ;
190209 content : " 数据预览 :" ;
191210}
211+ .xmlToJson {
212+ width : 50% ;
213+ height : 100% ;
214+ }
215+ .xmlToJson ::before {
216+ position : absolute ;
217+ font-size : 17px ;
218+ top : 0px ;
219+ left : 10px ;
220+ content : " XML转JSON :" ;
221+ }
192222 </style >
0 commit comments