소스 검색

样本库模块文件上传下载功能开发完成

Koishi 3 년 전
부모
커밋
51937017d1
1개의 변경된 파일58개의 추가작업 그리고 5개의 파일을 삭제
  1. 58 5
      src/views/sampleDatabase/fault/index.vue

+ 58 - 5
src/views/sampleDatabase/fault/index.vue

@@ -98,11 +98,34 @@
             </el-date-picker>
           </div>
         </div>
-        <div class="query-actions">
+        <div class="query-actions" style="margin-left: 10px">
           <button class="btn" @click="list">查询</button>
-          <button class="btn" @click="add">新增</button>
-          <button class="btn" @click="query()">导入</button>
-          <button class="btn" @click="exportData()">导出</button>
+          <button class="btn" style="margin-left: 6px" @click="add">
+            新增
+          </button>
+          <el-upload
+            style="display: inline; margin-left: 6px"
+            :show-file-list="false"
+            :on-success="onSuccess"
+            :on-error="onError"
+            :before-upload="beforeUpload"
+            action="http://192.168.1.18:9002/case/upload/file"
+            accept=".xls,.xlsx"
+          >
+            <button class="btn" @click="importFile">
+              {{ btnText }}
+            </button>
+          </el-upload>
+          <button class="btn" style="margin-left: 6px" @click="exportData()">
+            导出
+          </button>
+          <button
+            class="btn"
+            style="margin-left: 6px"
+            @click="downloadTemplate"
+          >
+            下载模板
+          </button>
         </div>
       </div>
     </div>
@@ -151,7 +174,7 @@
         (res) => {
           addDialogTitle = '';
           addDialogShow = false;
-          list()
+          list();
         }
       "
     >
@@ -310,6 +333,7 @@ export default {
   data() {
     const that = this;
     return {
+      btnText: "导入",
       addDialogTitle: "",
       addDialogShow: false,
       addDialogForm: {
@@ -947,6 +971,35 @@ export default {
       that.addDialogTitle = "编辑";
       that.addDialogShow = true;
     },
+
+    onSuccess(response, file, fileList) {
+      if (response.code === 200) {
+        this.BASE.showMsg({
+          type: "success",
+          msg: `文件上传成功`,
+        });
+      } else {
+        this.BASE.showMsg({
+          msg: response.msg,
+        });
+      }
+
+      this.BASE.closeLoading();
+      this.btnText = "导入";
+    },
+    onError(err, file, fileList) {
+      this.btnText = "导入";
+    },
+    beforeUpload(file) {
+      this.BASE.showLoading();
+      this.btnText = "正在导入";
+      return file.type.indexOf(".sheet") !== -1;
+    },
+    downloadTemplate() {
+      window.open(
+        "http://192.168.1.18:9002/case/download/template?template=fault"
+      );
+    },
   },
   created() {
     this.startAjax();