Browse Source

预览打印

刘湘琪 2 years ago
parent
commit
7819288ff7

+ 25 - 1
src/views/enclosurePreview/index.vue

@@ -1,5 +1,6 @@
 <template>
 <template>
   <div class="app-container">
   <div class="app-container">
+    <el-button type="primary" plain icon="el-icon-download" size="mini" @click="handleClick" class="not-print-content">打印</el-button>
     <div class="container" style="margin-top: 20px;">
     <div class="container" style="margin-top: 20px;">
       <div v-show="loading" class="well loading">正在加载中,请耐心等待...</div>
       <div v-show="loading" class="well loading">正在加载中,请耐心等待...</div>
       <div v-show="!loading" class="well" ref="output"></div>
       <div v-show="!loading" class="well" ref="output"></div>
@@ -34,6 +35,23 @@
       }
       }
     },
     },
     methods: {
     methods: {
+      handleClick() {
+        if (!!window.ActiveXObject || "ActiveXObject" in window) {
+            //是否ie
+            remove_ie_header_and_footer();
+          }
+        window.print();
+      },
+      //去掉页眉页脚
+      remove_ie_header_and_footer() {
+        var hkey_path =
+          "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
+        try {
+          var RegWsh = new ActiveXObject("WScript.Shell");
+          RegWsh.RegWrite(hkey_path + "header", "");
+          RegWsh.RegWrite(hkey_path + "footer", "");
+        } catch (e) {}
+      },
       getLoadEnclosure() {
       getLoadEnclosure() {
         const filename = this.fileName
         const filename = this.fileName
         axios({
         axios({
@@ -89,5 +107,11 @@
   }
   }
 </script>
 </script>
 
 
-<style>
+<style scoped>
+  @media print {
+    .not-print-content {
+        display: none;
+    }
+  }
+  @page { margin: 0; }
 </style>
 </style>

+ 0 - 63
src/views/enterprise/declare/components/EnclosureInfo.vue

@@ -16,7 +16,6 @@
           <template slot-scope="scope">
           <template slot-scope="scope">
             <el-button type="text" @click="loadFromUrl(scope.row)">查看</el-button>
             <el-button type="text" @click="loadFromUrl(scope.row)">查看</el-button>
             <el-button type="text" @click="handleDownload(scope.row)">下载</el-button>
             <el-button type="text" @click="handleDownload(scope.row)">下载</el-button>
-            <!-- <el-button type="text" @click="handlePrint(scope.row)">打印</el-button> -->
           </template>
           </template>
         </el-table-column>
         </el-table-column>
       </el-table>
       </el-table>
@@ -27,10 +26,6 @@
         :limit.sync="queryParams.pageSize"
         :limit.sync="queryParams.pageSize"
         @pagination="getList"/>
         @pagination="getList"/>
     </div>
     </div>
-    <div class="container" style="margin-top: 20px;">
-      <div v-show="loading" class="well loading">正在加载中,请耐心等待...</div>
-      <div v-show="!loading" class="well" ref="output"></div>
-    </div>
   </div>
   </div>
 </template>
 </template>
 
 
@@ -39,9 +34,6 @@
   import {getEnclosureApi,deleteEnclosureApi,getProjectInfoApi,getProjectInfoCommonApi} from '@/api/enterprise/project/project'
   import {getEnclosureApi,deleteEnclosureApi,getProjectInfoApi,getProjectInfoCommonApi} from '@/api/enterprise/project/project'
   // 先导入getLodop方法
   // 先导入getLodop方法
   import { getLodop } from "@/plugins/lodopFuncs"
   import { getLodop } from "@/plugins/lodopFuncs"
-
-  import { getExtend, readBuffer, render } from '@/utils/util';
-  import { parse } from 'qs';
   export default {
   export default {
     props: {
     props: {
       finEnclosure: {
       finEnclosure: {
@@ -59,7 +51,6 @@
         id: this.$route.query.id,
         id: this.$route.query.id,
         dataId: undefined,
         dataId: undefined,
         attachType: 'PROJECT',
         attachType: 'PROJECT',
-        loading: false,
         selectionList: [],
         selectionList: [],
         ids: '',
         ids: '',
         info: {},
         info: {},
@@ -248,60 +239,6 @@
           query: {url: row.url,fileName: row.fileName,id: row.id}
           query: {url: row.url,fileName: row.fileName,id: row.id}
         });
         });
         window.open(routeUrl.href, "_blank");
         window.open(routeUrl.href, "_blank");
-        // this.loading = true;
-        // // 要预览的文件地址
-        // const { url } = row.url;
-        // const filename = row.fileName
-        // // const filename = url.substr(url.lastIndexOf('/') + 1);
-        // // 拼接iframe请求url
-        // axios({
-        //   url: "http://124.232.146.72:7015/api/common/attach/"+row.id,
-        //   method: 'get',
-        //   responseType: 'blob',
-        // }).then(({ data }) => {
-        //   if (!data) {
-        //     console.error('文件下载失败');
-        //   }
-        //   const file = new File([ data ], filename, {});
-        //   this.handleChange({ target: { files: [ file ] } });
-        // }).finally(() => {
-        //   this.loading = false;
-        // })
-      },
-      async handleChange(e) {
-        this.loading = true;
-        try {
-          const [ file ] = e.target.files;
-          this.filename = file.name && decodeURIComponent(file.name) || '';
-          const arrayBuffer = await readBuffer(file);
-          this.loading = false
-          this.last = await this.displayResult(arrayBuffer, file)
-          console.log("last")
-          console.log(this.last)
-        } catch (e) {
-          console.error(e)
-        } finally {
-          this.loading = false
-        }
-      },
-      displayResult(buffer, file) {
-        // 取得文件名
-        const { name } = file;
-        // 取得扩展名
-        const extend = getExtend(name);
-        // 输出目的地
-        const { output } = this.$refs;
-        // 生成新的dom
-        const node = document.createElement('div');
-        // 添加孩子,防止vue实例替换dom元素
-        if (this.last) {
-          output.removeChild(this.last.$el);
-          this.last.$destroy();
-        }
-        const child = output.appendChild(node);
-        // 调用渲染方法进行渲染
-        return new Promise((resolve, reject) => render(buffer, extend, child)
-            .then(resolve).catch(reject));
       }
       }
     }
     }
   };
   };

+ 5 - 59
src/views/enterprise/project/components/EnclosureInfo.vue

@@ -126,65 +126,11 @@
       },
       },
       // 从url加载
       // 从url加载
       handleView(row) {
       handleView(row) {
-		  let routeUrl = this.$router.resolve({
-		    path: '/enclosurePreview',
-		    query: {url: row.url,fileName: row.fileName,id: row.id}
-		  });
-		  window.open(routeUrl.href, "_blank");
-        // this.loading = true;
-        // // 要预览的文件地址
-        // const { url } = row.url;
-        // const filename = row.fileName
-        // // const filename = url.substr(url.lastIndexOf('/') + 1);
-        // // 拼接iframe请求url
-        // axios({
-        //   url: "http://124.232.146.72:7015/api/common/attach/"+row.id,
-        //   method: 'get',
-        //   responseType: 'blob',
-        // }).then(({ data }) => {
-        //   if (!data) {
-        //     console.error('文件下载失败');
-        //   }
-        //   const file = new File([ data ], filename, {});
-        //   this.handleChange({ target: { files: [ file ] } });
-        // }).finally(() => {
-        //   this.loading = false;
-        // })
-      },
-      async handleChange(e) {
-        this.loading = true;
-        try {
-          const [ file ] = e.target.files;
-          this.filename = file.name && decodeURIComponent(file.name) || '';
-          const arrayBuffer = await readBuffer(file);
-          this.loading = false
-          this.last = await this.displayResult(arrayBuffer, file)
-          console.log("last")
-          console.log(this.last)
-        } catch (e) {
-          console.error(e)
-        } finally {
-          this.loading = false
-        }
-      },
-      displayResult(buffer, file) {
-        // 取得文件名
-        const { name } = file;
-        // 取得扩展名
-        const extend = getExtend(name);
-        // 输出目的地
-        const { output } = this.$refs;
-        // 生成新的dom
-        const node = document.createElement('div');
-        // 添加孩子,防止vue实例替换dom元素
-        if (this.last) {
-          output.removeChild(this.last.$el);
-          this.last.$destroy();
-        }
-        const child = output.appendChild(node);
-        // 调用渲染方法进行渲染
-        return new Promise((resolve, reject) => render(buffer, extend, child)
-            .then(resolve).catch(reject));
+        let routeUrl = this.$router.resolve({
+          path: '/enclosurePreview',
+          query: {url: row.url,fileName: row.fileName,id: row.id}
+        });
+        window.open(routeUrl.href, "_blank");
       },
       },
       handleDelete(row) {
       handleDelete(row) {
         const id = row.id;
         const id = row.id;

+ 5 - 59
src/views/enterprise/project/components/EntEnclosure.vue

@@ -119,65 +119,11 @@
       },
       },
       // 从url加载
       // 从url加载
       handleView(row) {
       handleView(row) {
-		  let routeUrl = this.$router.resolve({
-		    path: '/enclosurePreview',
-		    query: {url: row.url,fileName: row.fileName,id: row.id}
-		  });
-		  window.open(routeUrl.href, "_blank");
-        // this.loading = true;
-        // // 要预览的文件地址
-        // const { url } = row.url;
-        // const filename = row.fileName
-        // // const filename = url.substr(url.lastIndexOf('/') + 1);
-        // // 拼接iframe请求url
-        // axios({
-        //   url: "http://124.232.146.72:7015/api/common/attach/"+row.id,
-        //   method: 'get',
-        //   responseType: 'blob',
-        // }).then(({ data }) => {
-        //   if (!data) {
-        //     console.error('文件下载失败');
-        //   }
-        //   const file = new File([ data ], filename, {});
-        //   this.handleChange({ target: { files: [ file ] } });
-        // }).finally(() => {
-        //   this.loading = false;
-        // })
-      },
-      async handleChange(e) {
-        this.loading = true;
-        try {
-          const [ file ] = e.target.files;
-          this.filename = file.name && decodeURIComponent(file.name) || '';
-          const arrayBuffer = await readBuffer(file);
-          this.loading = false
-          this.last = await this.displayResult(arrayBuffer, file)
-          console.log("last")
-          console.log(this.last)
-        } catch (e) {
-          console.error(e)
-        } finally {
-          this.loading = false
-        }
-      },
-      displayResult(buffer, file) {
-        // 取得文件名
-        const { name } = file;
-        // 取得扩展名
-        const extend = getExtend(name);
-        // 输出目的地
-        const { output } = this.$refs;
-        // 生成新的dom
-        const node = document.createElement('div');
-        // 添加孩子,防止vue实例替换dom元素
-        if (this.last) {
-          output.removeChild(this.last.$el);
-          this.last.$destroy();
-        }
-        const child = output.appendChild(node);
-        // 调用渲染方法进行渲染
-        return new Promise((resolve, reject) => render(buffer, extend, child)
-            .then(resolve).catch(reject));
+        let routeUrl = this.$router.resolve({
+          path: '/enclosurePreview',
+          query: {url: row.url,fileName: row.fileName,id: row.id}
+        });
+        window.open(routeUrl.href, "_blank");
       },
       },
       handleDelete(row) {
       handleDelete(row) {
         const id = row.id;
         const id = row.id;

+ 5 - 59
src/views/enterprise/project/components/FinEnclosure.vue

@@ -119,65 +119,11 @@
       },
       },
       // 从url加载
       // 从url加载
       handleView(row) {
       handleView(row) {
-		  let routeUrl = this.$router.resolve({
-		    path: '/enclosurePreview',
-		    query: {url: row.url,fileName: row.fileName,id: row.id}
-		  });
-		  window.open(routeUrl.href, "_blank");
-        // this.loading = true;
-        // // 要预览的文件地址
-        // const { url } = row.url;
-        // const filename = row.fileName
-        // // const filename = url.substr(url.lastIndexOf('/') + 1);
-        // // 拼接iframe请求url
-        // axios({
-        //   url: "http://124.232.146.72:7015/api/common/attach/"+row.id,
-        //   method: 'get',
-        //   responseType: 'blob',
-        // }).then(({ data }) => {
-        //   if (!data) {
-        //     console.error('文件下载失败');
-        //   }
-        //   const file = new File([ data ], filename, {});
-        //   this.handleChange({ target: { files: [ file ] } });
-        // }).finally(() => {
-        //   this.loading = false;
-        // })
-      },
-      async handleChange(e) {
-        this.loading = true;
-        try {
-          const [ file ] = e.target.files;
-          this.filename = file.name && decodeURIComponent(file.name) || '';
-          const arrayBuffer = await readBuffer(file);
-          this.loading = false
-          this.last = await this.displayResult(arrayBuffer, file)
-          console.log("last")
-          console.log(this.last)
-        } catch (e) {
-          console.error(e)
-        } finally {
-          this.loading = false
-        }
-      },
-      displayResult(buffer, file) {
-        // 取得文件名
-        const { name } = file;
-        // 取得扩展名
-        const extend = getExtend(name);
-        // 输出目的地
-        const { output } = this.$refs;
-        // 生成新的dom
-        const node = document.createElement('div');
-        // 添加孩子,防止vue实例替换dom元素
-        if (this.last) {
-          output.removeChild(this.last.$el);
-          this.last.$destroy();
-        }
-        const child = output.appendChild(node);
-        // 调用渲染方法进行渲染
-        return new Promise((resolve, reject) => render(buffer, extend, child)
-            .then(resolve).catch(reject));
+        let routeUrl = this.$router.resolve({
+          path: '/enclosurePreview',
+          query: {url: row.url,fileName: row.fileName,id: row.id}
+        });
+        window.open(routeUrl.href, "_blank");
       },
       },
       handleDelete(row) {
       handleDelete(row) {
         const id = row.id;
         const id = row.id;

+ 5 - 59
src/views/enterprise/project/components/TechEnclosure.vue

@@ -119,65 +119,11 @@
       },
       },
       // 从url加载
       // 从url加载
       handleView(row) {
       handleView(row) {
-		  let routeUrl = this.$router.resolve({
-		    path: '/enclosurePreview',
-		    query: {url: row.url,fileName: row.fileName,id: row.id}
-		  });
-		  window.open(routeUrl.href, "_blank");
-        // this.loading = true;
-        // // 要预览的文件地址
-        // const { url } = row.url;
-        // const filename = row.fileName
-        // // const filename = url.substr(url.lastIndexOf('/') + 1);
-        // // 拼接iframe请求url
-        // axios({
-        //   url: "http://124.232.146.72:7015/api/common/attach/"+row.id,
-        //   method: 'get',
-        //   responseType: 'blob',
-        // }).then(({ data }) => {
-        //   if (!data) {
-        //     console.error('文件下载失败');
-        //   }
-        //   const file = new File([ data ], filename, {});
-        //   this.handleChange({ target: { files: [ file ] } });
-        // }).finally(() => {
-        //   this.loading = false;
-        // })
-      },
-      async handleChange(e) {
-        this.loading = true;
-        try {
-          const [ file ] = e.target.files;
-          this.filename = file.name && decodeURIComponent(file.name) || '';
-          const arrayBuffer = await readBuffer(file);
-          this.loading = false
-          this.last = await this.displayResult(arrayBuffer, file)
-          console.log("last")
-          console.log(this.last)
-        } catch (e) {
-          console.error(e)
-        } finally {
-          this.loading = false
-        }
-      },
-      displayResult(buffer, file) {
-        // 取得文件名
-        const { name } = file;
-        // 取得扩展名
-        const extend = getExtend(name);
-        // 输出目的地
-        const { output } = this.$refs;
-        // 生成新的dom
-        const node = document.createElement('div');
-        // 添加孩子,防止vue实例替换dom元素
-        if (this.last) {
-          output.removeChild(this.last.$el);
-          this.last.$destroy();
-        }
-        const child = output.appendChild(node);
-        // 调用渲染方法进行渲染
-        return new Promise((resolve, reject) => render(buffer, extend, child)
-            .then(resolve).catch(reject));
+        let routeUrl = this.$router.resolve({
+          path: '/enclosurePreview',
+          query: {url: row.url,fileName: row.fileName,id: row.id}
+        });
+        window.open(routeUrl.href, "_blank");
       },
       },
       handleDelete(row) {
       handleDelete(row) {
         const id = row.id;
         const id = row.id;