From 0e86fcacac365d077ec718fe95103a5ae6af3df8 Mon Sep 17 00:00:00 2001
From: he wei <858544502@qq.com>
Date: 星期三, 03 一月 2024 16:11:21 +0800
Subject: [PATCH] U 压缩包解压预览

---
 src/pages/resourceManage/product/details/apis.js     |   12 +++
 src/pages/resourceManage/product/details/details.vue |  227 +++++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 202 insertions(+), 37 deletions(-)

diff --git a/src/pages/resourceManage/product/details/apis.js b/src/pages/resourceManage/product/details/apis.js
index 3766ffb..bcc28bb 100644
--- a/src/pages/resourceManage/product/details/apis.js
+++ b/src/pages/resourceManage/product/details/apis.js
@@ -102,4 +102,16 @@
     url: "zipAndRar/getzipAndRarInfo",
     params: { fileUrl },
   });
+};
+
+/**
+ * 瑙e帇鍘嬬缉鍖� 骞惰繑鍥炲唴閮ㄧ洰褰曠粨鏋勫強璺緞
+ * @returns
+ */
+export const decompress = (compressedFileUrl) => {
+  return axios({
+    method: "GET",
+    url: "zipAndRar/decompress",
+    params: { compressedFileUrl },
+  });
 };
\ No newline at end of file
diff --git a/src/pages/resourceManage/product/details/details.vue b/src/pages/resourceManage/product/details/details.vue
index a379983..889f5b5 100644
--- a/src/pages/resourceManage/product/details/details.vue
+++ b/src/pages/resourceManage/product/details/details.vue
@@ -84,8 +84,8 @@
                     <template
                       v-if="
                         record.softwares &&
-                        record.softwares.length &&
-                        canDownloadSoftware
+                          record.softwares.length &&
+                          canDownloadSoftware
                       "
                     >
                       <a-divider
@@ -120,8 +120,8 @@
                       <a-divider
                         v-if="
                           record.softwares &&
-                          record.softwares.length &&
-                          canDownloadSoftware
+                            record.softwares.length &&
+                            canDownloadSoftware
                         "
                         type="vertical"
                       ></a-divider>
@@ -133,8 +133,8 @@
                       <a-divider
                         v-if="
                           record.softwares &&
-                          record.softwares.length &&
-                          canDownloadSoftware
+                            record.softwares.length &&
+                            canDownloadSoftware
                         "
                         type="vertical"
                       ></a-divider>
@@ -148,8 +148,8 @@
                       <a-divider
                         v-if="
                           record.softwares &&
-                          record.softwares.length &&
-                          canDownloadSoftware
+                            record.softwares.length &&
+                            canDownloadSoftware
                         "
                         type="vertical"
                       ></a-divider>
@@ -192,7 +192,7 @@
             <a-button
               v-if="
                 ((canDownloadBom && currentVersion.enabled == 1) || isTester) &&
-                !is0120
+                  !is0120
               "
               type="primary"
               @click="checkLock('zipDownload')"
@@ -203,8 +203,8 @@
                 (((canDownloadBom || canDownloadOriginBom) &&
                   currentVersion.enabled == 1) ||
                   isTester) &&
-                originalZipUrl &&
-                !is0120
+                  originalZipUrl &&
+                  !is0120
               "
               type="primary"
               @click="checkLock('OriginalZipDownload')"
@@ -220,8 +220,8 @@
               type="primary"
               v-if="
                 softwareList.length &&
-                canDownloadSoftware &&
-                currentVersion.enabled == 1
+                  canDownloadSoftware &&
+                  currentVersion.enabled == 1
               "
               @click="showSoftwareDownload"
               >杞欢涓嬭浇</a-button
@@ -230,8 +230,8 @@
               type="primary"
               v-if="
                 currentVersion.enabled == 0 &&
-                canLockBom &&
-                (!is0120 || maxVersionid == currentVersion.id)
+                  canLockBom &&
+                  (!is0120 || maxVersionid == currentVersion.id)
               "
               @click="changeStatus"
               >婵�娲荤増鏈�</a-button
@@ -248,7 +248,10 @@
               @click="changeStatus"
               >閿佸畾鐗堟湰</a-button
             >
-	          <a-button type="primary" @click="viewSopFile">SOP鏌ョ湅</a-button>
+            <a-button type="primary" @click="viewSopFile">SOP鏌ョ湅</a-button>
+            <a-button v-if="originalZipUrl" type="primary" @click="preview"
+              >鍘熷鍖呴瑙�</a-button
+            >
           </template>
         </a-card>
       </a-layout-footer>
@@ -429,17 +432,60 @@
         <a-empty v-else />
       </div>
     </a-modal>
-	  <a-modal
-		  :visible="showSop"
-		  :footer="null"
-		  :width="1366"
-		  title="SOP鏌ョ湅"
-		  :destroyOnClose="true"
-		  @cancel="showSop = false">
-		  <div style="height: 600px">
-			  <sop-list :parentCode="parentCode"></sop-list>
-		  </div>
-	  </a-modal>
+
+    <a-modal
+      :visible="fileTreeViewVisible"
+      :footer="null"
+      :width="860"
+      title="鏂囦欢鍒楄〃"
+      :destroyOnClose="true"
+      @cancel="fileTreeViewVisible = false"
+    >
+      <div class="log-content">
+        <a-tree
+          class="file-tree-view"
+          v-if="fileTreeView.length"
+          :show-line="true"
+          defaultExpandAll
+          :tree-data="fileTreeView"
+        >
+          <template slot="custom" slot-scope="item">
+            <div class="flex-r space-between">
+              <span class="node-title">{{ item.title }} </span>
+              <span
+                class="icon-wrap"
+                v-if="item.isLeaf && viewAble(item.type)"
+                title="棰勮"
+                @click="view(item)"
+              >
+                <a-icon type="file-search" />
+              </span>
+            </div>
+          </template>
+        </a-tree>
+        <a-empty v-else />
+      </div>
+    </a-modal>
+    <a-modal
+      :visible="showSop"
+      :footer="null"
+      :width="1366"
+      title="SOP鏌ョ湅"
+      :destroyOnClose="true"
+      @cancel="showSop = false"
+    >
+      <div style="height: 600px">
+        <sop-list :parentCode="parentCode"></sop-list>
+      </div>
+    </a-modal>
+    <a-modal
+      :width="600"
+      :visible="previewVisible"
+      :footer="null"
+      @cancel="handleCancel"
+    >
+      <img alt="" style="width: 100%" :src="imgUrl" />
+    </a-modal>
   </div>
 </template>
 
@@ -466,6 +512,7 @@
   getOriginalZip,
   checkExist,
   getzipAndRarInfo,
+  decompress,
 } from "./apis";
 import {
   searchDefaultMailUser,
@@ -485,9 +532,13 @@
   mixins: [WSMixin],
   data() {
     return {
-			showSop: false,
+      imgUrl: "",
+      previewVisible: false,
+      showSop: false,
       fileTreeVisible: false,
       fileTree: [],
+      fileTreeViewVisible: false,
+      fileTreeView: [],
       userListAll: [],
       mailList: [],
       tester: [],
@@ -739,7 +790,7 @@
     Pop,
     DownloadReason,
     DownloadLogs,
-	  SopList,
+    SopList,
   },
   computed: {
     ...mapGetters("setting", ["affixed"]),
@@ -800,9 +851,9 @@
     },
   },
   methods: {
-	  viewSopFile() {
-			this.showSop = true;
-	  },
+    viewSopFile() {
+      this.showSop = true;
+    },
     getRoleUser() {
       getRoleUser(1)
         .then((res) => {
@@ -1361,7 +1412,7 @@
 
       return res;
     },
-    format(list) {
+    format(list, needTime = true) {
       let counter = this.counter();
       let obj = {
         counter,
@@ -1374,10 +1425,14 @@
       //   children: [],
       // };
       list.forEach((v) => {
-        let url = v.fileName;
+        let url = needTime ? v.fileName : v;
         let fileTime = v.fileTime;
-        let arr = url.split("/");
+        let splitStr = needTime ? "/" : "\\";
+        let arr = url.split(splitStr);
         let fileName = arr.pop();
+        let files = fileName.split(".");
+        let type = files.length ? files[files.length - 1].toLowerCase() : "";
+
         let tmp = obj;
 
         for (let i = 0, len = arr.length; i < len; i++) {
@@ -1388,6 +1443,7 @@
               title: arr[i],
               key: parent.key + "-" + parent.counter(),
               children: [],
+              scopedSlots: { title: "custom" },
               counter: this.counter(),
             };
             // tmp[arr[i]].parent.children.push(tmp[arr[i]]);
@@ -1397,10 +1453,13 @@
         }
         // console.log(tmp.children, 'children')
         tmp.children.push({
+          url,
+          type,
           fileName,
           fileTime,
           key: tmp.key + "-" + tmp.counter(),
-          title: fileName + "  " + fileTime,
+          title: needTime ? fileName + "  " + fileTime : fileName,
+          scopedSlots: { title: "custom" },
           isLeaf: true,
         });
         // console.log(obj, '......')
@@ -1425,13 +1484,14 @@
         return count++;
       };
     },
+    // 鏌ョ湅鍘嬬缉鍖呭唴鏂囦欢鐩綍缁撴瀯
     viewRar() {
       let loading = this.$layer.loading();
       // console.log(this.originalZipUrl);
       getzipAndRarInfo(this.originalZipUrl)
         .then((res) => {
           let { code, data, data2 } = res.data;
-          let list = [];
+          let list = { children: [] };
           if (code && data) {
             console.log(data2);
             list = this.format(data2);
@@ -1446,6 +1506,71 @@
           this.$layer.close(loading);
           console.log(err);
         });
+    },
+    // 瑙e帇鍘嬬缉鍖呭埌鏈嶅姟鍣� 鐒跺悗杩斿洖鍐呴儴鏂囦欢鐨勭粨鏋勫拰璺緞 璺緞鍙敤鏉ラ瑙�
+    preview() {
+      let loading = this.$layer.loading();
+      decompress(this.originalZipUrl)
+        .then((res) => {
+          let { code, data, data2, msg } = res.data;
+          let list = [];
+          if (code && data) {
+            // console.log(data);
+            this.$message.success("瑙f瀽鎴愬姛");
+            let {
+              children: [
+                {
+                  children: [{ children: list1 }],
+                },
+              ],
+            } = this.format(data2, false);
+            list = list1;
+          } else {
+            this.$message.error(msg);
+          }
+          this.$layer.close(loading);
+
+          this.fileTreeView = list;
+
+          // this.fileTreeView = list.children[0]["children"][0]["children"];
+          this.fileTreeViewVisible = true;
+          // console.log(list, "===list111");
+        })
+        .catch((err) => {
+          console.log(err);
+          this.$layer.close(loading);
+        });
+    },
+    viewAble(type) {
+      return ["bmp", "jpg", "jpeg", "png", "pdf", "doc", "docx", "dwg"].some(
+        (v) => v == type
+      );
+    },
+    view(obj) {
+      switch (obj.type) {
+        // 鍥剧墖
+        case "bmp":
+        case "jpg":
+        case "jpeg":
+        case "png":
+          this.imgUrl = this.webUrl + obj.url;
+          this.previewVisible = true;
+          break;
+        case "pdf":
+          window.open(this.webUrl + obj.url);
+          break;
+        case "doc":
+        case "docx":
+        case "dwg":
+          this.dwgReview(obj.url);
+          break;
+        // default:
+        //   this.$message.warn("璇ョ被鍨嬫枃浠舵殏涓嶆敮鎸侀瑙�");
+        //   break;
+      }
+    },
+    handleCancel() {
+      this.previewVisible = false;
     },
   },
   mounted() {
@@ -1637,4 +1762,32 @@
 /deep/.ant-descriptions-row .ant-descriptions-item:first-child {
   width: 180px;
 }
+.file-tree-view /deep/ li {
+  // display: flex;
+  // flex-direction: row;
+  .ant-tree-switcher {
+    float: left;
+  }
+  .ant-tree-node-content-wrapper {
+    display: block;
+    cursor: auto;
+    .ant-tree-title {
+      display: block;
+    }
+  }
+  .ant-tree-child-tree {
+    flex-basis: 100%;
+  }
+  .icon-wrap {
+    cursor: pointer;
+    font-size: 22px;
+  }
+}
+.flex-r {
+  display: flex;
+  flex-direction: row;
+  &.space-between {
+    justify-content: space-between;
+  }
+}
 </style>

--
Gitblit v1.9.1