mirror of
http://112.124.100.131/GFRS/ebiz-h5.git
synced 2025-12-12 12:36:43 +08:00
更换贺报下载的方法36
This commit is contained in:
@@ -152,7 +152,6 @@ function appCallBack() {}
|
|||||||
|
|
||||||
// 初始化App桥接环境
|
// 初始化App桥接环境
|
||||||
function setupWebViewJavascriptBridge(callback) {
|
function setupWebViewJavascriptBridge(callback) {
|
||||||
console.log(callback);
|
|
||||||
// Android 调用
|
// Android 调用
|
||||||
if (window.WebViewJavascriptBridge) {
|
if (window.WebViewJavascriptBridge) {
|
||||||
callback(WebViewJavascriptBridge)
|
callback(WebViewJavascriptBridge)
|
||||||
@@ -195,9 +194,6 @@ function appCallBack() {}
|
|||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
document.documentElement.removeChild(WVJBIframe)
|
document.documentElement.removeChild(WVJBIframe)
|
||||||
}, 0)
|
}, 0)
|
||||||
setTimeout(() => {
|
|
||||||
document.documentElement.removeChild(WVJBIframe)
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,15 +236,11 @@ function appCallBack() {}
|
|||||||
|
|
||||||
// 初始化SDK
|
// 初始化SDK
|
||||||
var EWebBridge = (window.EWebBridge = {
|
var EWebBridge = (window.EWebBridge = {
|
||||||
|
|
||||||
webCallAppInJs: function(method, params) {
|
webCallAppInJs: function(method, params) {
|
||||||
// params --> Mixed (json对象 {"a":"123","b":"200"} 或 null 或其他形式的参数,具体根据和app端的约定来)
|
// params --> Mixed (json对象 {"a":"123","b":"200"} 或 null 或其他形式的参数,具体根据和app端的约定来)
|
||||||
method = method || 'getUserToken'
|
method = method || 'getUserToken'
|
||||||
params = params || null
|
params = params || null
|
||||||
return triggerCallHandler(method, params)
|
return triggerCallHandler(method, params)
|
||||||
},
|
|
||||||
webCallAppInJs: function() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})(window)
|
})(window)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="contents">
|
<div>
|
||||||
<div id="capture" ref="xingdownLoad" style="height: 100vh; overflow: hidden">
|
<div id="capture" ref="generateImg" style="height: 100vh; overflow: hidden">
|
||||||
<img src="@/assets/images/list_img.png" crossorigin="anonymous" alt="" />
|
<img src="@/assets/images/list_img.png" alt="" />
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<p class="organ">{{ orderList.manageComNameFull }}</p>
|
<p class="organ">{{ orderList.manageComNameFull }}</p>
|
||||||
@@ -10,14 +10,15 @@
|
|||||||
<div class="pName">{{ orderList.productNameFull }}</div>
|
<div class="pName">{{ orderList.productNameFull }}</div>
|
||||||
<div class="type">{{ orderList.outOrderType == 'accept' ? '承保规保' : '预收规保' }}</div>
|
<div class="type">{{ orderList.outOrderType == 'accept' ? '承保规保' : '预收规保' }}</div>
|
||||||
<div class="yuan">{{ orderList.prem }}<span style="color: #333333">元</span></div>
|
<div class="yuan">{{ orderList.prem }}<span style="color: #333333">元</span></div>
|
||||||
<div class="time">{{ orderList.outOrderType == 'accept' ? '承保时间:' : '预收时间:' }}{{ orderList.appntDate }}</div>
|
<div class="time">{{ orderList.outOrderType == 'accept' ? '承保时间:' : '预收时间:' }}
|
||||||
|
<span v-if="orderList.outOrderType == 'accept'">{{ orderList.signDate }}</span>
|
||||||
|
<span v-if="orderList.outOrderType != 'accept'">{{ orderList.appntDate }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-content-s bottom-btn border-color">
|
<div class="flex justify-content-s bottom-btn border-color">
|
||||||
<!-- <van-button square type="default" :disabled="shareJin" size="large" @click="shareImg" v-no-more-click="1000"> 分享 </van-button> -->
|
<van-button square type="default" size="large" @click="shareImg" v-no-more-click="1000"> 分享 </van-button>
|
||||||
<!-- <van-button square type="danger" :disabled="downLoadJin" size="large" @click="downLoadImagesFunc" v-no-more-click="1000"> 下载 </van-button> -->
|
<van-button square type="danger" size="large" @click="downLoadImagesFunc" v-no-more-click="1000"> 下载 </van-button>
|
||||||
<button class="shareImg" @click="fenxiang()" v-no-more-click="1000"> 分享 </button>
|
|
||||||
<button class="downLoad" @click="domToImage()" v-no-more-click="1000"> 下载 </button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="close" @click="close()">
|
<div class="close" @click="close()">
|
||||||
<van-icon name="cross" size="38" color="#fff" />
|
<van-icon name="cross" size="38" color="#fff" />
|
||||||
@@ -27,7 +28,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import html2canvas from 'html2canvas'
|
import html2canvas from 'html2canvas'
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import { base64Excel } from '@/api/ebiz/nbs'
|
import { base64Excel } from '@/api/ebiz/nbs'
|
||||||
export default {
|
export default {
|
||||||
name: 'generateImg',
|
name: 'generateImg',
|
||||||
@@ -42,13 +42,8 @@ export default {
|
|||||||
return {
|
return {
|
||||||
orderList: {},
|
orderList: {},
|
||||||
isIOS: false,
|
isIOS: false,
|
||||||
shareJin: false,
|
|
||||||
downLoadJin: false,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// beforeCreate() {
|
|
||||||
// this.$refs.xingdownLoad.innerHTML = ''; // 清空内容
|
|
||||||
// },
|
|
||||||
created() {
|
created() {
|
||||||
this.isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
this.isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
||||||
if(this.isIOS) {
|
if(this.isIOS) {
|
||||||
@@ -58,13 +53,10 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.getList()
|
this.getList()
|
||||||
},
|
},
|
||||||
beforeDestroy(){
|
|
||||||
this.$refs.xingdownLoad.innerHTML = ''; // 清空内容
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
getList() {
|
getList() {
|
||||||
this.orderList = JSON.parse(localStorage.getItem('orderList'))
|
this.orderList = JSON.parse(localStorage.getItem('orderList'))
|
||||||
// console.log('页面数据',this.orderList);
|
console.log('页面数据',this.orderList);
|
||||||
},
|
},
|
||||||
// 将 Blob转base64
|
// 将 Blob转base64
|
||||||
blobToBase64(blob) {
|
blobToBase64(blob) {
|
||||||
@@ -76,32 +68,21 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 分享
|
// 分享
|
||||||
fenxiang() {
|
shareImg() {
|
||||||
// const element = document.getElementById('capture')
|
// const element = document.getElementById('capture')
|
||||||
// const canvas = await html2canvas(element)
|
// const canvas = await html2canvas(element)
|
||||||
var num = 0
|
html2canvas(this.$refs.generateImg, {
|
||||||
html2canvas(this.$refs.xingdownLoad, {
|
width: this.$refs.generateImg.offsetWidth,
|
||||||
width: this.$refs.xingdownLoad.offsetWidth,
|
height: this.$refs.generateImg.offsetHeight,
|
||||||
height: this.$refs.xingdownLoad.offsetHeight,
|
|
||||||
backgroundColor: '#fff',
|
backgroundColor: '#fff',
|
||||||
scale: 2,
|
scale: 2,
|
||||||
dpi: 300,
|
dpi: 300
|
||||||
useCORS: true,
|
|
||||||
allowTaint: true,
|
|
||||||
}).then((canvas) => {
|
}).then((canvas) => {
|
||||||
console.log('分享');
|
|
||||||
// 将 canvas 转换为 Blob
|
// 将 canvas 转换为 Blob
|
||||||
canvas.toBlob((blob) => {
|
canvas.toBlob((blob) => {
|
||||||
this.blobToBase64(blob).then((base64String) => {
|
this.blobToBase64(blob).then((base64String) => {
|
||||||
if(localStorage.getItem("first")) {
|
|
||||||
if(num < 1) {
|
|
||||||
num++
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
localStorage.setItem("first", true)
|
|
||||||
let base64Manane = base64String.split(',')[1]
|
let base64Manane = base64String.split(',')[1]
|
||||||
console.log(base64Manane);
|
// console.log(base64String)
|
||||||
EWebBridge.webCallAppInJs('bridge', {
|
EWebBridge.webCallAppInJs('bridge', {
|
||||||
flag: 'share',
|
flag: 'share',
|
||||||
extra: {
|
extra: {
|
||||||
@@ -114,82 +95,63 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 生成图片并下载
|
// 生成图片并下载
|
||||||
domToImage() {
|
domToImage(domElement, quality, callback) {
|
||||||
let domElement = this.$refs.xingdownLoad;
|
console.log(location);
|
||||||
// 调用 captureAndProcessImage 函数
|
html2canvas(domElement, {
|
||||||
this.captureAndProcessImage(domElement);
|
width: domElement.offsetWidth,
|
||||||
return false
|
height: domElement.offsetHeight,
|
||||||
},
|
backgroundColor: '#fff',
|
||||||
async captureAndProcessImage(domElement) {
|
scale: 1,
|
||||||
try {
|
dpi: 300
|
||||||
// 获取 DOM 元素
|
}).then((canvas) => {
|
||||||
// let domElement = this.$refs.xingdownLoad;
|
// 转换canvas为PNG图片并压缩
|
||||||
// 使用 html2canvas 捕获图像,并等待其完成
|
canvas.toBlob(
|
||||||
var canvas = await html2canvas(domElement, {
|
(blob) => {
|
||||||
width: domElement.offsetWidth,
|
// const a = document.createElement('a')
|
||||||
height: domElement.offsetHeight,
|
// a.href = URL.createObjectURL(blob)
|
||||||
backgroundColor: '#fff',
|
// a.download = '业绩贺报.png'
|
||||||
scale: 1,
|
// a.click()
|
||||||
dpi: 300,
|
// let newimg = new Image()
|
||||||
useCORS: true,
|
// newimg.src = URL.createObjectURL(blob)
|
||||||
allowTaint: true,
|
// newimg.onload = function () {
|
||||||
});
|
// URL.revokeObjectURL(newimg.src)
|
||||||
console.log('下载',canvas);
|
// callback(newimg)
|
||||||
// 将画布转换为 Blob,并等待其完成
|
// }
|
||||||
const blob = await new Promise((resolve, reject) => {
|
this.blobToBase64(blob).then((base64String) => {
|
||||||
canvas.toBlob(resolve, 'image/png');
|
base64Excel({ base64Img: base64String }).then(res => {
|
||||||
});
|
if (res.result == '0') {
|
||||||
|
EWebBridge.webCallAppInJs('download', {
|
||||||
|
name: '业绩贺报.png',
|
||||||
|
url: res.path
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
console.log('下载完成')
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.$toast.fail('图片下载失败,请重新下载!')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var base64String = await new Promise((resolve, reject) => {
|
})
|
||||||
const reader = new FileReader()
|
|
||||||
reader.onloadend = () => resolve(reader.result)
|
})
|
||||||
reader.onerror = reject
|
},
|
||||||
reader.readAsDataURL(blob)
|
'image/png'
|
||||||
console.log(4444);
|
// quality
|
||||||
})
|
)
|
||||||
|
})
|
||||||
// 调用 base64Excel 函数,并等待其完成
|
},
|
||||||
const res = await base64Excel({ base64Img: base64String });
|
downLoadImagesFunc() {
|
||||||
|
this.domToImage(this.$refs.generateImg)
|
||||||
// window.location.href = res.path
|
|
||||||
// 检查结果,并处理下载逻辑
|
|
||||||
if (res.result === '0') {
|
|
||||||
console.log(5555);
|
|
||||||
console.log(res.path + '?t=' + Date.now());
|
|
||||||
console.log(EWebBridge);
|
|
||||||
EWebBridge.webCallAppInJs('download', {
|
|
||||||
name: '业绩贺报.png',
|
|
||||||
url: res.path,
|
|
||||||
})
|
|
||||||
// .then(() => {
|
|
||||||
// console.log('下载完成')
|
|
||||||
// }).catch(() => {
|
|
||||||
// // this.$toast.fail('图片下载失败,请重新下载!')
|
|
||||||
// })
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// 处理整个过程中的任何错误
|
|
||||||
console.error('Error capturing or processing the image:', error);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
close() {
|
close() {
|
||||||
console.log(15434678);
|
|
||||||
document.getElementById('capture').innerHTML = '';
|
|
||||||
this.$emit('child-colse', '1')
|
this.$emit('child-colse', '1')
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.contents {
|
|
||||||
width: 100%;
|
|
||||||
height: 100vh;
|
|
||||||
background-color: #fff;
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
}
|
|
||||||
img {
|
img {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -279,19 +241,13 @@ img {
|
|||||||
border: 2px solid;
|
border: 2px solid;
|
||||||
border-image: radial-gradient(circle, rgba(255, 233, 124, 1), rgba(222, 144, 34, 1)) 2 2;
|
border-image: radial-gradient(circle, rgba(255, 233, 124, 1), rgba(222, 144, 34, 1)) 2 2;
|
||||||
}
|
}
|
||||||
.shareImg {
|
/deep/ .van-button {
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
width: 35%;
|
width: 42%;
|
||||||
height: 50px;
|
|
||||||
border: none !important;
|
|
||||||
}
|
}
|
||||||
.downLoad {
|
/deep/ .van-button--danger {
|
||||||
border-radius: 12px;
|
|
||||||
width: 35%;
|
|
||||||
height: 49px;
|
|
||||||
background: linear-gradient(to right, #f26e43, #ac0209) !important;
|
background: linear-gradient(to right, #f26e43, #ac0209) !important;
|
||||||
/*设置按钮为渐变颜色*/
|
/*设置按钮为渐变颜色*/
|
||||||
color: #fff;
|
|
||||||
border: none !important;
|
border: none !important;
|
||||||
}
|
}
|
||||||
.close {
|
.close {
|
||||||
|
|||||||
Reference in New Issue
Block a user