From 1d69b2703aa304f9e8b2c470b8a3d74d43cb4809 Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期五, 28 七月 2023 17:46:45 +0800
Subject: [PATCH] 主题库导入 导出功能

---
 Source/UBCS-WEB/src/components/Theme/ThemeImport.vue |  155 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 141 insertions(+), 14 deletions(-)

diff --git a/Source/UBCS-WEB/src/components/Theme/ThemeImport.vue b/Source/UBCS-WEB/src/components/Theme/ThemeImport.vue
index 70caaaa..f2d533d 100644
--- a/Source/UBCS-WEB/src/components/Theme/ThemeImport.vue
+++ b/Source/UBCS-WEB/src/components/Theme/ThemeImport.vue
@@ -1,33 +1,160 @@
 <template>
   <el-dialog
-    title="涓婚搴撳鍏�"
+    title="涓婚搴撳垎绫诲鍏�"
     :visible.sync="dialogVisible"
     append-to-body
-    v-dialogDrag
-  ></el-dialog>
+  >
+    <Divider text="瀵煎叆鎻愮ず" left="30px"></Divider>
+    <ul>
+      <li>
+        1.绾㈣壊瀛椾綋琛ㄧず蹇呰緭椤�
+      </li>
+      <li>
+        2.鍒嗙被鐨勮矾寰勯渶瑕佺敤#鍒嗛殧
+      </li>
+      <li>
+        3.姣忔浠呰兘鏈�澶氬鍏�10000鏉℃暟鎹�
+      </li>
+    </ul>
+    <Divider text="excel鏂囦欢锛岄�夋嫨鏂囦欢鍚庝細鑷姩涓婁紶" left="30px"></Divider>
+    <el-upload
+      accept=".xlsx, .xls"
+      action="/api/ubcs-code/codeClassify/importClassify"
+      :on-success="onSuccess"
+      :on-error="onError"
+      :headers="uploadHeaders"
+      :show-file-list="false"
+      :before-upload="beforeUpload"
+      :on-change="uploadChange"
+      class="upload-demo">
+      <el-button size="small" type="primary" style="margin: 15px 35px">娴忚鏂囦欢</el-button>
+    </el-upload>
+    <template #footer>
+      <el-button
+        type="primary"
+        size="small"
+        @click="downloadTemplateFun"
+        :loading="downloadLoading"
+      >涓嬭浇瀵煎叆妯℃澘</el-button
+      >
+      <el-button size="small" @click="dialogVisible = false">鍏抽棴</el-button>
+    </template>
+  </el-dialog>
 </template>
 
 <script>
+import {downloadErrorFile,downloadBatchImportApplyTemplate} from '@/api/template/templateAttr'
+import {getToken} from "@/util/auth";
+import func from "@/util/func";
 export default {
   name: "ThemeImport",
-  props:{
-    dialogVisible: {
-      get() {
-        return this.dialogVisible;
-      },
-      set(val) {
-        this.$emit("update:dialogVisible", val);
-      },
+  props: {
+    visible: {
+      type: Boolean,
+      default: false,
+    },
+    codeClassifyOid: {
+      type: String,
+      default: "",
     },
   },
   data(){
     return{
-
+      flga:true,
+      pageLoading: null,
+      downloadLoading: false,
+    }
+  },
+  watch:{
+    visible:{
+      handler(newval,oldval){
+        console.log('newval',newval)
+      }
+    }
+  },
+  computed:{
+    uploadHeaders() {
+      return {
+        "Blade-Auth": "bearer " + getToken(),
+      };
+    },
+    dialogVisible: {
+      get() {
+        return this.visible;
+      },
+      set(val) {
+        this.$emit("update:visible", val);
+      },
+    },
+  },
+  methods:{
+    //鏂囦欢涓婁紶鍓�
+    async beforeUpload(file) {
+      const fileType = file.name.split(".").pop();
+      if (fileType !== "xlsx" && fileType !== "xls") {
+        // 涓婁紶鏍煎紡涓嶇鍚堣姹傦紝鎻愮ず閿欒淇℃伅骞跺彇娑堜笂浼�
+        this.$message.error("鍙厑璁镐笂浼爔lsx銆亁ls鏍煎紡鐨勬枃浠�");
+        return Promise.reject(false);
+      }
+      this.pageLoading = this.$loading({
+        lock: true,
+        text: "鏂囦欢涓婁紶涓�",
+        spinner: "el-icon-loading",
+        background: "rgba(0, 0, 0, 0.7)",
+      });
+      return true;
+    },
+    // 鏂囦欢涓婁紶鎴愬姛
+    onSuccess(resbonse){
+      if (Object.keys(resbonse.data).length === 0) {
+        this.$message.success( "涓婚搴撳垎绫诲鍏ユ垚鍔燂紒");
+        this.dialogVisible = false;
+        return;
+      }
+      if (resbonse.data.fileOid) {
+        const fileName = resbonse.data.filePath.split("/").pop();
+        this.$message.error("璇蜂笅杞介敊璇俊鎭枃浠惰繘琛屾煡鐪嬶紒");
+        downloadErrorFile({ uuid: resbonse.data.fileOid }).then((res) => {
+          func.downloadFileByBlobHandler(res);
+        });
+      }
+    },
+    //鐐瑰嚮涓嬭浇妯℃澘
+    downloadTemplateFun(){
+      this.downloadLoading = true;
+      downloadBatchImportApplyTemplate({codeClassifyOid: this.codeClassifyOid}).then(res=>{
+        console.log(res)
+        this.$utilFunc.downloadFileByBlob(res.data,  "涓婚搴撳垎绫绘ā鏉�.xls");
+        this.downloadLoading = false;
+      }).catch((res)=>{
+        this.$message.warning(res)
+        this.downloadLoading = false;
+      })
+    },
+    //鏂囦欢涓婁紶澶辫触
+    onError(res){
+      console.log(res)
+      this.pageLoading.close();
+    },
+    //鏂囦欢鐘舵�佹敼鍙�
+    uploadChange(file){
+      if (file.status === "success" || file.status === "error") {
+        this.pageLoading.close();
+      }
     }
   }
 }
 </script>
 
-<style scoped>
-
+<style scoped lang="scss">
+ul {
+  color: rgb(188, 188, 188);
+  margin: 20px 0 20px 0;
+  padding: 0 0 0 30px;
+  list-style: none;
+  li {
+    margin-bottom: 5px;
+    font-size: 13px;
+  }
+}
 </style>

--
Gitblit v1.9.3