浏览代码

实现API配置管理页面的导入带出

Sanmu8 1 年之前
父节点
当前提交
ea3a5d8cb6
共有 1 个文件被更改,包括 62 次插入5 次删除
  1. 62 5
      src/views/APICONFIG/index.vue

+ 62 - 5
src/views/APICONFIG/index.vue

@@ -92,13 +92,23 @@
         <el-button
           type="warning"
           plain
-          icon="el-icon-download"
           size="mini"
+          icon="el-icon-upload"
           @click="openUpload = true"
           v-hasPermi="['business:APICONFIG:export']"
           >导入</el-button
         >
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          plain
+          size="mini"
+          icon="el-icon-download"
+          @click="handleDownload()"
+          :disabled="radio === '' ? true : false"
+          >导出</el-button
+        >
+      </el-col>
       <right-toolbar
         :showSearch.sync="showSearch"
         @queryTable="getList"
@@ -109,8 +119,19 @@
       v-loading="loading"
       :data="APICONFIGList"
       @selection-change="handleSelectionChange"
+      @row-click="showRow"
     >
-      <el-table-column type="selection" width="55" align="center" />
+    <el-table-column label="选择" width="70" center>
+        <template scope="scope">
+          <el-radio
+            class="radio"
+            v-model="radio"
+            :label="scope.$index"
+            @change.native="getCurrentRow(scope.row)"
+            >{{ "" }}</el-radio
+          >
+        </template>
+      </el-table-column>
       <el-table-column label="接口编号" align="center" prop="apiCode">
         <template slot-scope="scope">
           {{ scope.row.apiCode }}
@@ -337,6 +358,11 @@ import {
   upload,
 } from "@/api/portal/APICONFIG/APICONFIG.js";
 
+import { saveAs } from "file-saver";
+import { getToken } from "@/utils/auth";
+import axios from "axios";
+//我好困
+
 export default {
   name: "APICONFIG",
   data() {
@@ -376,6 +402,7 @@ export default {
       baseURL: process.env.VUE_APP_BASE_API,
       // 遮罩层
       loading: true,
+      rowData: {},
       // 选中数组
       ids: [],
       // 非单个禁用
@@ -414,6 +441,7 @@ export default {
         linkStatus: null,
         remark: null,
       },
+      radio:'',
       // 表单参数
       form: {},
       // 表单校验
@@ -504,6 +532,9 @@ export default {
       this.openUpload = false;
       this.reset();
     },
+    getCurrentRow(val) {
+      console.log(val);
+    },
     // 表单重置
     reset() {
       this.form = {
@@ -597,10 +628,36 @@ export default {
       this.openUpload = false
     },
     /** 导出按钮操作 */
-    handleExport(id) {
-      exportAPICONFIG(id).then(res=>{
+    // handleExport(id) {
+    //   exportAPICONFIG(id).then(res=>{
         
-      })
+    //   })
+    // },
+      /** 导出按钮操作 */
+      showRow(row) {
+      //赋值给radio
+      this.radio = this.APICONFIGList.indexOf(row);
+      this.rowData = row;
+    },
+    handleDownload() {
+      let row = this.rowData;
+      axios({
+        url: process.env.VUE_APP_BASE_API + "/APICONFIG/export/",
+        method: "post",
+        responseType: "blob",
+        data:row,
+        headers: {
+          Authorization: "Bearer " + getToken(),
+        },
+      }).then((res) => {
+        // const temp = res.headers["content-disposition"]
+        //   .split(";")[1]
+        //   .split("filename=")[1];
+        // const fileName = decodeURIComponent(temp);
+        const blob = new Blob([res.data]);
+        saveAs(blob, row.apiName+'.xlsx');
+        this.getList();
+      });
     },
     
   },