Ver código fonte

指令配置 XML 导入导出

wanggaokun 1 ano atrás
pai
commit
9691bde536

+ 1 - 1
PHM-web/package.json

@@ -39,7 +39,7 @@
     "@riophae/vue-treeselect": "0.4.0",
     "axios": "0.24.0",
     "clipboard": "2.0.8",
-    "core-js": "3.25.3",
+    "core-js": "^3.34.0",
     "echarts": "^5.4.0",
     "element-ui": "2.15.13",
     "file-saver": "2.0.5",

+ 42 - 7
PHM-web/src/views/manage/instructionInfo/Editor.vue → PHM-web/src/views/manage/components/Editor.vue

@@ -6,7 +6,8 @@
         <el-button type="primary" @click="formateXml(content)">格式化</el-button>
       </div>
       <div class="right">
-        <el-button type="primary" @click="determine">确定修改</el-button>
+        <el-button type="primary" v-if="isExport" @click="exportFn">导出</el-button>
+        <el-button type="primary" v-if="isUpdate" @click="determine">确定修改</el-button>
         <el-button @click="cancel">取 消</el-button>
       </div>
     </div>
@@ -26,11 +27,29 @@ export default {
   components: {
     codemirror,
   },
-  props:[ 'textContent','closeEditor','dataType'],
+  props: {
+    // 内容
+    textContent: {
+      type: String,
+      default: () => ''
+    },
+    dataType: {
+      type: String,
+      default: () => 'xml'
+    },
+    isUpdate: {
+      type: Boolean,
+      default: () => false
+    },
+    isExport: {
+      type: Boolean,
+      default: () => false
+    }
+  },
   data() {
     return {
       // 初始的 text 内容
-      content: this.textContent, 
+      content: this.textContent,
       // 绑定的数据
       bindContentData:this.textContent,
       editorOptions: null,
@@ -63,6 +82,22 @@ export default {
       // 在这里处理 XML 内容的变化
       // console.log(textContent)
     },
+    exportFn() {
+      // 创建Blob对象
+      const blob = new Blob([this.content], { type: "text/xml" });
+
+      // // 创建下载链接
+      const link = document.createElement("a");
+      link.href = window.URL.createObjectURL(blob);
+      link.download = "指令.xml";
+
+      // 将链接添加到文档中并模拟点击
+      document.body.appendChild(link);
+      link.click();
+
+      // 清理
+      document.body.removeChild(link);
+    },
     // xml格式化
     formateXml(xmlStr){
       var that = this;
@@ -124,10 +159,10 @@ export default {
         return result;
     },
     determine(){
-      this.closeEditor(this.content)
+      this.$emit('closeEditor', this.content);
     },
     cancel(){
-      this.closeEditor('no')
+      this.$emit('closeEditor', 'no');
     }
   }
 }
@@ -141,6 +176,6 @@ export default {
   margin-top: 20px;
   display: flex;
   justify-content: space-around;
-  
+
 }
-</style>
+</style>

+ 2 - 2
PHM-web/src/views/manage/instructionInfo/index.vue

@@ -79,7 +79,7 @@
       </div>
     </el-dialog>
     <el-dialog title="详情" :visible.sync="editDialog" width="1000px" :close-on-click-modal="false" :show-close="false">
-      <Editor :textContent='textContent' :closeEditor='closeEditor' :dataType='dataType' />
+      <Editor :textContent='textContent' @closeEditor='closeEditor' :dataType='dataType' />
     </el-dialog>
   </div>
 </template>
@@ -92,7 +92,7 @@ import {
   addInstructionInfo,
   updateInstructionInfo,
 } from '@/api/manage/instructionInfo'
-import Editor from '@/views/manage/instructionInfo/Editor'
+import Editor from '@/views/manage/components/Editor'
 
 export default {
   name: 'InstructionInfo',