소스 검색

wx上传PDF

zhangxiaomu 2 년 전
부모
커밋
cf0417c408
2개의 변경된 파일30개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 0
      src/api/pages/common/common.js
  2. 27 2
      src/view/wx-print/index.vue

+ 3 - 0
src/api/pages/common/common.js

@@ -116,6 +116,9 @@ export default {
     // 获取组织仓库
     getOrgWh:'get_org_wh',
   },
+  fileService:{
+    prefix: 'mdm-server/file/',
+  }
 }
 
 /**

+ 27 - 2
src/view/wx-print/index.vue

@@ -21,6 +21,18 @@ export default {
     }
   },
   methods: {
+    dataURLtoFile: (dataurl, filename) => {
+      let arr = dataurl.split(',');
+      let mime = arr[0].match(/:(.*?);/)[1];
+      let bstr = atob(arr[1]);
+      let n = bstr.length;
+      let u8arr = new Uint8Array(n);
+      while (n--) {
+        u8arr[n] = bstr.charCodeAt(n);
+      }
+      //转换成file对象
+      return new File([u8arr], filename, {type: mime});
+    }
   },
   created() {
   },
@@ -38,6 +50,10 @@ export default {
       this.$Message.warning('请先选择单据类型再打印')
       return
     }
+    if (!this.$route.query.uuid) {
+      this.$Message.warning('请先设置唯一id')
+      return
+    }
 
     // let template = this.templateList.find(it => it.layoutId == this.$route.query.layout_id)?.layoutData
     console.log('templateList',this.templateList)
@@ -54,15 +70,24 @@ export default {
           let layout =results?.[2]?.data?.list.find(it => it.layoutId == this.$route.query.layout_id)?.layoutData
           this.$set(header, 'table', detail['orderItem'])
 
-
           let printData = {...header}
 
           let hiprintTemplate = new hiprint.PrintTemplate({
             template: layout,
           })
 
-          hiprintTemplate.toPdf(printData,'单据打印')
+          hiprintTemplate.toPdf(printData,'单据打印',{isDownload:false,type:'datauristring'}).then(dataURL=>{
+            // console.log('res',dataURL)
 
+            let pdf = this.dataURLtoFile(dataURL, "pdf");
+            let formData = new FormData();
+            formData.append('file', pdf);
+            this.excute(this.$service.fileService, `upload?folder=pdf&uuid=${this.$route.query.uuid}`,formData).then(res => {
+              if (res.code === this.$config.SUCCESS_CODE) {
+                console.log('upload-res',res)
+              }
+            })
+          })
 
         }else {
           this.$Message.warning(this.$t('W_006'))