diff --git a/public/js/EWebBridge.js b/public/js/EWebBridge.js index c55d3825e..23d6baf42 100644 --- a/public/js/EWebBridge.js +++ b/public/js/EWebBridge.js @@ -152,6 +152,7 @@ function appCallBack() {} // 初始化App桥接环境 function setupWebViewJavascriptBridge(callback) { + console.log(callback); // Android 调用 if (window.WebViewJavascriptBridge) { callback(WebViewJavascriptBridge) @@ -194,6 +195,9 @@ function appCallBack() {} setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0) + setTimeout(() => { + document.documentElement.removeChild(WVJBIframe) + }, 100); } } diff --git a/src/views/ebiz/billingDetail/billingDetail.vue b/src/views/ebiz/billingDetail/billingDetail.vue index d039d46cf..de3346bd4 100644 --- a/src/views/ebiz/billingDetail/billingDetail.vue +++ b/src/views/ebiz/billingDetail/billingDetail.vue @@ -120,8 +120,7 @@

当前条件查无数据

- - + @@ -879,29 +878,6 @@ export default { const oneYearAgoDate = getOneYearAgoDate(); this.timeMinDate = oneYearAgoDate }, - xiazai() { - this.haha() - }, - haha() { - async function captureAndProcessImage() { - EWebBridge.webCallAppInJs('download', { - url: 'https://iagentsales-test2.e-guofu.com/images/2024/12/30/realTimeOrder_b2914c33a78c496fa5be5033e3aa8e7e.png', - name: '业绩贺报.png' - }) - } - captureAndProcessImage() - }, - xiazai2() { - this.haha2() - }, - haha2() { - async function captureAndProcessImage() { - EWebBridge.webCallAppInJs('download', { - url: 'https://iagentsales-test2.e-guofu.com/images/2024/12/30/realTimeOrder_b2914c33a78c496fa5be5033e3aa8e7e.png', - name: '业绩贺报.png' - }) - } - } } } diff --git a/src/views/ebiz/generateImg/generateImg.vue b/src/views/ebiz/generateImg/generateImg.vue index bb9b10c56..11c900fea 100644 --- a/src/views/ebiz/generateImg/generateImg.vue +++ b/src/views/ebiz/generateImg/generateImg.vue @@ -17,7 +17,7 @@ - +
@@ -76,139 +76,86 @@ export default { }) }, // 分享 - fenxiang() { - if(this.$refs.xingdownLoad != this.$refs.xingdownLoad) { - return - } + shareImg() { // const element = document.getElementById('capture') // const canvas = await html2canvas(element) - html2canvas(this.$refs.xingdownLoad, { - width: this.$refs.xingdownLoad.offsetWidth, - height: this.$refs.xingdownLoad.offsetHeight, - backgroundColor: '#fff', - scale: 2, - dpi: 300 - }).then((canvas) => { - // 将 canvas 转换为 Blob - canvas.toBlob((blob) => { - this.blobToBase64(blob).then((base64String) => { - let base64Manane = base64String.split(',')[1] - // console.log(base64String) - if(this.shareJin == false) { - this.shareJin = true - EWebBridge.webCallAppInJs('bridge', { - flag: 'share', - extra: { - shareType: '1', - base64: base64Manane - } - }) + html2canvas(this.$refs.xingdownLoad, { + width: this.$refs.xingdownLoad.offsetWidth, + height: this.$refs.xingdownLoad.offsetHeight, + backgroundColor: '#fff', + scale: 2, + dpi: 300 + }).then((canvas) => { + // 将 canvas 转换为 Blob + canvas.toBlob((blob) => { + this.blobToBase64(blob).then((base64String) => { + let base64Manane = base64String.split(',')[1] + // console.log(base64String) + EWebBridge.webCallAppInJs('bridge', { + flag: 'share', + extra: { + shareType: '1', + base64: base64Manane } - setTimeout(() => { - this.shareJin = false - }, 5000); }) - }, 'image/png') - }) - setTimeout(() => { - this.close() - }, 3000); - }, - // 生成图片并下载 - domToImage() { - console.log('this.$refs.xingdownLoad', this.$refs.xingdownLoad); - this.$refs.xingdownLoad = this.$refs.xingdownLoad - setTimeout(() => { - let domElement = this.$refs.xingdownLoad; - async function captureAndProcessImage() { - console.log(1111); - try { - // 获取 DOM 元素 - - console.log('domElement', domElement); - console.log(location); - console.log(2222); - - // 使用 html2canvas 捕获图像,并等待其完成 - var canvas = await html2canvas(domElement, { - width: domElement.offsetWidth, - height: domElement.offsetHeight, - backgroundColor: '#fff', - scale: 1, - dpi: 300 - }); - - // 将画布转换为 Blob,并等待其完成 - const blob = await new Promise((resolve, reject) => { - canvas.toBlob(resolve, 'image/png'); - console.log(3333); - }); - - // let arr = false - // // 将 Blob 转换为 Base64 字符串,并等待其完成 - // if(arr == false) { - // arr = true - var base64String = await new Promise((resolve, reject) => { - const reader = new FileReader() - reader.onloadend = () => resolve(reader.result) - reader.onerror = reject - reader.readAsDataURL(blob) - console.log(4444); - }) - // } - - - // 调用 base64Excel 函数,并等待其完成 - const res = await base64Excel({ base64Img: base64String }); - - // 检查结果,并处理下载逻辑 - if (res.result === '0') { - console.log(5555); - console.log(res.path); - console.log(EWebBridge); - EWebBridge.webCallAppInJs('download', { - name: '业绩贺报.png', - url: res.path - }).then(() => { - console.log('下载完成') - }).catch(() => { - // this.$toast.fail('图片下载失败,请重新下载!') - }) - } - canvas = null - } catch (error) { - console.log(6666); - - // 处理整个过程中的任何错误 - console.error('Error capturing or processing the image:', error); - // this.$toast.fail('图片处理或下载失败,请重试!'); - } - } - - // 调用 captureAndProcessImage 函数 - captureAndProcessImage(); + }) setTimeout(() => { - this.close() + this.close(); }, 3000); - - return false - }, 500); - }, - - - xiazai() { - EWebBridge.webCallAppInJs('download', { - url: 'https://iagentsales-test2.e-guofu.com/images/2024/12/30/realTimeOrder_b2914c33a78c496fa5be5033e3aa8e7e.png', - name: '业绩贺报.png' + }, 'image/png') }) }, + // 生成图片并下载 + domToImage(domElement, quality, callback) { + console.log(domElement); + html2canvas(domElement, { + width: domElement.offsetWidth, + height: domElement.offsetHeight, + backgroundColor: '#fff', + scale: 1, + dpi: 300 + }).then((canvas) => { + // 转换canvas为PNG图片并压缩 + canvas.toBlob( + (blob) => { + this.blobToBase64(blob).then((base64String) => { + base64Excel({ base64Img: base64String }).then(res => { + console.log(res); + if (res.result == '0') { + EWebBridge.webCallAppInJs('download', { + name: '业绩贺报.png', + url: res.path + }) + .then(() => { + console.log('下载完成') + setTimeout(() => { + this.close(); + }, 3000); + }) + .catch(() => { + this.$toast.fail('图片下载失败,请重新下载!') + }) + } + + }) + + }) + }, + 'image/png' + // quality + ) + }) + }, + downLoadImagesFunc() { + this.domToImage(this.$refs.xingdownLoad) + }, + + close() { console.log(15434678); - // document.documentElement.removeChild(this.$refs.xingdownLoad) - // this.$refs.xingdownLoad.removeChild(this.$refs.xingdownLoad); document.getElementById('capture').innerHTML = ''; this.$emit('child-colse', '1') - } + }, } }