posterService.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view>
  3. <view class="poster" id="poster">
  4. <image class="poster-pic" :src="posterBg" mode="widthFix"></image>
  5. <view class="ddflex" style="padding: 22rpx 35rpx;position: relative;">
  6. <view class="flex">
  7. <view class="poster-title">杜平 | 中国人寿股份湖南分公司</view>
  8. <view class="poster-note">长按小程序码了解更多</view>
  9. </view>
  10. <image class="poster-code" src="/static/images/lj_img.png"></image>
  11. <view class="change-product ddflex" @click="jumpUrl('/library/productLink/productLink')" data-html2canvas-ignore="true">
  12. <image src="/static/images/edit1.png"></image>
  13. 产品链接</view>
  14. </view>
  15. </view>
  16. <view style="height: 150rpx;"></view>
  17. <view class="share-btn">
  18. <view class="btn" @click="toImg">立即分享</view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. const app = getApp();
  24. const req = require("../../utils/request.js");
  25. import html2canvas from '../static/html2canvas.min.js';
  26. export default {
  27. components: {},
  28. props: {},
  29. data() {
  30. return {
  31. systems: {},
  32. isTop:0,
  33. productLink:'',
  34. posterBg:'',
  35. base64:''
  36. }
  37. },
  38. onLoad(options) {
  39. this.posterBg = 'http://img.zhiqiyun.com/test/2023/07/31/8b7ed072b68fe70f0d6f409a71a8b17b.png'
  40. // this.posterBg = 'https://hxdms.oss-cn-hangzhou.aliyuncs.com/hxdms/2986a2805d414b75952d609381f2d280.png'
  41. this.imageChange(this.posterBg)
  42. },
  43. onShow() {
  44. },
  45. methods: {
  46. jumpUrl(url){
  47. uni.navigateTo({
  48. url:url
  49. })
  50. },
  51. creatCode(){
  52. },
  53. toImg() {
  54. // 使页面滑到顶部,避免顶部出现白边
  55. uni.pageScrollTo({
  56. scrollTop: 0,
  57. duration: 0
  58. })
  59. var dom = document.querySelector('#poster'); // 获取dom元素
  60. html2canvas(dom, {
  61. width: dom.clientWidth, //dom 原始宽度
  62. height: dom.clientHeight,
  63. scrollY: 0, // html2canvas默认绘制视图内的页面,需要把scrollY,scrollX设置为0
  64. scrollX: 0,
  65. useCORS: true, //支持跨域,但好像没什么用
  66. }).then((canvas) => {
  67. // 将生产的canvas转为base64图片
  68. this.base64 = canvas.toDataURL('image/png')
  69. console.log(this.base64)
  70. });
  71. },
  72. imageChange(img){
  73. // let imagePromise = this.getCoverSrc(img);
  74. // Promise.all([imagePromise]).then(([image]) => {
  75. // console.log(image)
  76. // this.posterBg = image
  77. // })
  78. // this.posterBg = image
  79. //创建xhr对象
  80. }
  81. },
  82. mounted() {
  83. const systemInfo = uni.getSystemInfoSync();
  84. // px转换到rpx的比例
  85. let pxToRpxScale = 750 / systemInfo.windowWidth;
  86. let systems = {
  87. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  88. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  89. };
  90. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  91. this.systems = systems;
  92. },
  93. onPageScroll: function(e) {
  94. if (e.scrollTop > this.systems.barHeight) {
  95. this.isTop = 1;
  96. } else {
  97. this.isTop = 0;
  98. }
  99. }
  100. }
  101. </script>
  102. <style>
  103. @import "./posterService.css";
  104. </style>