qinzhipeng_v 5 years ago
parent
commit
1f38971a11
2 changed files with 31 additions and 14 deletions
  1. 1 0
      package.json
  2. 30 14
      src/views/Platform/presentation/testPresenyL.vue

+ 1 - 0
package.json

@@ -16,6 +16,7 @@
   },
   "dependencies": {
     "axios": "0.18.0",
+    "dom-to-image": "^2.6.0",
     "echarts": "^4.2.1",
     "element-ui": "^2.9.1",
     "file-saver": "^2.0.2",

+ 30 - 14
src/views/Platform/presentation/testPresenyL.vue

@@ -39,7 +39,8 @@
 import echarts from 'echarts'
 import { bugDailyList, dailyReport } from '@/api/testPresentetion'
 import { dailyReportSendmail } from '@/api/ResultPage'
-import html2canvas from 'html2canvas'
+// import html2canvas from 'html2canvas'
+import domtoimage from 'dom-to-image'
 export default {
   name: 'TestPresenyL',
   data() {
@@ -121,20 +122,35 @@ export default {
     },
 
     sendReport(e, ele) {
-      setTimeout(() => {
-        var that = this
-        that.btn = false
-        html2canvas(document.getElementById('resumeId'), { useCORS: true, windowWidth: document.getElementById('resumeId').scrollWidth, windowHeight: document.getElementById('resumeId').scrollHeight }).then(function(canvas) {
-          var url = canvas.toDataURL('image/png', 1.0)
-          console.log(url)
-          url = url.toString().substring(url.indexOf(',') + 1)
-          var postData = { 'reportId': ele.id, 'imgStr': url, 'url': window.location.href, 'emailUser': e }
-          dailyReportSendmail(postData).then(res => {
-            res.code === 200 ? that.$message({ type: 'success', message: '发送测试报告成功' }) : that.$message({ type: 'error', message: '发送测试报告失败,请联系管理员!' })
-            that.btn = true
-          })
+      var node = document.getElementById('resumeId')
+      domtoimage.toPng(node).then(function(dataUrl) {
+        var url = dataUrl
+        url = url.toString().substring(url.indexOf(',') + 1)
+        var postData = { 'reportId': ele.id, 'imgStr': url, 'url': window.location.href, 'emailUser': e }
+        dailyReportSendmail(postData).then(res => {
+          res.code === 200 ? console.log('发送测试报告成功') : console.log('发送测试报告失败,请联系管理员!')
+          // res.code === 200 ? that.$message({ type: 'success', message: '发送测试报告成功' }) : that.$message({ type: 'error', message: '发送测试报告失败,请联系管理员!' })
         })
-      }, 1000)
+        // var img = new Image()
+        // img.src = dataUrl
+        // document.body.appendChild(img)
+      }).catch(function(error) {
+        console.error('oops, something went wrong!', error)
+      })
+      // setTimeout(() => {
+      //   var that = this
+      //   that.btn = false
+      //   html2canvas(document.getElementById('resumeId'), { useCORS: true, windowWidth: document.getElementById('resumeId').scrollWidth, windowHeight: document.getElementById('resumeId').scrollHeight }).then(function(canvas) {
+      //     var url = canvas.toDataURL('image/png', 1.0)
+      //     console.log(url)
+      //     url = url.toString().substring(url.indexOf(',') + 1)
+      //     var postData = { 'reportId': ele.id, 'imgStr': url, 'url': window.location.href, 'emailUser': e }
+      //     dailyReportSendmail(postData).then(res => {
+      //       res.code === 200 ? that.$message({ type: 'success', message: '发送测试报告成功' }) : that.$message({ type: 'error', message: '发送测试报告失败,请联系管理员!' })
+      //       that.btn = true
+      //     })
+      //   })
+      // }, 1000)
     }
   }
 }